django-dajax Documentation

Similar documents
django-dajaxice Documentation

Django Map Widgets Documentation

django-sticky-uploads Documentation

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

django-allauth-2fa Documentation

Django EL(Endless) Pagination Documentation

django-inplaceedit Documentation

Unveiling Zend Studio 8.0

Django File Picker Documentation

Django File Picker Documentation

django simple pagination Documentation

Welcome to CS50 section! This is Week 10 :(

Easy-select2 Documentation

welcome to BOILERCAMP HOW TO WEB DEV

django-users2 Documentation

TailorDev Contact Documentation

DJOAuth2 Documentation

PHP / MYSQL DURATION: 2 MONTHS

Djam Documentation. Release Participatory Culture Foundation

django-messages Documentation

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

Django MFA Documentation

Django-frontend-notification Documentation

Building a Django Twilio Programmable Chat Application

Course 20480: Programming in HTML5 with JavaScript and CSS3

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

mincss Documentation Release 0.1 Peter Bengtsson

Programming in HTML5 with JavaScript and CSS3

django-xross Documentation

Django-Select2 Documentation. Nirupam Biswas

django-image-cropping Documentation

Web Development 20480: Programming in HTML5 with JavaScript and CSS3. Upcoming Dates. Course Description. Course Outline

django-telegram-login Documentation

django-mama-cas Documentation

Django-CSP Documentation

django-intercom Documentation

User Interaction: jquery

Standard 1 The student will author web pages using the HyperText Markup Language (HTML)

Create-A-Page Design Documentation

django-geoip Documentation

Working with Javascript Building Responsive Library apps

Programming in HTML5 with JavaScript and CSS3

django-baton Documentation

Linguistic Architecture

django-ad-code Documentation

django_podcasting Documentation

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

kaleo Documentation Release 1.5 Eldarion

The Django Web Framework Part VI

django-session-security Documentation

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries

django-avatar Documentation

django-avatar Documentation

Frontend UI Training. Whats App :

CSE 154 LECTURE 26: JAVASCRIPT FRAMEWORKS

django-baton Documentation

MIT AITI Python Software Development Lab DJ1:

django-cron Documentation

Programming in HTML5 with JavaScript and CSS3

Learn Web Development CodersTrust Polska course outline. Hello CodersTrust! Unit 1. HTML Structuring the Web Prerequisites Learning pathway.

Django Leaflet Documentation

20480B: Programming in HTML5 with JavaScript and CSS3

7401ICT eservice Technology. (Some of) the actual examination questions will be more precise than these.

django-teamwork Documentation

Qiufeng Zhu Advanced User Interface Spring 2017

Django Debug Toolbar Documentation

django-revproxy Documentation

Getting Started with

django-celery Documentation

CodeValue. C ollege. Prerequisites: Basic knowledge of web development and especially JavaScript.

Client Side JavaScript and AJAX

Tomasz Szumlak WFiIS AGH 23/10/2017, Kraków

Human-Computer Interaction Design

Gargoyle Documentation

django-openid Documentation

youckan Documentation

Trunk Player Documentation

django-amp-tools Documentation Release latest

Mix It Up: Visual Studio 2010 and ASP.NET 4.0. Singapore 25 March 2009

Databases/JQuery AUGUST 1, 2018

Tooling for Ajax-Based Development. Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.

Django Phantom Theme Documentation

XAP: extensible Ajax Platform

Prototype jquery. To and from JavaScript libraries. Remy Sharp (remysharp.com)

django-rest-framework-datatables Documentation

SEEM4570 System Design and Implementation. Lecture 4 AJAX and Demo

django-osm-field Release 0.3.1

WEB DEVELOPER BLUEPRINT

Django Wordpress API Documentation

cmsplugin-blog Release post 0 Øyvind Saltvik

20486: Developing ASP.NET MVC 4 Web Applications

BriCS. University of Bristol Cloud Service Simulation Runner. User & Developer Guide. 1 October John Cartlidge & M.

Flask-Genshi Documentation

django-stored-messages Documentation

Comprehensive AngularJS Programming (5 Days)

Web Programming Step by Step

Atmel Studio IDE for RIO-2015PG User Guide

HTML CS 4640 Programming Languages for Web Applications

JQuery WHY DIDN T WE LEARN THIS EARLIER??!

Transcription:

django-dajax Documentation Release 0.9 Jorge Bastida Nov 16, 2017

Contents 1 Documentation 3 1.1 Installation................................................ 3 1.2 API.................................................... 4 1.3 Migrating to 0.9............................................. 8 1.4 Changelog................................................ 8 2 How does it work? 11 3 Example 13 4 Supported JS Frameworks 15 i

ii

Dajax is a powerful tool to easily and super-quickly develop asynchronous presentation logic in web applications, using Python and almost no JavaScript source code. It supports four of the most popular JavaScript frameworks: Prototype, jquery, Dojo and mootols. Using django-dajaxice as communication core, Dajax implements an abstraction layer between presentation logic managed with JavaScript and your Python business logic. With Dajax you can modify your DOM structure directly from Python. Contents 1

2 Contents

CHAPTER 1 Documentation 1.1 Installation In order to use dajax you should install django-dajaxice before. Please follow these instructions here. 1.1.1 Installing Dajax Install django-dajax using easy_install or pip: $ pip install django_dajax $ easy_install django_dajax Add dajax in your project settings.py inside INSTALLED_APPS: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'dajaxice', 'dajax',... ) Create a new ajax.py file inside your app with your own dajax functions: def multiply(request, a, b): result = int(a) * int(b) dajax.assign('#result','value',str(result)) 3

