Contents

About the Author

Acknowledgments

Preface

Introduction


CHAPTER 1     Understanding Django

                            Philosophy

                                  Django's Interpretation of the MVC Pattern

                                  Loose Coupling

                                  Don't Repeat Yourself (DRY)

                                  A Focus on Readability

                                  Failing Loudly

                            Community

                                  Management of the Framework

                                  News and Resources

                                  Reusable Applications

                                  Getting Help

                            Now What?

CHAPTER 2     Django Is Python

                            How Python Builds Classes

                                  Building a Class Programmatically

                                  Metaclasses Change It Up

                                  Using a Base Class with a Metaclass

                                  Declarative Syntax

                            Common Duck-Typing Protocols

                                  Callables

                                  Dictionaries

                                  Files

                                  Iterables

                                  Sequences

                            Augmenting Functions

                                  Excess Arguments

                                  Decorators

                            Descriptors

                                  __get__(self, instance, owner)

                                  __set__(self, instance, value)

                                  Keeping Track of Instance Data

                            Introspection

                                  Common Class and Function Attributes

                                  Identifying Object Types

                                  Function Signatures

                                  Docstrings

                            Applied Techniques

                                  Tracking Subclasses

                                  A Simple Plugin Architecture

                            Now What?

CHAPTER 3     Models

                            How Django Processes Model Classes

                                  Setting Attributes on Models

                            Getting Information About Models

                                  Class Information

                                  Field Definitions

                                  Primary Key Fields

                                  Configuration Options

                                  Accessing the Model Cache

                            Using Model Fields

                                  Common Field Attributes

                                  Common Field Methods

                            Subclassing Fields

                                  Deciding Whether to Invent or Extend

                                  Performing Actions During Model Registration

                                  Altering Data Behavior

                                  Controlling Database Behavior

                            Dealing with Files

                                  get_directory_name(self)

                                  get_filename(self, filename)

                                  generate_filename(self, instance, filename)

                                  save_form_data(self, instance, data)

                                  delete_file(self, instance, sender)

                                  attr_class

                                  Customizing the File Class

                            Signals

                                  class_prepared

                                  pre_init and post_init

                                  pre_save and post_save

                                  pre_delete and post_delete

                                  post_syncdb

                            Applied Techniques

                                  Loading Attributes on Demand

                                  Creating Models Dynamically at Runtime

                            Now What?

CHAPTER 4     URLs and Views

                            URLs

                                  Standard URL Configuration

                                  Resolving URLs to Views

                                  Resolving Views to URLs

                            Views

                                  Templates Break It Up a Bit

                                  Anatomy of a View

                                  Writing Views to Be Generic

                                  View Decorators

                                  Using an Object As a View

                            Applied Techniques

                                  Dual-Format Decorator

                            Now What?

CHAPTER 5     Forms

                            Declaring and Identifying Fields

                            Binding to User Input

                                  Validating Input

                            Custom Fields

                                  Validation

                                  Controlling Widgets

                            Defining HTML Behavior

                                  Custom Widgets

                                  Customizing Form Markup

                                  Accessing Individual Fields

                                  Customizing the Display of Errors

                            Applied Techniques

                                  Pending and Resuming Forms

                            Now What?

CHAPTER 6     Templates

                            What Makes a Template

                                  Exceptions

                                  The Process at Large

                                  Content Tokens

                                  Parsing Tokens into Nodes

                                  Template Nodes

                                  Rendering Templates

                            Context

                                  Simple Variable Resolution

                                  Complex Variable Lookup

                                  Including Aspects of the Request

                            Retrieving Templates

                                  Shortcuts to Load and Render Templates

                            Adding Features for Templates

                                  Setting Up the Package

                                  Variable Filters

                                  Template Tags

                                  Adding Features to All Templates

                            Applied Techniques

                                  Embedding Another Template Engine

                                  Enabling User-Submitted Themes

                            Now What?

