Django

Code

Changeset 7137

Show
Ignore:
Timestamp:
02/19/08 20:00:20 (7 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Fixed a couple of FIXME items.

These are mostly code cleanups, although now we also install the right type of
class for our exception sublasses on models in Python 2.5.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/base.py

    r7136 r7137  
    3535 
    3636        # Create the class. 
    37         new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')}
     37        module = attrs.pop('__module__'
    3838        meta = attrs.pop('Meta', None) 
    39         # FIXME: Promote Meta to a newstyle class before attaching it to the 
    40         # model. 
    41         ## if meta: 
    42         ##     new_class.Meta = meta 
     39        new_class = type.__new__(cls, name, bases, {'__module__': module}) 
    4340        new_class.add_to_class('_meta', Options(meta)) 
    44         # FIXME: Need to be smarter here. Exception is an old-style class in 
    45         # Python <= 2.4, new-style in Python 2.5+. This construction is only 
    46         # really correct for old-style classes. 
    47         new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) 
    48         new_class.add_to_class('MultipleObjectsReturned', types.ClassType('MultipleObjectsReturned', (MultipleObjectsReturned, ), {})) 
     41        new_class.add_to_class('DoesNotExist', 
     42                subclass_exception('DoesNotExist', ObjectDoesNotExist, module)) 
     43        new_class.add_to_class('MultipleObjectsReturned', 
     44                subclass_exception('MultipleObjectsReturned', 
     45                    MultipleObjectsReturned, module)) 
    4946 
    5047        # Do the appropriate setup for any model parents. 
     
    489486def get_absolute_url(opts, func, self, *args, **kwargs): 
    490487    return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs) 
     488 
     489######## 
     490# MISC # 
     491######## 
     492 
     493if sys.version_info < (2, 5): 
     494    # Prior to Python 2.5, Exception was an old-style class 
     495    def subclass_exception(name, parent, unused): 
     496        return types.ClassType(name, (parent,), {}) 
     497 
     498else: 
     499    def subclass_exception(name, parent, module): 
     500        return type(name, (parent,), {'__module__': module}) 
     501 
  • django/branches/queryset-refactor/django/db/models/options.py

    r7126 r7137  
    11import re 
    22from bisect import bisect 
     3try: 
     4    set 
     5except NameError: 
     6    from sets import Set as set     # Python 2.3 fallback 
    37 
    48from django.conf import settings 
     
    408412        determining if something is an ancestor, regardless of lineage. 
    409413        """ 
    410         # FIXME: Fix model hashing and then use a Set here. 
    411         result = [] 
     414        result = set() 
    412415        for parent in self.parents: 
    413             result.append(parent) 
    414             result.extend(parent._meta.get_parent_list()) 
     416            result.add(parent) 
     417            result.update(parent._meta.get_parent_list()) 
    415418        return result 
    416419