Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

boulder-oracle-sprint: Merged to [5127]

  • Loading branch information...
commit 5a7802586d117a75f91df04c032fd249808a877d 1 parent 3b479bf
Boulder Sprinters authored
View
BIN  django/conf/locale/de/LC_MESSAGES/django.mo
Binary file not shown
View
2,125 django/conf/locale/de/LC_MESSAGES/django.po
1,355 additions, 770 deletions not shown
View
4 django/conf/urls/defaults.py
@@ -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)
View
46 django/db/models/fields/__init__.py
@@ -346,11 +346,13 @@ def _get_choices(self):
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 @@ def get_manipulator_field_objs(self):
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 @@ def to_python(self, value):
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 @@ def flatten_data(self, follow, obj=None):
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 @@ def flatten_data(self,follow, obj = None):
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 @@ def validate(self, field_data, all_data):
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 @@ def get_manipulator_field_objs(self):
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 @@ def validate(self, field_data, all_data):
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 @@ def get_manipulator_field_objs(self):
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 @@ def flatten_data(self,follow, obj = None):
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 @@ def get_internal_type(self):
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):
View
18 django/db/models/fields/related.py
@@ -550,9 +550,9 @@ def contribute_to_related_class(self, cls, related):
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 @@ def contribute_to_related_class(self, cls, related):
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 @@ def value_from_object(self, obj):
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,
View
4 django/template/__init__.py
@@ -204,7 +204,7 @@ def tokenize(self):
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 @@ def tokenize(self):
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):
View
8 docs/db-api.txt
@@ -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)``
@@ -906,8 +906,8 @@ The database API supports the following lookup types:
exact
~~~~~
-Exact match. If the value provided for comparison is ``None``, it will
-be interpreted as an SQL ``NULL`` (See isnull_ for more details).
+Exact match. If the value provided for comparison is ``None``, it will
+be interpreted as an SQL ``NULL`` (See isnull_ for more details).
Examples::
View
15 docs/email.txt
@@ -21,20 +21,19 @@ In two lines::
['to@example.com'], fail_silently=False)
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.
+and `EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_
+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()
View
5 docs/settings.txt
@@ -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``.
View
41 tests/modeltests/model_forms/models.py
@@ -24,6 +24,12 @@
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 @@ def __str__(self):
>>> 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 @@ def __str__(self):
<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&#39;s a test</option>
@@ -200,6 +213,12 @@ def __str__(self):
<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&#39;s a test</option>
@@ -232,6 +251,12 @@ def __str__(self):
<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&#39;s a test</option>
@@ -310,6 +335,12 @@ def __str__(self):
<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&#39;s a test</option>
@@ -329,6 +360,12 @@ def __str__(self):
<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&#39;s a test</option>
View
2  tests/regressiontests/templates/tests.py
@@ -217,7 +217,7 @@ def test_templates(self):
# 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"),
Please sign in to comment.
Something went wrong with that request. Please try again.