1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Merged the newforms-admin branch into trunk.

This is a backward incompatible change. The admin contrib app has been
refactored. The newforms module has several improvements including FormSets
and Media definitions.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7967 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner
2008-07-18 23:54:34 +00:00
parent dc375fb0f3
commit a19ed8aea3
121 changed files with 8050 additions and 2680 deletions

View File

@@ -28,16 +28,10 @@ from django.utils import datetime_safe
class NOT_PROVIDED:
pass
# Values for filter_interface.
HORIZONTAL, VERTICAL = 1, 2
# The values to use for "blank" in SelectFields. Will be appended to the start of most "choices" lists.
BLANK_CHOICE_DASH = [("", "---------")]
BLANK_CHOICE_NONE = [("", "None")]
# returns the <ul> class for a given radio_admin value
get_ul_class = lambda x: 'radiolist%s' % ((x == HORIZONTAL) and ' inline' or '')
class FieldDoesNotExist(Exception):
pass
@@ -85,10 +79,10 @@ class Field(object):
def __init__(self, verbose_name=None, name=None, primary_key=False,
max_length=None, unique=False, blank=False, null=False,
db_index=False, core=False, rel=None, default=NOT_PROVIDED,
editable=True, serialize=True, prepopulate_from=None,
unique_for_date=None, unique_for_month=None, unique_for_year=None,
validator_list=None, choices=None, radio_admin=None, help_text='',
db_column=None, db_tablespace=None, auto_created=False):
editable=True, serialize=True, unique_for_date=None,
unique_for_month=None, unique_for_year=None, validator_list=None,
choices=None, help_text='', db_column=None, db_tablespace=None,
auto_created=False):
self.name = name
self.verbose_name = verbose_name
self.primary_key = primary_key
@@ -102,11 +96,9 @@ class Field(object):
self.editable = editable
self.serialize = serialize
self.validator_list = validator_list or []
self.prepopulate_from = prepopulate_from
self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month
self.unique_for_year = unique_for_year
self._choices = choices or []
self.radio_admin = radio_admin
self.help_text = help_text
self.db_column = db_column
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
@@ -294,11 +286,7 @@ class Field(object):
params['max_length'] = self.max_length
if self.choices:
if self.radio_admin:
field_objs = [oldforms.RadioSelectField]
params['ul_class'] = get_ul_class(self.radio_admin)
else:
field_objs = [oldforms.SelectField]
field_objs = [oldforms.SelectField]
params['choices'] = self.get_choices_default()
else:
@@ -386,10 +374,7 @@ class Field(object):
return first_choice + lst
def get_choices_default(self):
if self.radio_admin:
return self.get_choices(include_blank=self.blank, blank_choice=BLANK_CHOICE_NONE)
else:
return self.get_choices()
return self.get_choices()
def _get_val_from_obj(self, obj):
if obj:
@@ -1012,7 +997,11 @@ class NullBooleanField(Field):
return [oldforms.NullBooleanField]
def formfield(self, **kwargs):
defaults = {'form_class': forms.NullBooleanField}
defaults = {
'form_class': forms.NullBooleanField,
'required': not self.blank,
'label': capfirst(self.verbose_name),
'help_text': self.help_text}
defaults.update(kwargs)
return super(NullBooleanField, self).formfield(**defaults)