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:
parent
df36122320
commit
1e36a28d67
|
@ -7,6 +7,8 @@
|
|||
<th{{ fw.header_class_attribute }}>{{ fw.field.verbose_name|capfirst }}</th>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<td><td>
|
||||
</tr></thead>
|
||||
{% for fcw in bound_related_object.form_field_collection_wrappers %}
|
||||
{% if change %}{% if original_row_needed %}
|
||||
{% if fcw.obj.original %}
|
||||
|
@ -29,9 +31,13 @@
|
|||
{% if bound_related_object.show_url %}<td>
|
||||
{% if fcw.obj.original %}<a href="/r/{{ fcw.obj.original.content_type_id }}/{{ fcw.obj.original.id }}/">View on site</a>{% endif %}
|
||||
</td>{% endif %}
|
||||
<td>
|
||||
<button class="deletebutton" name="command" value="{{fcw.deletecommand}}">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %} </table>
|
||||
<button class="addbutton" name="command" value="{{bound_related_object.addcommand}}">Add</button>
|
||||
|
||||
{% for fcw in bound_related_object.form_field_collection_wrappers %}
|
||||
{% for bound_field in fcw.bound_fields %}
|
||||
|
|
|
@ -36,9 +36,9 @@ def change_stage(request, path, object_id):
|
|||
raise PermissionDenied
|
||||
if request.POST and request.POST.has_key("_saveasnew"):
|
||||
return add_stage(request, path, form_url='../../add/')
|
||||
|
||||
try:
|
||||
manipulator_class = model.ChangeManipulator
|
||||
manipulator = manipulator_class(object_id)
|
||||
manipulator = model.ChangeManipulator(object_id)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
|
||||
|
@ -50,7 +50,12 @@ def change_stage(request, path, object_id):
|
|||
errors = manipulator.get_validation_errors(new_data)
|
||||
|
||||
manipulator.do_html2python(new_data)
|
||||
if not errors and not request.POST.has_key("_preview"):
|
||||
if not errors:
|
||||
if request.POST.has_key("command"):
|
||||
command_name = request.POST.get("command")
|
||||
manipulator.do_command(new_data, command_name)
|
||||
new_data = manipulator.flatten_data()
|
||||
elif not request.POST.has_key("_preview"):
|
||||
new_object = manipulator.save(new_data)
|
||||
log_change_message(request.user, opts, manipulator, new_object)
|
||||
msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue