1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +00:00

new-admin: Negligible formatting changes to django/core/meta/fields.py

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1414 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-25 01:51:19 +00:00
parent 88fb208912
commit 5c60773256

View File

@ -57,8 +57,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
return return
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname): if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
return return
raise validators.ValidationError, _("%(optname)s with this %(fieldname)s already exists.") % {'optname':capfirst(opts.verbose_name), 'fieldname':f.verbose_name} raise validators.ValidationError, _("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name}
class BoundField(object): class BoundField(object):
def __init__(self, field, field_mapping, original): def __init__(self, field, field_mapping, original):
@ -77,8 +76,7 @@ class BoundField(object):
return self.original.__dict__[self.field.column] return self.original.__dict__[self.field.column]
def __repr__(self): def __repr__(self):
return "BoundField:(%s, %s)" %( self.field.name, self.form_fields) return "BoundField:(%s, %s)" % (self.field.name, self.form_fields)
# A guide to Field parameters: # A guide to Field parameters:
# #
@ -310,7 +308,6 @@ class Field(object):
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
"Returns a list of tuples used as SelectField choices for this field." "Returns a list of tuples used as SelectField choices for this field."
first_choice = include_blank and blank_choice or [] first_choice = include_blank and blank_choice or []
if self.choices: if self.choices:
return first_choice + list(self.choices) return first_choice + list(self.choices)
@ -333,10 +330,10 @@ class Field(object):
def flatten_data(self, follow, obj = None): def flatten_data(self, follow, obj = None):
""" """
Returns a dictionary mapping the field's manipulator field names to its Returns a dictionary mapping the field's manipulator field names to its
"flattened" string values for the admin view. Obj is the instance to extract the "flattened" string values for the admin view. obj is the instance to
values from. extract the values from.
""" """
return { self.attname : self._get_val_from_obj(obj)} return {self.attname: self._get_val_from_obj(obj)}
def get_follow(self, override=None): def get_follow(self, override=None):
if override != None: if override != None:
@ -869,14 +866,12 @@ class OneToOne(ManyToOne):
class BoundFieldLine(object): class BoundFieldLine(object):
def __init__(self, field_line, field_mapping, original, bound_field_class=BoundField): def __init__(self, field_line, field_mapping, original, bound_field_class=BoundField):
self.bound_fields = [field.bind(field_mapping, original, bound_field_class) self.bound_fields = [field.bind(field_mapping, original, bound_field_class) for field in field_line]
for field in field_line]
def __iter__(self): def __iter__(self):
for bound_field in self.bound_fields: for bound_field in self.bound_fields:
yield bound_field yield bound_field
def __len__(self): def __len__(self):
return len(self.bound_fields) return len(self.bound_fields)
@ -901,8 +896,7 @@ class BoundFieldSet(object):
def __init__(self, field_set, field_mapping, original, bound_field_line_class=BoundFieldLine): def __init__(self, field_set, field_mapping, original, bound_field_line_class=BoundFieldLine):
self.name = field_set.name self.name = field_set.name
self.classes = field_set.classes self.classes = field_set.classes
self.bound_field_lines = [ field_line.bind(field_mapping,original, bound_field_line_class) self.bound_field_lines = [field_line.bind(field_mapping,original, bound_field_line_class) for field_line in field_set]
for field_line in field_set]
def __iter__(self): def __iter__(self):
for bound_field_line in self.bound_field_lines: for bound_field_line in self.bound_field_lines:
@ -946,18 +940,15 @@ class Admin:
def get_field_sets(self, opts): def get_field_sets(self, opts):
if self.fields is None: if self.fields is None:
field_struct = ((None, { field_struct = ((None, {
'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)] 'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)]
}),) }),)
else: else:
field_struct = self.fields field_struct = self.fields
new_fieldset_list = [] new_fieldset_list = []
for fieldset in field_struct: for fieldset in field_struct:
name = fieldset[0] name = fieldset[0]
fs_options = fieldset[1] fs_options = fieldset[1]
classes = fs_options.get('classes', () ) classes = fs_options.get('classes', ())
line_specs = fs_options['fields'] line_specs = fs_options['fields']
new_fieldset_list.append(FieldSet(name, classes, opts.get_field, line_specs) ) new_fieldset_list.append(FieldSet(name, classes, opts.get_field, line_specs))
return new_fieldset_list return new_fieldset_list