CHAPTER 7     Handling HTTP

                            Requests and Responses

                                  HttpRequest

                                  HttpResponse

                            Writing HTTP Middleware

                                  MiddlewareClass.process_request(self, request)

                                  MiddlewareClass.process_view(self, request, view, args, kwargs)

                                  MiddlewareClass.process_response(self, request, response)

                                  MiddlewareClass.process_exception(self, request, exception)

                                  Deciding Between Middleware and View Decorators

                            HTTP-Related Signals

                                  django.core.signals.request_started

                                  django.core.signals.request_finished

                                  django.core.signals.got_request_exception

                            Applied Techniques

                                  Signing and Validating Cookies

                            Now What?

CHAPTER 8     Backend Protocols

                            Database Access

                                  django.db.backends

                                  Creation of New Structures

                                  Introspection of Existing Structures

                                  DatabaseClient

                                  DatabaseError and IntegrityError

                            Authentication

                                  get_user(user_id)

                                  authenticate(**credentials)

                                  Storing User Information

                            Files

                                  The Base File Class

                                  Handling Uploads

                                  Storing Files

                            Session Management

                            Caching

                                  Specifying a Backend

                                  Using the Cache Manually

                            Template Loading

                                  load_template_source(template_name, template_dirs=None)

                                  load_template_source.is_usable

                            Context Processors

                            Applied Techniques

                                  Loading Templates Using a Different Engine

                                  Scanning Incoming Files for Viruses

                            Now What?

CHAPTER 9     Common Tools

                            Core Exceptions

                                  django.core.exceptions.ImproperlyConfigured

                                  django.core.exceptions.MiddlewareNotUsed

                                  django.core.exceptions.MultipleObjectsReturned

                                  django.core.exceptions.ObjectDoesNotExist

                                  django.core.exceptions.PermissionDenied

                                  django.core.exceptions.SuspiciousOperation

                                  django.core.exceptions.ViewDoesNotExist

                            Text Modification

                                  get_text_list(items, last_word='or')

                                  javascript_quote(s, quote_double_quotes=False)

                                  normalize_newlines(text)

                                  phone2numeric(phone)

                                  recapitalize(text)

                                  smart_split(text)

                                  truncate_words(s,num)

                                  truncate_html_words(s, num)

                                  wrap(text, width)

                            Data Structures

                                  django.utils.datastructures.MergeDict

                                  django.utils.datastructures.MultiValuedDict

                                  django.utils.datastructures.SortedDict

                            Functional Utilities

                                  django.utils.functional.curry

                                  django.utils.functional.memoize

                                  django.utils.functional.wraps

                            Signals

                                  How It Works

                                  Defining a Signal

                                  Sending a Signal

                                  Capturing Return Values

                                  Defining a Listener

                                  Registering Listeners

                                  Forcing Strong References

                            Now What?

CHAPTER 10     Coordinating Applications

                           Contacts

                                 contacts.models.Contact

                                 contacts.forms.UserEditorForm

                                 contacts.forms.ContactEditorForm

                                 contacts.views.edit_contact

                                 Admin Configuration

                                 URL Configuration

                           Real Estate Properties

                                 properties.models.Property

                                 properties.models.Feature

                                 properties.models.PropertyFeature

                                 properties.models.InterestedParty

                                 Admin Configuration

                                 URL Configuration

                           Now What?

CHAPTER 11     Enhancing Applications

                           Recording the Current User

                                 The Thread-Local Approach—Useful but Dangerous

                                 The Admin Approach

                                 Introducing the CurrentUserField

                                 Keeping Track of CurrentUserField Instances

                                 The CurrentUserMiddleware

                                 Performance Considerations

                           Keeping Historical Records

                                 Intended Usage

                                 Overview of the Process

                                 Step 1: Copy the Model

                                 Step 2: Register Signal Handlers

                                 Step 3: Assign a Manager

                           Now What?

APPENDIX     Contributing to Django

                            Reporting a Ticket

                            Supplying a Patch

                            Writing Tests

                            Writing Documentation

                            Development Sprints

                            Publishing Code

                            Releasing an Application


Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset