Removed trailing whitespace.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8201 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2008-08-03 19:04:32 +00:00
parent cca261325a
commit 71b2e01ec2
1 changed files with 70 additions and 70 deletions

View File

@ -39,7 +39,7 @@ The library deals with these concepts:
* **Media** -- A definition of the CSS and JavaScript resources that are
required to render a form.
The library is decoupled from the other Django components, such as the database
layer, views and templates. It relies only on Django settings, a couple of
``django.utils`` helper functions and Django's internationalization hooks (but
@ -1198,7 +1198,7 @@ given length.
Takes one extra argument, ``choices``, which is an iterable (e.g., a list or
tuple) of 2-tuples to use as choices for this field. This argument accepts
the same formats as the ``choices`` argument to a model field. See the
the same formats as the ``choices`` argument to a model field. See the
`model API documentation on choices`_ for more details.
.. _model API documentation on choices: ../model-api#choices
@ -1324,33 +1324,33 @@ extra arguments:
============== ========== ===============================================
Argument Required? Description
============== ========== ===============================================
``path`` Yes The absolute path to the directory whose
contents you want listed. This directory must
``path`` Yes The absolute path to the directory whose
contents you want listed. This directory must
exist.
``recursive`` No If ``False`` (the default) only the direct
contents of ``path`` will be offered as choices.
If ``True``, the directory will be descended
into recursively and all descendants will be
listed as choices.
``match`` No A regular expression pattern; only files with
names matching this expression will be allowed
as choices.
============== ========== ===============================================
``FloatField``
~~~~~~~~~~~~~~
``FloatField``
~~~~~~~~~~~~~~
* Default widget: ``TextInput``
* Empty value: ``None``
* Normalizes to: A Python float.
* Validates that the given value is an float. Leading and trailing
whitespace is allowed, as in Python's ``float()`` function.
* Error message keys: ``required``, ``invalid``, ``max_value``,
``min_value``
Takes two optional arguments for validation, ``max_value`` and ``min_value``.
* Default widget: ``TextInput``
* Empty value: ``None``
* Normalizes to: A Python float.
* Validates that the given value is an float. Leading and trailing
whitespace is allowed, as in Python's ``float()`` function.
* Error message keys: ``required``, ``invalid``, ``max_value``,
``min_value``
Takes two optional arguments for validation, ``max_value`` and ``min_value``.
These control the range of values permitted in the field.
``ImageField``
@ -1410,7 +1410,7 @@ These control the range of values permitted in the field.
Takes one extra argument, ``choices``, which is an iterable (e.g., a list or
tuple) of 2-tuples to use as choices for this field. This argument accepts
the same formats as the ``choices`` argument to a model field. See the
the same formats as the ``choices`` argument to a model field. See the
`model API documentation on choices`_ for more details.
``NullBooleanField``
@ -1837,17 +1837,17 @@ They've been deprecated, but you can still `view the documentation`_.
Media
=====
Rendering an attractive and easy-to-use web form requires more than just
HTML - it also requires CSS stylesheets, and if you want to use fancy
"Web2.0" widgets, you may also need to include some JavaScript on each
page. The exact combination of CSS and JavaScript that is required for
Rendering an attractive and easy-to-use web form requires more than just
HTML - it also requires CSS stylesheets, and if you want to use fancy
"Web2.0" widgets, you may also need to include some JavaScript on each
page. The exact combination of CSS and JavaScript that is required for
any given page will depend upon the widgets that are in use on that page.
This is where Django media definitions come in. Django allows you to
This is where Django media definitions come in. Django allows you to
associate different media files with the forms and widgets that require
that media. For example, if you want to use a calendar to render DateFields,
you can define a custom Calendar widget. This widget can then be associated
with the CSS and JavaScript that is required to render the calendar. When
that media. For example, if you want to use a calendar to render DateFields,
you can define a custom Calendar widget. This widget can then be associated
with the CSS and JavaScript that is required to render the calendar. When
the Calendar widget is used on a form, Django is able to identify the CSS and
JavaScript files that are required, and provide the list of file names
in a form suitable for easy inclusion on your web page.
@ -1858,9 +1858,9 @@ in a form suitable for easy inclusion on your web page.
for calendars, filtered selections, and so on. These widgets define
media requirements, and the Django Admin uses the custom widgets
in place of the Django defaults. The Admin templates will only include
those media files that are required to render the widgets on any
those media files that are required to render the widgets on any
given page.
If you like the widgets that the Django Admin application uses,
feel free to use them in your own application! They're all stored
in ``django.contrib.admin.widgets``.
@ -1868,18 +1868,18 @@ in a form suitable for easy inclusion on your web page.
.. admonition:: Which JavaScript toolkit?
Many JavaScript toolkits exist, and many of them include widgets (such
as calendar widgets) that can be used to enhance your application.
as calendar widgets) that can be used to enhance your application.
Django has deliberately avoided blessing any one JavaScript toolkit.
Each toolkit has its own relative strengths and weaknesses - use
Each toolkit has its own relative strengths and weaknesses - use
whichever toolkit suits your requirements. Django is able to integrate
with any JavaScript toolkit.
with any JavaScript toolkit.
Media as a static definition
----------------------------
The easiest way to define media is as a static definition. Using this method,
the media declaration is an inner class. The properties of the inner class
define the media requirements.
define the media requirements.
Here's a simple example::
@ -1891,12 +1891,12 @@ Here's a simple example::
js = ('animations.js', 'actions.js')
This code defines a ``CalendarWidget``, which will be based on ``TextInput``.
Every time the CalendarWidget is used on a form, that form will be directed
to include the CSS file ``pretty.css``, and the JavaScript files
``animations.js`` and ``actions.js``.
Every time the CalendarWidget is used on a form, that form will be directed
to include the CSS file ``pretty.css``, and the JavaScript files
``animations.js`` and ``actions.js``.
This static media definition is converted at runtime into a widget property
named ``media``. The media for a CalendarWidget instance can be retrieved
named ``media``. The media for a CalendarWidget instance can be retrieved
through this property::
>>> w = CalendarWidget()
@ -1910,16 +1910,16 @@ Here's a list of all possible ``Media`` options. There are no required options.
``css``
~~~~~~~
A dictionary describing the CSS files required for various forms of output
media.
A dictionary describing the CSS files required for various forms of output
media.
The values in the dictionary should be a tuple/list of file names. See
`the section on media paths`_ for details of how to specify paths to media
`the section on media paths`_ for details of how to specify paths to media
files.
.. _the section on media paths: `Paths in media definitions`_
The keys in the dictionary are the output media types. These are the same
The keys in the dictionary are the output media types. These are the same
types accepted by CSS files in media declarations: 'all', 'aural', 'braille',
'embossed', 'handheld', 'print', 'projection', 'screen', 'tty' and 'tv'. If
you need to have different stylesheets for different media types, provide
@ -1932,9 +1932,9 @@ provide two CSS options -- one for the screen, and one for print::
'print': ('newspaper.css',)
}
If a group of CSS files are appropriate for multiple output media types,
the dictionary key can be a comma separated list of output media types.
In the following example, TV's and projectors will have the same media
If a group of CSS files are appropriate for multiple output media types,
the dictionary key can be a comma separated list of output media types.
In the following example, TV's and projectors will have the same media
requirements::
class Media:
@ -1943,29 +1943,29 @@ requirements::
'tv,projector': ('lo_res.css',),
'print': ('newspaper.css',)
}
If this last CSS definition were to be rendered, it would become the following HTML::
<link href="http://media.example.com/pretty.css" type="text/css" media="screen" rel="stylesheet" />
<link href="http://media.example.com/lo_res.css" type="text/css" media="tv,projector" rel="stylesheet" />
<link href="http://media.example.com/newspaper.css" type="text/css" media="print" rel="stylesheet" />
``js``
~~~~~~
A tuple describing the required JavaScript files. See
`the section on media paths`_ for details of how to specify paths to media
`the section on media paths`_ for details of how to specify paths to media
files.
``extend``
``extend``
~~~~~~~~~~
A boolean defining inheritance behavior for media declarations.
A boolean defining inheritance behavior for media declarations.
By default, any object using a static media definition will inherit all the
media associated with the parent widget. This occurs regardless of how the
media associated with the parent widget. This occurs regardless of how the
parent defines its media requirements. For example, if we were to extend our
basic Calendar widget from the example above::
basic Calendar widget from the example above::
class FancyCalendarWidget(CalendarWidget):
class Media:
@ -1982,13 +1982,13 @@ basic Calendar widget from the example above::
<script type="text/javascript" src="http://media.example.com/actions.js"></script>
<script type="text/javascript" src="http://media.example.com/whizbang.js"></script>
The FancyCalendar widget inherits all the media from it's parent widget. If
The FancyCalendar widget inherits all the media from it's parent widget. If
you don't want media to be inherited in this way, add an ``extend=False``
declaration to the media declaration::
class FancyCalendar(Calendar):
class Media:
extend = False
extend = False
css = {
'all': ('fancy.css',)
}
@ -1999,19 +1999,19 @@ declaration to the media declaration::
<link href="http://media.example.com/fancy.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/whizbang.js"></script>
If you require even more control over media inheritance, define your media
If you require even more control over media inheritance, define your media
using a `dynamic property`_. Dynamic properties give you complete control over
which media files are inherited, and which are not.
.. _dynamic property: `Media as a dynamic property`_
Media as a dynamic property
---------------------------
If you need to perform some more sophisticated manipulation of media
requirements, you can define the media property directly. This is done
by defining a model property that returns an instance of ``forms.Media``.
The constructor for ``forms.Media`` accepts ``css`` and ``js`` keyword
The constructor for ``forms.Media`` accepts ``css`` and ``js`` keyword
arguments in the same format as that used in a static media definition.
For example, the static media definition for our Calendar Widget could
@ -2029,7 +2029,7 @@ return values for dynamic media properties.
Paths in media definitions
--------------------------
Paths used to specify media can be either relative or absolute. If a path
Paths used to specify media can be either relative or absolute. If a path
starts with '/', 'http://' or 'https://', it will be interpreted as an absolute
path, and left as-is. All other paths will be prepended with the value of
``settings.MEDIA_URL``. For example, if the MEDIA_URL for your site was
@ -2053,15 +2053,15 @@ Media objects
When you interrogate the media attribute of a widget or form, the value that
is returned is a ``forms.Media`` object. As we have already seen, the string
representation of a Media object is the HTML required to include media
in the ``<head>`` block of your HTML page.
representation of a Media object is the HTML required to include media
in the ``<head>`` block of your HTML page.
However, Media objects have some other interesting properties.
Media subsets
~~~~~~~~~~~~~
If you only want media of a particular type, you can use the subscript operator
If you only want media of a particular type, you can use the subscript operator
to filter out a medium of interest. For example::
>>> w = CalendarWidget()
@ -2073,7 +2073,7 @@ to filter out a medium of interest. For example::
>>> print w.media['css']
<link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" />
When you use the subscript operator, the value that is returned is a new
When you use the subscript operator, the value that is returned is a new
Media object -- but one that only contains the media of interest.
Combining media objects
@ -2100,7 +2100,7 @@ the resulting Media object contains the union of the media from both files::
<script type="text/javascript" src="http://media.example.com/animations.js"></script>
<script type="text/javascript" src="http://media.example.com/actions.js"></script>
<script type="text/javascript" src="http://media.example.com/whizbang.js"></script>
Media on Forms
--------------
@ -2109,8 +2109,8 @@ can also define media. The rules for media definitions on forms are the
same as the rules for widgets: declarations can be static or dynamic;
path and inheritance rules for those declarations are exactly the same.
Regardless of whether you define a media declaration, *all* Form objects
have a media property. The default value for this property is the result
Regardless of whether you define a media declaration, *all* Form objects
have a media property. The default value for this property is the result
of adding the media definitions for all widgets that are part of the form::
class ContactForm(forms.Form):
@ -2124,7 +2124,7 @@ of adding the media definitions for all widgets that are part of the form::
<script type="text/javascript" src="http://media.example.com/actions.js"></script>
<script type="text/javascript" src="http://media.example.com/whizbang.js"></script>
If you want to associate additional media with a form -- for example, CSS for form
If you want to associate additional media with a form -- for example, CSS for form
layout -- simply add a media declaration to the form::
class ContactForm(forms.Form):
@ -2135,7 +2135,7 @@ layout -- simply add a media declaration to the form::
css = {
'all': ('layout.css',)
}
>>> f = ContactForm()
>>> f.media
<link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" />
@ -2192,7 +2192,7 @@ example::
... {'title': u'Django is now open source',
... 'pub_date': datetime.date.today()},
... ])
>>> for form in formset.forms:
... print form.as_table()
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Django is now open source" id="id_form-0-title" /></td></tr>
@ -2281,11 +2281,11 @@ A formset has a ``clean`` method similar to the one on a ``Form`` class. This
is where you define your own validation that deals at the formset level::
>>> from django.forms.formsets import BaseFormSet
>>> class BaseArticleFormSet(BaseFormSet):
... def clean(self):
... raise forms.ValidationError, u'An error occured.'
>>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet)
>>> formset = ArticleFormSet({})
>>> formset.is_valid()
@ -2348,7 +2348,7 @@ happen when the user changes these values::
... 'form-2-pub_date': u'2008-05-01',
... 'form-2-ORDER': u'0',
... }
>>> formset = ArticleFormSet(data, initial=[
... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)},
@ -2403,7 +2403,7 @@ delete fields you can access them with ``deleted_forms``::
... 'form-2-pub_date': u'',
... 'form-2-DELETE': u'',
... }
>>> formset = ArticleFormSet(data, initial=[
... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)},