mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
boulder-oracle-sprint: Merged to [5127]
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5128 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3b479bfc56
commit
5a7802586d
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -22,5 +22,7 @@ def url(regex, view, kwargs=None, name=None, prefix=''):
|
||||
# For include(...) processing.
|
||||
return RegexURLResolver(regex, view[0], kwargs)
|
||||
else:
|
||||
return RegexURLPattern(regex, prefix and (prefix + '.' + view) or view, kwargs, name)
|
||||
if prefix and isinstance(view, basestring):
|
||||
view = prefix + '.' + view
|
||||
return RegexURLPattern(regex, view, kwargs, name)
|
||||
|
||||
|
@ -346,11 +346,13 @@ class Field(object):
|
||||
return self._choices
|
||||
choices = property(_get_choices)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
def formfield(self, form_class=forms.CharField, **kwargs):
|
||||
"Returns a django.newforms.Field instance for this database Field."
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
if self.choices:
|
||||
defaults['widget'] = forms.Select(choices=self.get_choices())
|
||||
defaults.update(kwargs)
|
||||
return forms.CharField(**defaults)
|
||||
return form_class(**defaults)
|
||||
|
||||
def value_from_object(self, obj):
|
||||
"Returns the value of this field in the given model instance."
|
||||
@ -410,9 +412,9 @@ class BooleanField(Field):
|
||||
return [oldforms.CheckboxField]
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.BooleanField}
|
||||
defaults.update(kwargs)
|
||||
return forms.BooleanField(**defaults)
|
||||
return super(BooleanField, self).formfield(**defaults)
|
||||
|
||||
class CharField(Field):
|
||||
def get_manipulator_field_objs(self):
|
||||
@ -429,9 +431,9 @@ class CharField(Field):
|
||||
return str(value)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'max_length': self.maxlength}
|
||||
defaults.update(kwargs)
|
||||
return forms.CharField(**defaults)
|
||||
return super(CharField, self).formfield(**defaults)
|
||||
|
||||
# TODO: Maybe move this into contrib, because it's specialized.
|
||||
class CommaSeparatedIntegerField(CharField):
|
||||
@ -507,9 +509,9 @@ class DateField(Field):
|
||||
return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.DateField}
|
||||
defaults.update(kwargs)
|
||||
return forms.DateField(**defaults)
|
||||
return super(DateField, self).formfield(**defaults)
|
||||
|
||||
class DateTimeField(DateField):
|
||||
def to_python(self, value):
|
||||
@ -576,9 +578,9 @@ class DateTimeField(DateField):
|
||||
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.DateTimeField}
|
||||
defaults.update(kwargs)
|
||||
return forms.DateTimeField(**defaults)
|
||||
return super(DateTimeField, self).formfield(**defaults)
|
||||
|
||||
class EmailField(CharField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -595,9 +597,9 @@ class EmailField(CharField):
|
||||
validators.isValidEmail(field_data, all_data)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.EmailField}
|
||||
defaults.update(kwargs)
|
||||
return forms.EmailField(**defaults)
|
||||
return super(EmailField, self).formfield(**defaults)
|
||||
|
||||
class FileField(Field):
|
||||
def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs):
|
||||
@ -732,9 +734,9 @@ class IntegerField(Field):
|
||||
return [oldforms.IntegerField]
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.IntegerField}
|
||||
defaults.update(kwargs)
|
||||
return forms.IntegerField(**defaults)
|
||||
return super(IntegerField, self).formfield(**defaults)
|
||||
|
||||
class IPAddressField(Field):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -771,9 +773,9 @@ class PhoneNumberField(IntegerField):
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
from django.contrib.localflavor.us.forms import USPhoneNumberField
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': USPhoneNumberField}
|
||||
defaults.update(kwargs)
|
||||
return USPhoneNumberField(**defaults)
|
||||
return super(PhoneNumberField, self).formfield(**defaults)
|
||||
|
||||
class PositiveIntegerField(IntegerField):
|
||||
def get_manipulator_field_objs(self):
|
||||
@ -804,9 +806,9 @@ class TextField(Field):
|
||||
return [oldforms.LargeTextField]
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'widget': forms.Textarea}
|
||||
defaults.update(kwargs)
|
||||
return forms.CharField(**defaults)
|
||||
return super(TextField, self).formfield(**defaults)
|
||||
|
||||
class TimeField(Field):
|
||||
empty_strings_allowed = False
|
||||
@ -864,9 +866,9 @@ class TimeField(Field):
|
||||
return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.TimeField}
|
||||
defaults.update(kwargs)
|
||||
return forms.TimeField(**defaults)
|
||||
return super(TimeField, self).formfield(**defaults)
|
||||
|
||||
class URLField(CharField):
|
||||
def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
|
||||
@ -883,9 +885,9 @@ class URLField(CharField):
|
||||
return "CharField"
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'required': not self.blank, 'verify_exists': self.verify_exists, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.URLField, 'verify_exists': self.verify_exists}
|
||||
defaults.update(kwargs)
|
||||
return forms.URLField(**defaults)
|
||||
return super(URLField, self).formfield(**defaults)
|
||||
|
||||
class USStateField(Field):
|
||||
def get_manipulator_field_objs(self):
|
||||
|
@ -550,9 +550,9 @@ class ForeignKey(RelatedField, Field):
|
||||
setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
|
||||
defaults.update(kwargs)
|
||||
return forms.ModelChoiceField(**defaults)
|
||||
return super(ForeignKey, self).formfield(**defaults)
|
||||
|
||||
class OneToOneField(RelatedField, IntegerField):
|
||||
def __init__(self, to, to_field=None, **kwargs):
|
||||
@ -616,9 +616,9 @@ class OneToOneField(RelatedField, IntegerField):
|
||||
cls._meta.one_to_one_field = self
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
|
||||
defaults.update(kwargs)
|
||||
return forms.ModelChoiceField(**defaults)
|
||||
return super(OneToOneField, self).formfield(**defaults)
|
||||
|
||||
class ManyToManyField(RelatedField, Field):
|
||||
def __init__(self, to, **kwargs):
|
||||
@ -735,13 +735,13 @@ class ManyToManyField(RelatedField, Field):
|
||||
return getattr(obj, self.attname).all()
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()}
|
||||
defaults.update(kwargs)
|
||||
# If initial is passed in, it's a list of related objects, but the
|
||||
# MultipleChoiceField takes a list of IDs.
|
||||
if kwargs.get('initial') is not None:
|
||||
kwargs['initial'] = [i._get_pk_val() for i in kwargs['initial']]
|
||||
defaults = {'queryset' : self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||
defaults.update(kwargs)
|
||||
return forms.ModelMultipleChoiceField(**defaults)
|
||||
if defaults.get('initial') is not None:
|
||||
defaults['initial'] = [i._get_pk_val() for i in defaults['initial']]
|
||||
return super(ManyToManyField, self).formfield(**defaults)
|
||||
|
||||
class ManyToOneRel(object):
|
||||
def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None,
|
||||
|
@ -204,7 +204,7 @@ class Lexer(object):
|
||||
def create_token(self, token_string, in_tag):
|
||||
"""
|
||||
Convert the given token string into a new Token object and return it.
|
||||
If tag is True, we are processing something that matched a tag,
|
||||
If in_tag is True, we are processing something that matched a tag,
|
||||
otherwise it should be treated as a literal string.
|
||||
"""
|
||||
if in_tag:
|
||||
@ -239,7 +239,7 @@ class DebugLexer(Lexer):
|
||||
|
||||
def create_token(self, token_string, source, in_tag):
|
||||
token = super(DebugLexer, self).create_token(token_string, in_tag)
|
||||
token.source = source
|
||||
token.source = self.origin, source
|
||||
return token
|
||||
|
||||
class Parser(object):
|
||||
|
@ -112,7 +112,7 @@ the previous record in the database::
|
||||
b4 = Blog(id=3, name='Not Cheddar', tagline='Anything but cheese.')
|
||||
b4.save() # Overrides the previous blog with ID=3!
|
||||
|
||||
See _`How Django knows to UPDATE vs. INSERT`, below, for the reason this
|
||||
See `How Django knows to UPDATE vs. INSERT`_, below, for the reason this
|
||||
happens.
|
||||
|
||||
Explicitly specifying auto-primary-key values is mostly useful for bulk-saving
|
||||
@ -714,7 +714,7 @@ QuerySet methods that do not return QuerySets
|
||||
The following ``QuerySet`` methods evaluate the ``QuerySet`` and return
|
||||
something *other than* a ``QuerySet``.
|
||||
|
||||
These methods do not use a cache (see _`Caching and QuerySets` below). Rather,
|
||||
These methods do not use a cache (see `Caching and QuerySets`_ below). Rather,
|
||||
they query the database each time they're called.
|
||||
|
||||
``get(**kwargs)``
|
||||
|
@ -22,19 +22,18 @@ In two lines::
|
||||
|
||||
Mail will be sent using the SMTP host and port specified in the `EMAIL_HOST`_
|
||||
and `EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_
|
||||
settings, if set, will be used to authenticate to the
|
||||
SMTP server.
|
||||
settings, if set, will be used to authenticate to the SMTP server.
|
||||
|
||||
.. note::
|
||||
|
||||
The character set of email sent with ``django.core.mail`` will be set to
|
||||
the value of your `DEFAULT_CHARSET setting`_.
|
||||
|
||||
.. _DEFAULT_CHARSET setting: ../settings/#DEFAULT_CHARSET
|
||||
.. _EMAIL_HOST: ../settings/#EMAIL_HOST
|
||||
.. _EMAIL_PORT: ../settings/#EMAIL_PORT
|
||||
.. _EMAIL_HOST_USER: ../settings/#EMAIL_HOST_USER
|
||||
.. _EMAIL_HOST_PASSWORD: ../settings/#EMAIL_HOST_PASSWORD
|
||||
.. _DEFAULT_CHARSET setting: ../settings/#default-charset
|
||||
.. _EMAIL_HOST: ../settings/#email-host
|
||||
.. _EMAIL_PORT: ../settings/#email-port
|
||||
.. _EMAIL_HOST_USER: ../settings/#email-host-user
|
||||
.. _EMAIL_HOST_PASSWORD: ../settings/#email-host-password
|
||||
|
||||
|
||||
send_mail()
|
||||
|
@ -396,8 +396,9 @@ EMAIL_HOST_PASSWORD
|
||||
Default: ``''`` (Empty string)
|
||||
|
||||
Password to use for the SMTP server defined in ``EMAIL_HOST``. This setting is
|
||||
used in conjunction with EMAIL_HOST_USER when authenticating to the SMTP server.
|
||||
If either of these settings is empty, Django won't attempt authenticaion.
|
||||
used in conjunction with ``EMAIL_HOST_USER`` when authenticating to the SMTP
|
||||
server. If either of these settings is empty, Django won't attempt
|
||||
authenticaion.
|
||||
|
||||
See also ``EMAIL_HOST_USER``.
|
||||
|
||||
|
@ -24,6 +24,12 @@ a commit=True parameter.
|
||||
|
||||
from django.db import models
|
||||
|
||||
ARTICLE_STATUS = (
|
||||
(1, 'Draft'),
|
||||
(2, 'Pending'),
|
||||
(3, 'Live'),
|
||||
)
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(maxlength=20)
|
||||
url = models.CharField('The URL', maxlength=40)
|
||||
@ -44,6 +50,7 @@ class Article(models.Model):
|
||||
writer = models.ForeignKey(Writer)
|
||||
article = models.TextField()
|
||||
categories = models.ManyToManyField(Category, blank=True)
|
||||
status = models.IntegerField(choices=ARTICLE_STATUS, blank=True, null=True)
|
||||
|
||||
def save(self):
|
||||
import datetime
|
||||
@ -147,8 +154,8 @@ Create a couple of Writers.
|
||||
>>> w = Writer(name='Bob Woodward')
|
||||
>>> w.save()
|
||||
|
||||
ManyToManyFields are represented by a MultipleChoiceField, and ForeignKeys are
|
||||
represented by a ChoiceField.
|
||||
ManyToManyFields are represented by a MultipleChoiceField, ForeignKeys and any
|
||||
fields with the 'choices' attribute are represented by a ChoiceField.
|
||||
>>> ArticleForm = form_for_model(Article)
|
||||
>>> f = ArticleForm(auto_id=False)
|
||||
>>> print f
|
||||
@ -160,6 +167,12 @@ represented by a ChoiceField.
|
||||
<option value="2">Bob Woodward</option>
|
||||
</select></td></tr>
|
||||
<tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
|
||||
<tr><th>Status:</th><td><select name="status">
|
||||
<option value="" selected="selected">---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></td></tr>
|
||||
<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
|
||||
<option value="1">Entertainment</option>
|
||||
<option value="2">It's a test</option>
|
||||
@ -200,6 +213,12 @@ current values are inserted as 'initial' data in each Field.
|
||||
<option value="2">Bob Woodward</option>
|
||||
</select></li>
|
||||
<li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
|
||||
<li>Status: <select name="status">
|
||||
<option value="" selected="selected">---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></li>
|
||||
<li>Categories: <select multiple="multiple" name="categories">
|
||||
<option value="1">Entertainment</option>
|
||||
<option value="2">It's a test</option>
|
||||
@ -232,6 +251,12 @@ Add some categories and test the many-to-many form output.
|
||||
<option value="2">Bob Woodward</option>
|
||||
</select></li>
|
||||
<li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
|
||||
<li>Status: <select name="status">
|
||||
<option value="" selected="selected">---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></li>
|
||||
<li>Categories: <select multiple="multiple" name="categories">
|
||||
<option value="1" selected="selected">Entertainment</option>
|
||||
<option value="2">It's a test</option>
|
||||
@ -310,6 +335,12 @@ the data in the database when the form is instantiated.
|
||||
<option value="2">Bob Woodward</option>
|
||||
</select></li>
|
||||
<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
|
||||
<li>Status: <select name="status">
|
||||
<option value="" selected="selected">---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></li>
|
||||
<li>Categories: <select multiple="multiple" name="categories">
|
||||
<option value="1">Entertainment</option>
|
||||
<option value="2">It's a test</option>
|
||||
@ -329,6 +360,12 @@ the data in the database when the form is instantiated.
|
||||
<option value="3">Carl Bernstein</option>
|
||||
</select></li>
|
||||
<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
|
||||
<li>Status: <select name="status">
|
||||
<option value="" selected="selected">---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></li>
|
||||
<li>Categories: <select multiple="multiple" name="categories">
|
||||
<option value="1">Entertainment</option>
|
||||
<option value="2">It's a test</option>
|
||||
|
@ -217,7 +217,7 @@ class Templates(unittest.TestCase):
|
||||
|
||||
# If a variable has a __str__() that returns a Unicode object, the
|
||||
# value will be converted to a bytestring.
|
||||
'basic-syntax18': (r'{{ var }}', {'var': UnicodeInStrClass()}, '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'),
|
||||
'filter-syntax18': (r'{{ var }}', {'var': UnicodeInStrClass()}, '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'),
|
||||
|
||||
### COMMENT SYNTAX ########################################################
|
||||
'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user