Include dajax in your <head>: Dajax supports up to four JS libraries. You should add to your project base template the one you need. jquery 1.7.2 - dajax/jquery.dajax.core.js Prototype 1.7 - dajax/prototype.dajax.core.js MooTools 1.4.5 - dajax/mootools.dajax.core.js Dojo 1.7 - dajax/dojo.dajax.core.js For example for jquery: {% static "/static/dajax/jquery.dajax.core.js" %} 1.1.2 Use Dajax Now you can call your ajax methods using Dajaxice.app.function( Dajax.process ): <button onclick="dajaxice.example.myexample(dajax.process);">click here!</button> The function _Dajax.process_ will process what the server returns and call the appropriate actions. If you need your own callback, you can change the callback with a function like: function my_callback(data){ Dajax.process(data); /* Your js code */ } And use it as: <button onclick="dajaxice.app.function(my_callback)">click here!</button> 1.2 API 1.2.1 alert(message) Alert a message. message: Any message you want to alert def alert_example(request): dajax.alert('hello from python!') 1.2.2 assign(selector, attribute, value) Assign to all elements that matches with the selector as attribute the value. 4 Chapter 1. Documentation

selector: CSS selector. attribute: Any valid attribute. value: The value you want to assing. def assign_example(request): dajax.assign('#button', 'value', 'Click here!') dajax.assign('div.alert', 'innerhtml', 'This email is invalid') 1.2.3 add_css_class(selector, value) Assign to all elements that matches with the selector the CSS class value. value could be a string or a list of them. selector: CSS selector. value: Any CSS class name or a list of them. def add_css_example(request): dajax.add_css_class('div.alert', 'red') dajax.add_css_class('div.warning', ['big', 'yellow']) 1.2.4 remove_css_class(selector, value) Remove to all elements that matches with the selector the CSS class value. value could be a string or a list of them. selector: CSS selector. value: Any CSS class name or a list of them. def remove_css_example(request): dajax.remove_css_class('div.message', 'big-message') dajax.remove_css_class('div.total', ['big', 'red']) 1.2.5 append(selector, attribute, value) Append to all elements that matches with the selector value to with the desired attribute. 1.2. API 5

