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
class BoundRelatedObject(object):
def __init__(self,related_object, field_mapping, original):
def __init__(self, related_object, field_mapping, original):
self.relation = related_object
self.field_mappings = field_mapping[related_object.opts.module_name]
def template_name(self):
raise NotImplementedException
raise NotImplementedError
def __repr__(self):
return repr(self.__dict__)
class RelatedObject(object):
def __init__(self,parent_opts, opts, field):
def __init__(self, parent_opts, opts, field):
self.parent_opts = parent_opts
self.opts = opts
self.field = field
@ -168,29 +168,30 @@ class RelatedObject(object):
self.name = opts.module_name
self.var_name = opts.object_name.lower()
def flatten_data(self,follow, obj = None):
def flatten_data(self, follow, obj=None):
new_data = {}
rel_instances = self.get_list(obj)
for i, rel_instance in enumerate(rel_instances):
instance_data = {}
for f in self.opts.fields + self.opts.many_to_many:
#TODO fix for recursive manipulators.
fol = follow.get(f.name, None )
# TODO: Fix for recursive manipulators.
fol = follow.get(f.name, None)
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():
instance_data['%s.%d.%s' % (self.var_name, i, name)] = value
new_data.update(instance_data)
return new_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
def get_list(self, parent_instance = None):
"Get the list of this type of object from an instance of the parent class"
def get_list(self, parent_instance=None):
"Get the list of this type of object from an instance of the parent class."
if parent_instance != None:
func_name = 'get_%s_list' % self.get_method_name_part()
func = getattr(parent_instance, func_name)
@ -214,9 +215,8 @@ class RelatedObject(object):
def editable_fields(self):
"""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 ]
"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]
def get_follow(self, override=None):
if isinstance(override, bool):
@ -239,7 +239,7 @@ class RelatedObject(object):
return "<RelatedObject: %s related to %s>" % ( self.name, self.field.name)
def get_manipulator_fields(self, opts, manipulator, change, follow):
#TODO: remove core fields stuff
# TODO: Remove core fields stuff.
if change:
meth_name = 'get_%s_count' % self.get_method_name_part()
count = getattr(manipulator.original_object, meth_name)()
@ -256,9 +256,7 @@ class RelatedObject(object):
for f in self.opts.fields + self.opts.many_to_many:
if follow.get(f.name, False):
prefix = '%s.%d.' % (self.var_name, i)
fields.extend(
f.get_manipulator_fields(self.opts, manipulator, change, name_prefix=prefix, rel=True))
fields.extend(f.get_manipulator_fields(self.opts, manipulator, change, name_prefix=prefix, rel=True))
return fields
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):
if follow == None:
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):
if follow == None :
if follow == None:
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):
follow = {}
@ -480,12 +478,12 @@ class Options:
self._ordered_objects = 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
field_type (e.g. FileField).
"""
#TODO: follow
# TODO: follow
if not hasattr(self, '_field_types'):
self._field_types = {}
if not self._field_types.has_key(field_type):
@ -857,11 +855,9 @@ class ModelBase(type):
old_app._MODELS[i] = new_class
# Replace all relationships to the old class with
# relationships to the new one.
for related in model._meta.get_all_related_objects() + \
model._meta.get_all_related_many_to_many_objects():
for related in model._meta.get_all_related_objects() + model._meta.get_all_related_many_to_many_objects():
related.field.rel.to = opts
break
return new_class
class Model: