1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

magic-removal:small amount of command stuff.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1769 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams
2005-12-23 01:31:37 +00:00
parent df36122320
commit 1e36a28d67
4 changed files with 53 additions and 57 deletions

View File

@@ -47,7 +47,7 @@ class ManipulatorHelper(object):
self.related_collection = related_collection
class FillHelper(ManipulatorHelper):
def matched_item(self,child_manip, obj_data):
def matched_item(self,index, child_manip, obj_data):
child_manip._fill_data(obj_data)
def missing_item(self, index, child_manip):
@@ -155,51 +155,58 @@ class AutomaticManipulator(Manipulator):
helper.new_item(obj_data)
def _fill_data(self, expanded_data):
self.original_object = self.get_new_object()
self.original_object = self.get_new_object(expanded_data)
# TODO: many_to_many
self._fill_related_objects(expanded_data,FillHelper)
def do_command(self, new_data, command):
expanded_data = dot_expand(new_data, MultiValueDict)
# Deal with the effects of previous commands
self.fill_data(expanded_data)
self._fill_data(expanded_data)
# Do this command
command_parts = command.split('.')
self._do_command_expanded(self, expanded_data, command_parts)
self._do_command_expanded(expanded_data, command_parts)
def _do_command_expanded(self, expanded_data, command_parts):
part = command_parts.pop(0, None)
if part == None:
try:
part = command_parts.pop(0)
except IndexError:
raise BadCommand, "Not enough parts in command"
# must be the name of a child manipulator collection
child_manips = None
related = None
for rel,manips in self.children:
for rel,manips in self.children.items():
if rel.var_name == part:
related = rel
child_manips = manips
break
if child_manips == None:
raise BadCommand, "%s : unknown manipulator collection name." % (part,)
raise BadCommand, "'%s' : unknown manipulator collection name." % (part,)
child_data = expanded_data.get(part, None)
if child_data == None:
raise BadCommand, "%s : could not find data for manipulator collection." % (part,)
raise BadCommand, "'%s' : could not find data for manipulator collection." % (part,)
# The next part could be an index of a manipulator,
# or it could be a command on the collection.
index_part = command_parts.pop(0)
try:
part = command_parts.pop(0)
except IndexError:
raise BadCommand, "Not enough parts in command"
try:
index = int(index_part)
manip = child_manips.get(index, None)
if manip == None:
raise BadCommand, "No %s manipulator found for index %s in command." % (part, index)
obj_data = child_data.get(index_part, None)
if obj_data == None:
raise BadCommand, "Could not find data for manipulator %s in %s collection." % (index, part)
if command_parts == ["delete"]:
child_manips[index] = None
else:
manip._do_command_expanded(expanded_data,command_parts)
manip._do_command_expanded(obj_data,command_parts)
except ValueError:
# Must be a command on the collection. Possible commands:
# add.

View File

@@ -87,32 +87,10 @@ class RelatedObject(object):
manipulators = []
for i,obj in enumerate(list):
prefix = '%s.%d.' % (self.var_name, i)
prefix = '%s%s.%d.' % (parent_manipulator.name_prefix, self.var_name, i)
manipulators.append(man_class(obj,follow, prefix) )
return manipulators
def get_manipulator_fields(self, opts, manipulator, follow):
# TODO: Remove core fields stuff.
change = manipulator.change
if manipulator.original_object:
meth_name = 'get_%s_count' % self.get_method_name_part()
count = getattr(manipulator.original_object, meth_name)()
count += self.field.rel.num_extra_on_change
if self.field.rel.min_num_in_admin:
count = max(count, self.field.rel.min_num_in_admin)
if self.field.rel.max_num_in_admin:
count = min(count, self.field.rel.max_num_in_admin)
else:
count = self.field.rel.num_in_admin
fields = []
for i in range(count):
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))
return fields
def bind(self, field_mapping, original, bound_related_object_class=BoundRelatedObject):
return bound_related_object_class(self, field_mapping, original)