selector: CSS selector. attribute: Any valid attribute. value: Any CSS class name or a list of them. def append_example(request): dajax.append('#message', 'innerhtml', 'Last message') 1.2.6 prepend(selector, attribute, value) Prepend to all elements that matches with the selector value to with the desired attribute. selector: CSS selector. attribute: Any valid attribute. value: Any CSS class name or a list of them. def prepend_example(request): dajax.prepend('#message', 'innerhtml', 'First message') 1.2.7 clear(selector, attribute) Clear all elements that matches with the selector the desired attribute. selector: CSS selector. attribute: Any valid attribute. def clear_example(request): dajax.clear('#message', 'innerhtml') 1.2.8 redirect(url, delay=0) Redirect current page to url with a delay of ms. url: Destination URL. delay: Number of ms that the browser should wait before redirecting. 6 Chapter 1. Documentation

def redirect_example(request): dajax.redirect('http://google.com', delay=2000) 1.2.9 script(code) Executes code in the browser code: Code to execute. def code_example(request): dajax.code('my_function();') 1.2.10 remove(selector) Remove all elements that matches selector. selector: CSS selector. def code_example(request): dajax.remove('.message') 1.2.11 add_data(data, callback_function) Send data to the browser and call callback_function using this data. data: Data you want to send to your function. callback_function: Fuction you want to call in the browser. def data_example(request): dajax.add_data(range(10), 'my_js_function') 1.2. API 7

1.3 Migrating to 0.9 1.3.1 Static files Since 0.9 dajax takes advantage of django.contrib.staticfiles so deploying a dajax application live is much easy than in previous versions. All the X.dajax.core.js flavoured files (jquery, Prototype,...) are inside a new folder named static instead of src. You need to remember to run python manage.py collectstatic before deploying your code live. This command will collect all the static files your application need into STATIC_ROOT. For further information, this is the Django static files docuemntation You should change all you dajax core imports using for example for jquery: {% static "dajax/jquery.core.js" %} 1.3.2 Imports If you was importing dajax using: from dajax.core.dajax import Dajax you should change it to: 1.4 Changelog 1.4.1 0.9.2 Fix unicode issues Fix Internet Explorer issues modifying element s innerhtml 1.4.2 0.9 Move dajaxice core from dajaxice.core.dajax to dajax.core Django 1.3 is now a requirement dajaxice 0.5 is now a requirement Static files are now located inside static instead of src 1.4.3 0.8.4 Upgrade to dajaxice 0.1.3 (New Dajaxice.EXCEPTION) Dajax PEP8 naming style for addcssclass and removecssclass Fixed some bugs in examples Fixed unicode problems 8 Chapter 1. Documentation

1.4.4 0.8.3 General: New and cleaned setup.py 1.4.5 0.8.2 General: Upgrade to dajaxice 0.1.1 1.4.6 0.8.0.1 dajaxice released, now dajax use it as communication core cleaned all the code 1.4.7 0.7.5 Added Dojo support Cleaned js files Ajax functions outside project folder now supported. Flickr in place editor example. 1.4.8 0.7.4.1 Typo error importing ajax functions 1.4.9 0.7.4.0 Typo error importing ajax functions Examples: Form validation using new utf-8 support. Examples: New deserialize method Examples: New DAJAX_CACHE_CONTROL usage in dajax.core.js view. 1.4. Changelog 9

10 Chapter 1. Documentation

CHAPTER 2 How does it work? 11

12 Chapter 2. How does it work?

CHAPTER 3 Example Once you ve installed dajaxice and dajax you can create ajax functions in your Python code: def assign_test(request): dajax.assign('#box', 'innerhtml', 'Hello World!') dajax.add_css_class('div.alert', 'red') This function will assign to #box as innerhtml the text Hello World! and Hola! to every DOM element that matches.btn. You can call this function in your html/js code using: <div onclick="dajaxice.app.assign_test(dajax.process);">click Here!</div> 13

14 Chapter 3. Example

CHAPTER 4 Supported JS Frameworks Dajax currently support four of the most popular: jquery 1.7.2 Prototype 1.7 MooTools 1.4.5 Dojo 1.7 15