Django

Code

Changeset 1414

Show
Ignore:
Timestamp:
11/24/05 19:51:19 (3 years ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/core/meta/fields.py

    r1361 r1414  
    5858    if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname): 
    5959        return 
    60     raise validators.ValidationError, _("%(optname)s with this %(fieldname)s already exists.") % {'optname':capfirst(opts.verbose_name), 'fieldname':f.verbose_name} 
    61  
     60    raise validators.ValidationError, _("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name} 
    6261 
    6362class BoundField(object): 
     
    7574    def original_value(self): 
    7675        if self.original: 
    77             return self.original.__dict__[self.field.column]  
     76            return self.original.__dict__[self.field.column] 
    7877 
    7978    def __repr__(self): 
    80         return "BoundField:(%s, %s)" %( self.field.name, self.form_fields) 
    81  
     79        return "BoundField:(%s, %s)" % (self.field.name, self.form_fields) 
    8280 
    8381# A guide to Field parameters: 
     
    9795 
    9896class Field(object): 
    99      
     97 
    10098    # Designates whether empty strings fundamentally are allowed at the 
    10199    # database level. 
     
    248246            else: 
    249247                field_objs = [formfields.SelectField] 
    250               
     248 
    251249            params['choices'] = self.get_choices_default() 
    252250        else: 
     
    311309    def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): 
    312310        "Returns a list of tuples used as SelectField choices for this field." 
    313         
    314311        first_choice = include_blank and blank_choice or [] 
    315312        if self.choices: 
    316313            return first_choice + list(self.choices) 
    317314        rel_obj = self.rel.to 
    318         return first_choice + [(getattr(x, rel_obj.pk.attname), str(x))  
     315        return first_choice + [(getattr(x, rel_obj.pk.attname), str(x)) 
    319316                               for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)] 
    320317 
     
    327324    def _get_val_from_obj(self, obj): 
    328325        if obj: 
    329            return getattr(obj, self.attname)  
    330         else:  
     326           return getattr(obj, self.attname) 
     327        else: 
    331328           return self.get_default() 
    332329 
     
    334331        """ 
    335332        Returns a dictionary mapping the field's manipulator field names to its 
    336         "flattened" string values for the admin view. Obj is the instance to extract the  
    337         values from. 
     333        "flattened" string values for the admin view. obj is the instance to 
     334        extract the values from. 
    338335        """ 
    339         return { self.attname : self._get_val_from_obj(obj)} 
     336        return {self.attname: self._get_val_from_obj(obj)} 
    340337 
    341338    def get_follow(self, override=None): 
     
    344341        else: 
    345342            return self.editable 
    346          
     343 
    347344    def bind(self, fieldmapping, original, bound_field_class=BoundField): 
    348345        return bound_field_class(self, fieldmapping, original) 
    349   
     346 
    350347class AutoField(Field): 
    351348    empty_strings_allowed = False 
     
    387384    def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): 
    388385        self.auto_now, self.auto_now_add = auto_now, auto_now_add 
    389         #HACKs : auto_now_add/auto_now should be done as a default or a pre_save...  
     386        #HACKs : auto_now_add/auto_now should be done as a default or a pre_save... 
    390387        if auto_now or auto_now_add: 
    391388            kwargs['editable'] = False 
     
    455452 
    456453    def flatten_data(self,follow, obj = None): 
    457         val = self._get_val_from_obj(obj)  
     454        val = self._get_val_from_obj(obj) 
    458455        date_field, time_field = self.get_manipulator_field_names('') 
    459456        return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''), 
     
    659656 
    660657    def flatten_data(self,follow, obj = None): 
    661         val = self._get_val_from_obj(obj)  
    662         return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')}  
     658        val = self._get_val_from_obj(obj) 
     659        return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')} 
    663660 
    664661class URLField(Field): 
     
    785782 
    786783    def flatten_data(self, follow, obj = None): 
    787         new_data = {}  
     784        new_data = {} 
    788785        if obj: 
    789786            get_list_func = getattr(obj, 'get_%s_list' % self.rel.singular) 
     
    792789                 new_data[self.name] = ",".join([str(id) for id in instance_ids]) 
    793790            else: 
    794                  new_data[self.name] = instance_ids  
     791                 new_data[self.name] = instance_ids 
    795792        else: 
    796793            # In required many-to-many fields with only one available choice, 
     
    870867class BoundFieldLine(object): 
    871868    def __init__(self, field_line, field_mapping, original, bound_field_class=BoundField): 
    872         self.bound_fields = [field.bind(field_mapping, original, bound_field_class)  
    873                              for field in field_line] 
    874      
     869        self.bound_fields = [field.bind(field_mapping, original, bound_field_class) for field in field_line] 
     870 
    875871    def __iter__(self): 
    876872        for bound_field in self.bound_fields: 
    877873            yield bound_field 
    878      
    879874 
    880875    def __len__(self): 
    881876        return len(self.bound_fields) 
    882      
     877 
    883878class FieldLine(object): 
    884879    def __init__(self, field_locator_func, linespec): 
     
    894889        for field in self.fields: 
    895890            yield field 
    896      
     891 
    897892    def __len__(self): 
    898893        return len(self.fields) 
    899      
     894 
    900895class BoundFieldSet(object): 
    901896    def __init__(self, field_set, field_mapping, original, bound_field_line_class=BoundFieldLine): 
    902897        self.name = field_set.name 
    903898        self.classes = field_set.classes 
    904         self.bound_field_lines = [ field_line.bind(field_mapping,original, bound_field_line_class)  
    905                                    for field_line in field_set] 
    906                                     
     899        self.bound_field_lines = [field_line.bind(field_mapping,original, bound_field_line_class) for field_line in field_set] 
     900 
    907901    def __iter__(self): 
    908902        for bound_field_line in self.bound_field_lines: 
    909903            yield bound_field_line 
    910     
     904 
    911905    def __len__(self): 
    912906        return len(self.bound_field_lines) 
    913     
     907 
    914908class FieldSet(object): 
    915909    def __init__(self, name, classes, field_locator_func, line_specs): 
     
    917911        self.field_lines = [FieldLine(field_locator_func, line_spec) for line_spec in line_specs] 
    918912        self.classes = classes 
    919          
     913 
    920914    def __repr__(self): 
    921915         return "FieldSet:(%s,%s)" % (self.name, self.field_lines) 
     
    943937        self.save_on_top = save_on_top 
    944938        self.list_select_related = list_select_related 
    945      
     939 
    946940    def get_field_sets(self, opts): 
    947941        if self.fields is None: 
    948942            field_struct = ((None, { 
    949                     'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)] 
    950                     }),) 
     943                'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)] 
     944                }),) 
    951945        else: 
    952946            field_struct = self.fields 
    953              
    954947        new_fieldset_list = [] 
    955948        for fieldset in field_struct: 
    956949            name = fieldset[0] 
    957950            fs_options = fieldset[1] 
    958             classes = fs_options.get('classes', ()
     951            classes = fs_options.get('classes', ()
    959952            line_specs = fs_options['fields'] 
    960             new_fieldset_list.append(FieldSet(name, classes, opts.get_field, line_specs)
     953            new_fieldset_list.append(FieldSet(name, classes, opts.get_field, line_specs)
    961954        return new_fieldset_list 
    962      
    963