1
0
mirror of https://github.com/django/django.git synced 2025-07-06 10:49:17 +00:00

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.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7137 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-02-20 02:00:20 +00:00
parent 3dd28bd566
commit ca123b0760
2 changed files with 28 additions and 14 deletions

View File

@ -34,18 +34,15 @@ class ModelBase(type):
return super(ModelBase, cls).__new__(cls, name, bases, attrs) return super(ModelBase, cls).__new__(cls, name, bases, attrs)
# Create the class. # Create the class.
new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')}) module = attrs.pop('__module__')
meta = attrs.pop('Meta', None) meta = attrs.pop('Meta', None)
# FIXME: Promote Meta to a newstyle class before attaching it to the new_class = type.__new__(cls, name, bases, {'__module__': module})
# model.
## if meta:
## new_class.Meta = meta
new_class.add_to_class('_meta', Options(meta)) new_class.add_to_class('_meta', Options(meta))
# FIXME: Need to be smarter here. Exception is an old-style class in new_class.add_to_class('DoesNotExist',
# Python <= 2.4, new-style in Python 2.5+. This construction is only subclass_exception('DoesNotExist', ObjectDoesNotExist, module))
# really correct for old-style classes. new_class.add_to_class('MultipleObjectsReturned',
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) subclass_exception('MultipleObjectsReturned',
new_class.add_to_class('MultipleObjectsReturned', types.ClassType('MultipleObjectsReturned', (MultipleObjectsReturned, ), {})) MultipleObjectsReturned, module))
# Do the appropriate setup for any model parents. # Do the appropriate setup for any model parents.
abstract_parents = [] abstract_parents = []
@ -488,3 +485,17 @@ def method_get_order(ordered_obj, self):
def get_absolute_url(opts, func, self, *args, **kwargs): def get_absolute_url(opts, func, self, *args, **kwargs):
return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs) return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs)
########
# MISC #
########
if sys.version_info < (2, 5):
# Prior to Python 2.5, Exception was an old-style class
def subclass_exception(name, parent, unused):
return types.ClassType(name, (parent,), {})
else:
def subclass_exception(name, parent, module):
return type(name, (parent,), {'__module__': module})

View File

@ -1,5 +1,9 @@
import re import re
from bisect import bisect from bisect import bisect
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from django.conf import settings from django.conf import settings
from django.db.models.related import RelatedObject from django.db.models.related import RelatedObject
@ -407,11 +411,10 @@ class Options(object):
Returns a list of all the ancestor of this model as a list. Useful for Returns a list of all the ancestor of this model as a list. Useful for
determining if something is an ancestor, regardless of lineage. determining if something is an ancestor, regardless of lineage.
""" """
# FIXME: Fix model hashing and then use a Set here. result = set()
result = []
for parent in self.parents: for parent in self.parents:
result.append(parent) result.add(parent)
result.extend(parent._meta.get_parent_list()) result.update(parent._meta.get_parent_list())
return result return result
def get_ordered_objects(self): def get_ordered_objects(self):