1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

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

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1413 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-25 01:46:07 +00:00
parent 32ca04e59e
commit 88fb208912

View File

@ -149,18 +149,18 @@ class BadKeywordArguments(Exception):
pass pass
class BoundRelatedObject(object): class BoundRelatedObject(object):
def __init__(self,related_object, field_mapping, original): def __init__(self, related_object, field_mapping, original):
self.relation = related_object self.relation = related_object
self.field_mappings = field_mapping[related_object.opts.module_name] self.field_mappings = field_mapping[related_object.opts.module_name]
def template_name(self): def template_name(self):
raise NotImplementedException raise NotImplementedError
def __repr__(self): def __repr__(self):
return repr(self.__dict__) return repr(self.__dict__)
class RelatedObject(object): class RelatedObject(object):
def __init__(self,parent_opts, opts, field): def __init__(self, parent_opts, opts, field):
self.parent_opts = parent_opts self.parent_opts = parent_opts
self.opts = opts self.opts = opts
self.field = field self.field = field
@ -168,29 +168,30 @@ class RelatedObject(object):
self.name = opts.module_name self.name = opts.module_name
self.var_name = opts.object_name.lower() self.var_name = opts.object_name.lower()
def flatten_data(self,follow, obj = None): def flatten_data(self, follow, obj=None):
new_data = {} new_data = {}
rel_instances = self.get_list(obj) rel_instances = self.get_list(obj)
for i, rel_instance in enumerate(rel_instances): for i, rel_instance in enumerate(rel_instances):
instance_data = {} instance_data = {}
for f in self.opts.fields + self.opts.many_to_many: for f in self.opts.fields + self.opts.many_to_many:
#TODO fix for recursive manipulators. # TODO: Fix for recursive manipulators.
fol = follow.get(f.name, None ) fol = follow.get(f.name, None)
if fol: if fol:
field_data = f.flatten_data(fol,rel_instance) field_data = f.flatten_data(fol, rel_instance)
for name, value in field_data.items(): for name, value in field_data.items():
instance_data['%s.%d.%s' % (self.var_name, i, name)] = value instance_data['%s.%d.%s' % (self.var_name, i, name)] = value
new_data.update(instance_data) new_data.update(instance_data)
return new_data return new_data
def extract_data(self, data): def extract_data(self, data):
"Pull out the data meant for inline objects of this class, ie anything starting with our module name" """
Pull out the data meant for inline objects of this class,
i.e. anything starting with our module name.
"""
return data # TODO return data # TODO
def get_list(self, parent_instance = None): def get_list(self, parent_instance=None):
"Get the list of this type of object from an instance of the parent class" "Get the list of this type of object from an instance of the parent class."
if parent_instance != None: if parent_instance != None:
func_name = 'get_%s_list' % self.get_method_name_part() func_name = 'get_%s_list' % self.get_method_name_part()
func = getattr(parent_instance, func_name) func = getattr(parent_instance, func_name)
@ -214,9 +215,8 @@ class RelatedObject(object):
def editable_fields(self): def editable_fields(self):
"""Get the fields in this class that should be edited inline.""" "Get the fields in this class that should be edited inline."
return [f for f in self.opts.fields + self.opts.many_to_many if f.editable and f != self.field]
return [f for f in self.opts.fields + self.opts.many_to_many if f.editable and f != self.field ]
def get_follow(self, override=None): def get_follow(self, override=None):
if isinstance(override, bool): if isinstance(override, bool):
@ -239,7 +239,7 @@ class RelatedObject(object):
return "<RelatedObject: %s related to %s>" % ( self.name, self.field.name) return "<RelatedObject: %s related to %s>" % ( self.name, self.field.name)
def get_manipulator_fields(self, opts, manipulator, change, follow): def get_manipulator_fields(self, opts, manipulator, change, follow):
#TODO: remove core fields stuff # TODO: Remove core fields stuff.
if change: if change:
meth_name = 'get_%s_count' % self.get_method_name_part() meth_name = 'get_%s_count' % self.get_method_name_part()
count = getattr(manipulator.original_object, meth_name)() count = getattr(manipulator.original_object, meth_name)()
@ -254,11 +254,9 @@ class RelatedObject(object):
fields = [] fields = []
for i in range(count): for i in range(count):
for f in self.opts.fields + self.opts.many_to_many: for f in self.opts.fields + self.opts.many_to_many:
if follow.get(f.name, False): if follow.get(f.name, False):
prefix = '%s.%d.' % (self.var_name, i) prefix = '%s.%d.' % (self.var_name, i)
fields.extend( fields.extend(f.get_manipulator_fields(self.opts, manipulator, change, name_prefix=prefix, rel=True))
f.get_manipulator_fields(self.opts, manipulator, change, name_prefix=prefix, rel=True))
return fields return fields
def bind(self, field_mapping, original, bound_related_object_class=BoundRelatedObject): def bind(self, field_mapping, original, bound_related_object_class=BoundRelatedObject):
@ -435,12 +433,12 @@ class Options:
def get_followed_related_objects(self, follow=None): def get_followed_related_objects(self, follow=None):
if follow == None: if follow == None:
follow = self.get_follow() follow = self.get_follow()
return [f for f in self.get_all_related_objects() if follow.get(f.name, None) ] return [f for f in self.get_all_related_objects() if follow.get(f.name, None)]
def get_data_holders(self, follow=None): def get_data_holders(self, follow=None):
if follow == None : if follow == None:
follow = self.get_follow() follow = self.get_follow()
return [f for f in self.fields + self.many_to_many + self.get_all_related_objects() if follow.get(f.name, None) ] return [f for f in self.fields + self.many_to_many + self.get_all_related_objects() if follow.get(f.name, None)]
def get_follow(self, override=None): def get_follow(self, override=None):
follow = {} follow = {}
@ -480,12 +478,12 @@ class Options:
self._ordered_objects = objects self._ordered_objects = objects
return self._ordered_objects return self._ordered_objects
def has_field_type(self, field_type, follow = None): def has_field_type(self, field_type, follow=None):
""" """
Returns True if this object's admin form has at least one of the given Returns True if this object's admin form has at least one of the given
field_type (e.g. FileField). field_type (e.g. FileField).
""" """
#TODO: follow # TODO: follow
if not hasattr(self, '_field_types'): if not hasattr(self, '_field_types'):
self._field_types = {} self._field_types = {}
if not self._field_types.has_key(field_type): if not self._field_types.has_key(field_type):
@ -857,11 +855,9 @@ class ModelBase(type):
old_app._MODELS[i] = new_class old_app._MODELS[i] = new_class
# Replace all relationships to the old class with # Replace all relationships to the old class with
# relationships to the new one. # relationships to the new one.
for related in model._meta.get_all_related_objects() + \ for related in model._meta.get_all_related_objects() + model._meta.get_all_related_many_to_many_objects():
model._meta.get_all_related_many_to_many_objects():
related.field.rel.to = opts related.field.rel.to = opts
break break
return new_class return new_class
class Model: class Model: