Django JavaScript Integration: Ajax and Jquery

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Jonathan Hayward
Publisher: Packt Publishing
Year: 2011

Language: English
Pages: 324

Cover
Copyright
Credits
Foreword
About the Author
About the Reviewers
Table of Contents
Preface
Chapter 1: jQuery and Ajax Integration in Django
Ajax and the XMLHttpRequest object
Human speech: An overlaid function
Ajax: Another overlaid function
The technologies Ajax is overlaid on
JavaScript
XMLHttpRequest
Methods
Properties
HTML/XHTML
XML
JSON
CSS
The DOM
iframes and other Ajax variations
JavaScript/Ajax Libraries
Server-side technologies
A look at Django
Django templating kickstart
A more complete glimpse at Django templating
Setting JavaScript and other static content in place
Summary
Chapter 2: jQuery—the Most Common JavaScript Framework
jQuery and basic Ajax
jQuery Ajax facilities
$.ajax()
context
data
dataFilter
dataType
error(XMLHttpRequest, textStatus, errorThrown)
success(data, textStatus, XMLHttpRequest)
type
url
$.aj0axSetup()
Sample invocation
$.get() and $.post()
.load()
jQuery as a virtual higher-level language
The selectors
A closure-based example to measure clock skew
Case study: A more in-depth application
Chapter 3: Validating Form Input on the Server Side
Chapter 4: Server-side Database Search with Ajax
Chapter 5: Signing Up and Logging into a Website Using Ajax
Chapter 6: jQuery In-place Editing Using Ajax
Chapter 7: Using jQuery UI Autocomplete in Django Templates
Chapter 8: Django ModelForm: a CSS Makeover
Chapter 9: Database and Search Handling
Chapter 10: Tinkering Around: Bugfixes, Friendlier Password Input, and a Directory That Tells Local Time
Chapter 11: Usability for Hackers
Appendix: Debugging Hard JavaScript Bugs
Summary
Chapter 3: Validating Form Input on the Server Side
The standard lecture: low-level validation
Matching regular expressions
You cannot guarantee absolutely valid data
Validating can detect (some) malicious input
The Django way of validation
Django gives you some things for free
The steps in Django's validation
A more sensible and cruelty-free approach to validation
Things get murkier
The zero-one-infinity rule: a cardinal rule of thumb in usability
An improvement on Django's advertised approach
A validation example: GPS coordinates
Avoiding error messages that point fingers and say, "You're wrong!"
Validation as demanding that assumptions be met
Old-school: conform to our U.S.-based assumptions!
Adding the wrong kind of band-aid
Making assumptions and demanding that users conform
At least names are simple, right?
Even in ASCII, things keep getting murkier
Better validation may be less validation
Caveat: English is something of a lingua franca
We don't have to negotiate with pistols
Doing our best to solve the wrong problem: a story
It really does apply to validation
Facebook and LinkedIn know something better
Summary
Chapter 4: Server-side Database Search with Ajax
Searching on the client side and server side
Handling databases through Django models
Models for an intranet employee photo directory
Searching our database
A tour of Django persistence facilities
Summary
Chapter 5: Signing Up and Logging into a Website Using Ajax
admin.py: administrative functions called once
functions.py: project-specific functions, including our @ajax_login_required decorator
views.py: functions that render web pages
style.css: basic styling for usability
search.html: a template for client-side Ajax
The Django admin interface
Summary
Chapter 6: jQuery In-place Editing Using Ajax
Including a plugin
How to make pages more responsive
A template handling the client-side requirements
The bulk of the profile
Whitespace and delivery
Page-specific JavaScript
Support on the server side
Summary
Chapter 7: Using jQuery UI Autocomplete in Django Templates
Adding autocomplete: first attempt
Progressive enhancement, a best practice
A real-world workaround
"Interest-based negotiation": a power tool for problem solving when plan A doesn't work
A first workaround
Boilerplate code from jQuery UI documentation
Turning on Ajax behavior (or trying to)
Code on the server side
Refining our solution further
Summary
Chapter 8: Django ModelForm: a CSS Makeover
"Hello, world!" in ModelForm
Expanding and customizing the example
Customizing ModelForm pages' appearance
Going under ModelForm's hood
An excellent "stupid" question: where's the e-mail slot?
Summary
Chapter 9: Database and Search Handling
Moving forward to an AHAH solution
Django templates for simple AHAH
Templating for a list of search results
Template for an individual profile
Views on the server side
Telling if the user is logged in
A view to support deletion
The AHAH view to load profiles
Helper functions for the AHAH view for searching
An updated model
An AHAH server-side search function
Handling the client-side: A template for the main page
CSS for styling the directory
Our updated urlpatterns
Summary
Chapter 10: Tinkering Around: Bugfixes, Friendlier Password Input, and a Directory That Tells Local Time
Minor tweaks and bugfixes
Setting a default name of "(Insert name here)"
Eliminating Borg behavior
Confusing jQuery's load() with html()
Preventing display of deleted instances
Adding a favicon.ico
Handling password input in a slightly different way
A directory that includes local timekeeping
Summary
Chapter 11: Usability for Hackers
Usability begins with anthropology… and Django hackers have a good start on anthropology
Anthropological usability techniques
An introductory example: card sorting
Focus groups: cargo cult research for usability
Anthropological observation: the bedrock of usability
More than one way to see the same situation
Applying this foundation to usability
It's just like (hard) debugging
Lessons from other areas
Live cross-cultural encounters
History
Old books and literature
The last other area: whatever you have
Understanding the user
A lesson from optimization
What's wrong with scratching an itch, or you are not your user
Worst practices from the jargon file
Python and usability
It's not all about the computer!
What to do in the concrete
Further reading
Summary
Appendix: Debugging Hard JavaScript Bugs
"Just fiddling with Firebug" is considered harmful
Cargo cult debugging at your fingertips
The scientific method of debugging
Exhausting yourself by barking up the wrong tree
The humble debugger
The value of taking a break
Two major benefits to asking for help
Firebug and Chrome developer tools
The basics across browsers
Zeroing in on Chrome
Summary
Index