mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
unicode: Merged from trunk up to [5265].
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5279 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c0b451fcfa
commit
6042458926
@ -578,7 +578,7 @@ def syncdb(verbosity=1, interactive=True):
|
|||||||
# Install the 'initialdata' fixture, using format discovery
|
# Install the 'initialdata' fixture, using format discovery
|
||||||
load_data(['initial_data'], verbosity=verbosity)
|
load_data(['initial_data'], verbosity=verbosity)
|
||||||
syncdb.help_doc = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
|
syncdb.help_doc = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
|
||||||
syncdb.args = '[--verbosity] [--interactive]'
|
syncdb.args = '[--verbosity] [--noinput]'
|
||||||
|
|
||||||
def get_admin_index(app):
|
def get_admin_index(app):
|
||||||
"Returns admin-index template snippet (in list form) for the given app."
|
"Returns admin-index template snippet (in list form) for the given app."
|
||||||
@ -672,7 +672,7 @@ The full error: """ % (app_name, app_name)) + style.ERROR_OUTPUT(str(e)) + '\n')
|
|||||||
else:
|
else:
|
||||||
print "Reset cancelled."
|
print "Reset cancelled."
|
||||||
reset.help_doc = "Executes ``sqlreset`` for the given app(s) in the current database."
|
reset.help_doc = "Executes ``sqlreset`` for the given app(s) in the current database."
|
||||||
reset.args = '[--interactive]' + APP_ARGS
|
reset.args = '[--noinput]' + APP_ARGS
|
||||||
|
|
||||||
def flush(verbosity=1, interactive=True):
|
def flush(verbosity=1, interactive=True):
|
||||||
"Returns all tables in the database to the same state they were in immediately after syncdb."
|
"Returns all tables in the database to the same state they were in immediately after syncdb."
|
||||||
@ -733,7 +733,7 @@ The full error: """ % settings.DATABASE_NAME + style.ERROR_OUTPUT(str(e)) + '\n'
|
|||||||
else:
|
else:
|
||||||
print "Flush cancelled."
|
print "Flush cancelled."
|
||||||
flush.help_doc = "Executes ``sqlflush`` on the current database."
|
flush.help_doc = "Executes ``sqlflush`` on the current database."
|
||||||
flush.args = '[--verbosity] [--interactive]'
|
flush.args = '[--verbosity] [--noinput]'
|
||||||
|
|
||||||
def _start_helper(app_or_project, name, directory, other_name=''):
|
def _start_helper(app_or_project, name, directory, other_name=''):
|
||||||
other = {'project': 'app', 'app': 'project'}[app_or_project]
|
other = {'project': 'app', 'app': 'project'}[app_or_project]
|
||||||
@ -1452,7 +1452,7 @@ def dump_data(app_labels, format='json', indent=None):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.stderr.write(style.ERROR("Unable to serialize database: %s\n" % e))
|
sys.stderr.write(style.ERROR("Unable to serialize database: %s\n" % e))
|
||||||
dump_data.help_doc = 'Output the contents of the database as a fixture of the given format'
|
dump_data.help_doc = 'Output the contents of the database as a fixture of the given format'
|
||||||
dump_data.args = '[--format]' + APP_ARGS
|
dump_data.args = '[--format] [--indent]' + APP_ARGS
|
||||||
|
|
||||||
# Utilities for command-line script
|
# Utilities for command-line script
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
Extra HTML Widget classes
|
Extra HTML Widget classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
from django.newforms.widgets import Widget, Select
|
from django.newforms.widgets import Widget, Select
|
||||||
from django.utils.dates import MONTHS
|
from django.utils.dates import MONTHS
|
||||||
import datetime
|
|
||||||
|
|
||||||
__all__ = ('SelectDateWidget',)
|
__all__ = ('SelectDateWidget',)
|
||||||
|
|
||||||
|
@ -2,14 +2,16 @@
|
|||||||
Field classes
|
Field classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.translation import ugettext
|
|
||||||
from django.utils.encoding import smart_unicode
|
|
||||||
from util import ErrorList, ValidationError
|
|
||||||
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
|
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext
|
||||||
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
|
from util import ErrorList, ValidationError
|
||||||
|
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Field', 'CharField', 'IntegerField',
|
'Field', 'CharField', 'IntegerField',
|
||||||
'DEFAULT_DATE_INPUT_FORMATS', 'DateField',
|
'DEFAULT_DATE_INPUT_FORMATS', 'DateField',
|
||||||
|
@ -2,13 +2,15 @@
|
|||||||
Form classes
|
Form classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.datastructures import SortedDict, MultiValueDict
|
import copy
|
||||||
|
|
||||||
|
from django.utils.datastructures import SortedDict
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.encoding import StrAndUnicode, smart_unicode
|
from django.utils.encoding import StrAndUnicode, smart_unicode
|
||||||
|
|
||||||
from fields import Field
|
from fields import Field
|
||||||
from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
|
from widgets import TextInput, Textarea
|
||||||
from util import flatatt, ErrorDict, ErrorList, ValidationError
|
from util import flatatt, ErrorDict, ErrorList, ValidationError
|
||||||
import copy
|
|
||||||
|
|
||||||
__all__ = ('BaseForm', 'Form')
|
__all__ = ('BaseForm', 'Form')
|
||||||
|
|
||||||
|
@ -5,13 +5,16 @@ and database field objects.
|
|||||||
|
|
||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
from util import ValidationError
|
from util import ValidationError
|
||||||
from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList
|
from forms import BaseForm, SortedDictFromList
|
||||||
from fields import Field, ChoiceField
|
from fields import Field, ChoiceField
|
||||||
from widgets import Select, SelectMultiple, MultipleHiddenInput
|
from widgets import Select, SelectMultiple, MultipleHiddenInput
|
||||||
|
|
||||||
__all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields',
|
__all__ = (
|
||||||
'ModelChoiceField', 'ModelMultipleChoiceField')
|
'save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields',
|
||||||
|
'ModelChoiceField', 'ModelMultipleChoiceField'
|
||||||
|
)
|
||||||
|
|
||||||
def save_instance(form, instance, fields=None, fail_message='saved', commit=True):
|
def save_instance(form, instance, fields=None, fail_message='saved', commit=True):
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
from django.conf import settings
|
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.functional import Promise, lazy
|
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
# Converts a dictionary to a single string with key="value", XML-style with
|
# Converts a dictionary to a single string with key="value", XML-style with
|
||||||
|
@ -2,24 +2,26 @@
|
|||||||
HTML Widget classes
|
HTML Widget classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = (
|
|
||||||
'Widget', 'TextInput', 'PasswordInput', 'HiddenInput', 'MultipleHiddenInput',
|
|
||||||
'FileInput', 'Textarea', 'CheckboxInput',
|
|
||||||
'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect', 'CheckboxSelectMultiple',
|
|
||||||
'MultiWidget', 'SplitDateTimeWidget',
|
|
||||||
)
|
|
||||||
|
|
||||||
from util import flatatt
|
|
||||||
from django.utils.datastructures import MultiValueDict
|
|
||||||
from django.utils.html import escape
|
|
||||||
from django.utils.translation import ugettext
|
|
||||||
from django.utils.encoding import StrAndUnicode, smart_unicode
|
|
||||||
from itertools import chain
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set # Only available in Python 2.4+
|
set # Only available in Python 2.4+
|
||||||
except NameError:
|
except NameError:
|
||||||
from sets import Set as set # Python 2.3 fallback
|
from sets import Set as set # Python 2.3 fallback
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
|
from django.utils.datastructures import MultiValueDict
|
||||||
|
from django.utils.html import escape
|
||||||
|
from django.utils.translation import ugettext
|
||||||
|
from django.utils.encoding import StrAndUnicode, smart_unicode
|
||||||
|
|
||||||
|
from util import flatatt
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'Widget', 'TextInput', 'PasswordInput',
|
||||||
|
'HiddenInput', 'MultipleHiddenInput',
|
||||||
|
'FileInput', 'Textarea', 'CheckboxInput',
|
||||||
|
'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect',
|
||||||
|
'CheckboxSelectMultiple', 'MultiWidget', 'SplitDateTimeWidget',
|
||||||
|
)
|
||||||
|
|
||||||
class Widget(object):
|
class Widget(object):
|
||||||
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
||||||
|
@ -279,6 +279,15 @@ Please follow these coding standards when writing code for inclusion in Django:
|
|||||||
* Mark all strings for internationalization; see the `i18n documentation`_
|
* Mark all strings for internationalization; see the `i18n documentation`_
|
||||||
for details.
|
for details.
|
||||||
|
|
||||||
|
* Please don't put your name in the code you contribute. Our policy is to
|
||||||
|
keep contributors' names in the ``AUTHORS`` file distributed with Django
|
||||||
|
-- not scattered throughout the codebase itself. Feel free to include a
|
||||||
|
change to the ``AUTHORS`` file in your patch if you make more than a
|
||||||
|
single trivial change.
|
||||||
|
|
||||||
|
Template style
|
||||||
|
--------------
|
||||||
|
|
||||||
* In Django template code, put one (and only one) space between the curly
|
* In Django template code, put one (and only one) space between the curly
|
||||||
brackets and the tag contents.
|
brackets and the tag contents.
|
||||||
|
|
||||||
@ -290,6 +299,9 @@ Please follow these coding standards when writing code for inclusion in Django:
|
|||||||
|
|
||||||
{{foo}}
|
{{foo}}
|
||||||
|
|
||||||
|
View style
|
||||||
|
----------
|
||||||
|
|
||||||
* In Django views, the first parameter in a view function should be called
|
* In Django views, the first parameter in a view function should be called
|
||||||
``request``.
|
``request``.
|
||||||
|
|
||||||
@ -303,11 +315,72 @@ Please follow these coding standards when writing code for inclusion in Django:
|
|||||||
def my_view(req, foo):
|
def my_view(req, foo):
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
* Please don't put your name in the code you contribute. Our policy is to
|
Model style
|
||||||
keep contributors' names in the ``AUTHORS`` file distributed with Django
|
-----------
|
||||||
-- not scattered throughout the codebase itself. Feel free to include a
|
|
||||||
change to the ``AUTHORS`` file in your patch if you make more than a
|
* Field names should be all lowercase, using underscores instead of
|
||||||
single trivial change.
|
camelCase.
|
||||||
|
|
||||||
|
Do this::
|
||||||
|
|
||||||
|
class Person(models.Model):
|
||||||
|
first_name = models.CharField(maxlength=20)
|
||||||
|
last_name = models.CharField(maxlength=40)
|
||||||
|
|
||||||
|
Don't do this::
|
||||||
|
|
||||||
|
class Person(models.Model):
|
||||||
|
FirstName = models.CharField(maxlength=20)
|
||||||
|
Last_Name = models.CharField(maxlength=40)
|
||||||
|
|
||||||
|
* The ``class Meta`` should appear *after* the fields are defined, with
|
||||||
|
a single blank line separating the fields and the class definition.
|
||||||
|
|
||||||
|
Do this::
|
||||||
|
|
||||||
|
class Person(models.Model):
|
||||||
|
first_name = models.CharField(maxlength=20)
|
||||||
|
last_name = models.CharField(maxlength=40)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = 'people'
|
||||||
|
|
||||||
|
Don't do this::
|
||||||
|
|
||||||
|
class Person(models.Model):
|
||||||
|
first_name = models.CharField(maxlength=20)
|
||||||
|
last_name = models.CharField(maxlength=40)
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = 'people'
|
||||||
|
|
||||||
|
Don't do this, either::
|
||||||
|
|
||||||
|
class Person(models.Model):
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = 'people'
|
||||||
|
|
||||||
|
first_name = models.CharField(maxlength=20)
|
||||||
|
last_name = models.CharField(maxlength=40)
|
||||||
|
|
||||||
|
* The order of model inner classes and standard methods should be as
|
||||||
|
follows (noting that these are not all required):
|
||||||
|
|
||||||
|
* All database fields
|
||||||
|
* ``class Meta``
|
||||||
|
* ``class Admin``
|
||||||
|
* ``def __str__()``
|
||||||
|
* ``def save()``
|
||||||
|
* ``def get_absolute_url()``
|
||||||
|
* Any custom methods
|
||||||
|
|
||||||
|
* If ``choices`` is defined for a given model field, define the choices as
|
||||||
|
a tuple of tuples, with an all-uppercase name, either near the top of the
|
||||||
|
model module or just above the model class. Example::
|
||||||
|
|
||||||
|
GENDER_CHOICES = (
|
||||||
|
('M', 'Male'),
|
||||||
|
('F', 'Female'),
|
||||||
|
)
|
||||||
|
|
||||||
Committing code
|
Committing code
|
||||||
===============
|
===============
|
||||||
|
@ -1765,8 +1765,8 @@ exist. For example::
|
|||||||
|
|
||||||
When you provide a model to this shortcut function, the default manager
|
When you provide a model to this shortcut function, the default manager
|
||||||
is used to execute the underlying ``get()`` query. If you don't want to
|
is used to execute the underlying ``get()`` query. If you don't want to
|
||||||
use the default manager, or you want to search a list of related objects,
|
use the default manager, or if you want to search a list of related objects,
|
||||||
you can provide ``get_object_or_404()`` with a manager object, instead.
|
you can provide ``get_object_or_404()`` with a manager object instead.
|
||||||
For example::
|
For example::
|
||||||
|
|
||||||
# Get the author of blog instance `e` with a name of 'Fred'
|
# Get the author of blog instance `e` with a name of 'Fred'
|
||||||
@ -1779,8 +1779,8 @@ For example::
|
|||||||
get_list_or_404()
|
get_list_or_404()
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
``get_list_or_404`` behaves the same was as ``get_object_or_404()``
|
``get_list_or_404`` behaves the same way as ``get_object_or_404()``
|
||||||
-- except the it uses using ``filter()`` instead of ``get()``. It raises
|
-- except that it uses ``filter()`` instead of ``get()``. It raises
|
||||||
``Http404`` if the list is empty.
|
``Http404`` if the list is empty.
|
||||||
|
|
||||||
Falling back to raw SQL
|
Falling back to raw SQL
|
||||||
|
@ -1759,6 +1759,15 @@ But this template code is good::
|
|||||||
|
|
||||||
<a href="{{ object.get_absolute_url }}">{{ object.name }}</a>
|
<a href="{{ object.get_absolute_url }}">{{ object.name }}</a>
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
The string you return from ``get_absolute_url()`` must be use only ASCII
|
||||||
|
characters (required by the URI spec, `RFC 2396`_) that has been
|
||||||
|
URL-encoded, if necessary. Code and templates using ``get_absolute_url()``
|
||||||
|
should be able to use the result directly without needing to do any
|
||||||
|
further processing.
|
||||||
|
|
||||||
|
.. _RFC 2396: http://www.ietf.org/rfc/rfc2396.txt
|
||||||
|
|
||||||
The ``permalink`` decorator
|
The ``permalink`` decorator
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -146,7 +146,10 @@ put into those elements.
|
|||||||
exist, it tries calling a method ``item_link()`` in the ``Feed`` class,
|
exist, it tries calling a method ``item_link()`` in the ``Feed`` class,
|
||||||
passing it a single parameter, ``item``, which is the object itself.
|
passing it a single parameter, ``item``, which is the object itself.
|
||||||
Both ``get_absolute_url()`` and ``item_link()`` should return the item's
|
Both ``get_absolute_url()`` and ``item_link()`` should return the item's
|
||||||
URL as a normal Python string.
|
URL as a normal Python string. As with ``get_absolute_url()``, the
|
||||||
|
result of ``item_link()`` will be included directly in the URL, so you
|
||||||
|
are responsible for doing all necessary URL quoting and conversion to
|
||||||
|
ASCII inside the method itself.
|
||||||
|
|
||||||
* For the LatestEntries example above, we could have very simple feed templates:
|
* For the LatestEntries example above, we could have very simple feed templates:
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ _django_completion()
|
|||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
# Standalone options
|
# Standalone options
|
||||||
opts="--help --settings --pythonpath --version"
|
opts="--help --settings --pythonpath --noinput --noreload --format --indent --verbosity --adminmedia --version"
|
||||||
# Actions
|
# Actions
|
||||||
actions="adminindex createcachetable dbshell diffsettings \
|
actions="adminindex createcachetable dbshell diffsettings \
|
||||||
inspectdb install reset runfcgi runserver \
|
dumpdata flush inspectdb loaddata reset runfcgi runserver \
|
||||||
shell sql sqlall sqlclear sqlindexes sqlinitialdata \
|
shell sql sqlall sqlclear sqlcustom sqlflush sqlindexes \
|
||||||
sqlreset sqlsequencereset startapp startproject \
|
sqlreset sqlsequencereset startapp startproject \
|
||||||
syncdb validate"
|
syncdb test validate"
|
||||||
# Action's options
|
# Action's options
|
||||||
action_shell_opts="--plain"
|
action_shell_opts="--plain"
|
||||||
action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir"
|
action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir"
|
||||||
@ -84,33 +84,33 @@ _django_completion()
|
|||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
case ${prev} in
|
case ${prev} in
|
||||||
adminindex|install|reset| \
|
adminindex|dumpdata|reset| \
|
||||||
sql|sqlall|sqlclear|sqlindexes| \
|
sql|sqlall|sqlclear|sqlcustom|sqlindexes| \
|
||||||
sqlinitialdata|sqlreset|sqlsequencereset)
|
sqlreset|sqlsequencereset|test)
|
||||||
# App completion
|
# App completion
|
||||||
settings=""
|
settings=""
|
||||||
# If settings.py in the PWD, use that
|
# If settings.py in the PWD, use that
|
||||||
if [ -e settings.py ] ; then
|
if [ -e settings.py ] ; then
|
||||||
settings="$PWD/settings.py"
|
settings="$PWD/settings.py"
|
||||||
else
|
else
|
||||||
# Use the ENV variable if it is set
|
# Use the ENV variable if it is set
|
||||||
if [ $DJANGO_SETTINGS_MODULE ] ; then
|
if [ $DJANGO_SETTINGS_MODULE ] ; then
|
||||||
settings=$DJANGO_SETTINGS_MODULE
|
settings=$DJANGO_SETTINGS_MODULE
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
# Couldn't find settings so return nothing
|
||||||
# Couldn't find settings so return nothing
|
if [ -z $settings ] ; then
|
||||||
if [ -z $settings ] ; then
|
COMPREPLY=()
|
||||||
COMPREPLY=()
|
# Otherwise inspect settings.py file
|
||||||
# Otherwise inspect settings.py file
|
else
|
||||||
else
|
apps=`sed -n "/INSTALLED_APPS = (/,/)/p" $settings | \
|
||||||
apps=`sed -n "/INSTALLED_APPS = (/,/)/p" $settings | \
|
grep -v "django.contrib" |
|
||||||
grep -v "django.contrib" |
|
sed -n "s/^[ ]*'\(.*\.\)*\(.*\)'.*$/\2 /pg" | \
|
||||||
sed -n "s/^[ ]*'\(.*\.\)*\(.*\)'.*$/\2 /pg" | \
|
tr -d "\n"`
|
||||||
tr -d "\n"`
|
COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) )
|
||||||
COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) )
|
fi
|
||||||
fi
|
return 0
|
||||||
return 0
|
;;
|
||||||
;;
|
|
||||||
|
|
||||||
createcachetable|dbshell|diffsettings| \
|
createcachetable|dbshell|diffsettings| \
|
||||||
inspectdb|runserver|startapp|startproject|syncdb| \
|
inspectdb|runserver|startapp|startproject|syncdb| \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user