Django

Code

Changeset 2032

Show
Ignore:
Timestamp:
01/17/06 11:23:18 (3 years ago)
Author:
adrian
Message:

magic-removal: Tiny code cleanups in db.models modules, and removed ManyToManyFieldNew? (which was never finished)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/fields/__init__.py

    r2028 r2032  
    388388        return value 
    389389 
    390     def contribute_to_class(self,cls, name ): 
     390    def contribute_to_class(self, cls, name): 
    391391        super(DateField,self).contribute_to_class(cls, name) 
    392392        if not self.null: 
     
    712712 
    713713    def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True): 
    714         return [forms.HiddenField(name_prefix + self.name) 
     714        return [forms.HiddenField(name_prefix + self.name)
    715715 
    716716class BoundFieldLine(object): 
     
    762762 
    763763    def __repr__(self): 
    764          return "FieldSet:(%s,%s)" % (self.name, self.field_lines) 
     764         return "FieldSet: (%s, %s)" % (self.name, self.field_lines) 
    765765 
    766766    def bind(self, field_mapping, original, bound_field_set_class=BoundFieldSet): 
  • django/branches/magic-removal/django/db/models/fields/related.py

    r1956 r2032  
    2424    other_cls = sender 
    2525    key = (other_cls.__module__, other_cls.__name__) 
    26     for rel_cls, field in pending_lookups.setdefault(key,[]): 
     26    for rel_cls, field in pending_lookups.setdefault(key, []): 
    2727        field.rel.to = other_cls 
    2828        field.do_related_class(other_cls, rel_cls) 
     
    101101        Field.__init__(self, **kwargs) 
    102102 
     103        self.db_index = True 
     104 
    103105        for name in ('num_in_admin', 'min_num_in_admin', 'max_num_in_admin', 'num_extra_on_change'): 
    104106            if name in kwargs: 
    105107                self.deprecated_args.append(name) 
    106108 
    107         if not self.db_index: 
    108             self.db_index = True 
    109  
    110109    def prepare_field_objs_and_params(self, manipulator, name_prefix): 
    111         params = {'validator_list': self.validator_list[:]} 
    112  
    113         params['member_name'] = name_prefix + self.attname 
     110        params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname} 
    114111        if self.rel.raw_id_admin: 
    115112            field_objs = self.get_manipulator_field_objs() 
     
    125122                    field_objs = [forms.SelectField] 
    126123            params['choices'] = self.get_choices_default() 
    127         return (field_objs, params) 
     124        return field_objs, params 
    128125 
    129126    def get_manipulator_field_objs(self): 
     
    193190        IntegerField.__init__(self, **kwargs) 
    194191 
     192        self.db_index = True 
     193 
    195194        for name in ('num_in_admin'): 
    196195            if name in kwargs: 
    197196                self.deprecated_args.append(name) 
    198  
    199         if not self.db_index: 
    200            self.db_index = True 
    201197 
    202198    def contribute_to_related_class(self, cls, related): 
     
    225221                self.deprecated_args.append(name) 
    226222 
    227  
    228223        if self.rel.raw_id_admin: 
    229             msg = gettext_lazy(' Separate multiple IDs with commas.') 
    230         else: 
    231             msg = gettext_lazy(' Hold down "Control", or "Command" on a Mac, to select more than one.') 
    232         self.help_text = string_concat( self.help_text , msg ) 
    233  
     224            msg = gettext_lazy('Separate multiple IDs with commas.') 
     225        else: 
     226            msg = gettext_lazy('Hold down "Control", or "Command" on a Mac, to select more than one.') 
     227        self.help_text = string_concat(self.help_text, msg) 
    234228 
    235229    def get_manipulator_field_objs(self): 
     
    294288    def contribute_to_related_class(self, cls, related): 
    295289        rel_obj_name = related.get_method_name_part() 
    296         setattr(cls, 'get_%s' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_object', rel_class=related.model , rel_field=related.field)) 
     290        setattr(cls, 'get_%s' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_object', rel_class=related.model, rel_field=related.field)) 
    297291        setattr(cls, 'get_%s_count' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_count', rel_class=related.model, rel_field=related.field)) 
    298292        setattr(cls, 'get_%s_list' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_list', rel_class=related.model, rel_field=related.field)) 
     
    307301        pass 
    308302 
    309 class ManyToManyFieldNew(RelatedField): 
    310     def __init__(self, to, **kwargs): 
    311         self.to = to 
    312         self.from_ = None 
    313         self.rel = self 
    314         self.edit_inline = False 
    315  
    316     def set_attributes_from_rel(self): 
    317         pass 
    318  
    319     def contribute_to_class(self, cls, name): 
    320         self.from_ = cls 
    321         self.name = name 
    322         super(ManyToManyFieldNew, self).contribute_to_class(cls, name) 
    323  
    324  
    325     def contribute_to_related_class(self, cls, name): 
    326         #Now we know both classes exist. 
    327         self.to = cls 
    328         # We need to wait until the class we were in was fully defined 
    329         dispatcher.connect(self.from_prepared, signal=signals.class_prepared, sender=self.from_) 
    330  
    331     def from_prepared(self): 
    332         from django.db.models.base import Model 
    333  
    334         class M2M(Model): 
    335             __module__ = self.from_.__module__ 
    336  
    337         id_to =  self.from_._meta.db_table 
    338         id_from =  self.to._meta.db_table 
    339  
    340         M2M.add_to_class(id_from, ForeignKey(to=self.from_)) 
    341         M2M.add_to_class(id_to, ForeignKey(to=self.to)) 
    342         M2M._meta.db_table = '%s_%s' % (self.from_._meta.db_table, self.name) 
    343         M2M._meta.unique_together = ((id_to, id_from),) 
    344         M2M.__name__ = "M2M_%s_%s_%s" % (self.name, self.from_.__name__, self.to.__name__) 
    345  
    346303class ManyToOne: 
    347304    def __init__(self, to, field_name, edit_inline=False, 
     
    350307            to._meta 
    351308        except AttributeError: 
    352             assert isinstance(to, basestring) , "'to' must be either a model, a model name or the string %r" % RECURSIVE_RELATIONSHIP_CONSTANT 
     309            assert isinstance(to, basestring), "'to' must be either a model, a model name or the string %r" % RECURSIVE_RELATIONSHIP_CONSTANT 
    353310        self.to, self.field_name = to, field_name 
    354311        self.edit_inline = edit_inline 
  • django/branches/magic-removal/django/db/models/__init__.py

    r2017 r2032  
    2727    if hasattr(mod, '__all__'): 
    2828        for name in mod.__all__: 
    29             sub_mod = __import__("%s.%s" % (mod.__name__, name), '','',['']) 
     29            sub_mod = __import__("%s.%s" % (mod.__name__, name), '', '', ['']) 
    3030            get_models_helper(sub_mod, seen_models) 
    3131 
     
    3434        comps = app_name.split('.') 
    3535        if app_label == comps[-1]: 
    36             app_models = __import__('%s.models' % app_name , '','',['']) 
     36            app_models = __import__('%s.models' % app_name, '', '', ['']) 
    3737            return app_models 
    3838    raise ImproperlyConfigured, "App with label %s could not be found" % app_label 
  • django/branches/magic-removal/django/db/models/manipulators.py

    r1956 r2032  
    244244# 
    245245#        # Save inline edited objects 
    246 #        self._fill_related_objects(expanded_data,SaveHelper) 
     246#        self._fill_related_objects(expanded_data, SaveHelper) 
    247247# 
    248248#        return new_object 
     
    437437 
    438438        prefix = '%s%s.' % (self.name_prefix, index ) 
    439         child_manip = man_class(self.follow, self.name_parts + ( str(index), ) 
     439        child_manip = man_class(self.follow, self.name_parts + (str(index),)
    440440 
    441441        self[index] = child_manip