Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 1e36a28d6765d7ddaee0c879ba0b68bc01f64d58 1 parent df36122
Robert Wittams authored December 23, 2005
8  django/contrib/admin/templates/admin/edit_inline_tabular.html
@@ -7,6 +7,8 @@
7 7
          <th{{ fw.header_class_attribute }}>{{ fw.field.verbose_name|capfirst }}</th>
8 8
       {% endif %}
9 9
    {% endfor %}
  10
+   <td><td>
  11
+   </tr></thead>
10 12
    {% for fcw in bound_related_object.form_field_collection_wrappers %}
11 13
       {% if change %}{% if original_row_needed %}
12 14
          {% if fcw.obj.original %}
@@ -29,10 +31,14 @@
29 31
       {% if bound_related_object.show_url %}<td>
30 32
          {% if fcw.obj.original %}<a href="/r/{{ fcw.obj.original.content_type_id }}/{{ fcw.obj.original.id }}/">View on site</a>{% endif %}
31 33
       </td>{% endif %}
  34
+      <td>
  35
+      	<button class="deletebutton" name="command" value="{{fcw.deletecommand}}">Delete</button>
  36
+      </td>
32 37
       </tr>
33 38
 
34 39
    {% endfor %} </table>
35  
-
  40
+    <button class="addbutton" name="command" value="{{bound_related_object.addcommand}}">Add</button>
  41
+    
36 42
    {% for fcw in bound_related_object.form_field_collection_wrappers %}
37 43
       {% for bound_field in fcw.bound_fields %}
38 44
          {% if bound_field.hidden %}
47  django/contrib/admin/views/stages/change.py
@@ -36,9 +36,9 @@ def change_stage(request, path, object_id):
36 36
         raise PermissionDenied
37 37
     if request.POST and request.POST.has_key("_saveasnew"):
38 38
         return add_stage(request, path, form_url='../../add/')
  39
+    
39 40
     try:
40  
-        manipulator_class = model.ChangeManipulator
41  
-        manipulator = manipulator_class(object_id)
  41
+        manipulator = model.ChangeManipulator(object_id)
42 42
     except ObjectDoesNotExist:
43 43
         raise Http404
44 44
 
@@ -50,26 +50,31 @@ def change_stage(request, path, object_id):
50 50
         errors = manipulator.get_validation_errors(new_data)
51 51
 
52 52
         manipulator.do_html2python(new_data)
53  
-        if not errors and not request.POST.has_key("_preview"):
54  
-            new_object = manipulator.save(new_data)
55  
-            log_change_message(request.user, opts, manipulator, new_object)
56  
-            msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
57  
-            pk_value = getattr(new_object, opts.pk.attname)
58  
-            if request.POST.has_key("_continue"):
59  
-                request.user.add_message(msg + ' ' + _("You may edit it again below."))
60  
-                if request.REQUEST.has_key('_popup'):
61  
-                    return HttpResponseRedirect(request.path + "?_popup=1")
  53
+        if not errors:
  54
+            if request.POST.has_key("command"):
  55
+                command_name = request.POST.get("command")
  56
+                manipulator.do_command(new_data, command_name)
  57
+                new_data = manipulator.flatten_data()
  58
+            elif not request.POST.has_key("_preview"):
  59
+                new_object = manipulator.save(new_data)
  60
+                log_change_message(request.user, opts, manipulator, new_object)
  61
+                msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
  62
+                pk_value = getattr(new_object, opts.pk.attname)
  63
+                if request.POST.has_key("_continue"):
  64
+                    request.user.add_message(msg + ' ' + _("You may edit it again below."))
  65
+                    if request.REQUEST.has_key('_popup'):
  66
+                        return HttpResponseRedirect(request.path + "?_popup=1")
  67
+                    else:
  68
+                        return HttpResponseRedirect(request.path)
  69
+                elif request.POST.has_key("_saveasnew"):
  70
+                    request.user.add_message(_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object})
  71
+                    return HttpResponseRedirect("../../%s/" % pk_value)
  72
+                elif request.POST.has_key("_addanother"):
  73
+                    request.user.add_message(msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
  74
+                    return HttpResponseRedirect("../../add/")
62 75
                 else:
63  
-                    return HttpResponseRedirect(request.path)
64  
-            elif request.POST.has_key("_saveasnew"):
65  
-                request.user.add_message(_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object})
66  
-                return HttpResponseRedirect("../../%s/" % pk_value)
67  
-            elif request.POST.has_key("_addanother"):
68  
-                request.user.add_message(msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
69  
-                return HttpResponseRedirect("../../add/")
70  
-            else:
71  
-                request.user.add_message(msg)
72  
-                return HttpResponseRedirect("../../")
  76
+                    request.user.add_message(msg)
  77
+                    return HttpResponseRedirect("../../")
73 78
     else:
74 79
         # Populate new_data with a "flattened" version of the current data.
75 80
         new_data = manipulator.flatten_data()
31  django/db/models/manipulators.py
@@ -47,7 +47,7 @@ def __init__(self, manip, related_collection):
47 47
         self.related_collection = related_collection
48 48
 
49 49
 class FillHelper(ManipulatorHelper):
50  
-    def matched_item(self,child_manip, obj_data):
  50
+    def matched_item(self,index, child_manip, obj_data):
51 51
         child_manip._fill_data(obj_data)
52 52
         
53 53
     def missing_item(self, index, child_manip):
@@ -155,51 +155,58 @@ def _fill_related_objects(self, expanded_data, helper_factory):
155 155
                         helper.new_item(obj_data)
156 156
                         
157 157
     def _fill_data(self, expanded_data):
158  
-        self.original_object = self.get_new_object()
  158
+        self.original_object = self.get_new_object(expanded_data)
159 159
         # TODO: many_to_many
160 160
         self._fill_related_objects(expanded_data,FillHelper)
161 161
         
162 162
     def do_command(self, new_data, command):
163 163
         expanded_data = dot_expand(new_data, MultiValueDict)
164 164
         # Deal with the effects of previous commands
165  
-        self.fill_data(expanded_data)
  165
+        self._fill_data(expanded_data)
166 166
         # Do this command
167 167
         command_parts = command.split('.')
168  
-        self._do_command_expanded(self, expanded_data, command_parts)
  168
+        self._do_command_expanded(expanded_data, command_parts)
169 169
     
170 170
     def _do_command_expanded(self, expanded_data, command_parts):
171  
-        part = command_parts.pop(0, None)
172  
-        if part == None:
  171
+        try: 
  172
+            part = command_parts.pop(0)
  173
+        except IndexError:
173 174
             raise BadCommand, "Not enough parts in command"
174 175
     
175 176
         # must be the name of a child manipulator collection
176 177
         child_manips = None
177 178
         related = None
178  
-        for rel,manips in self.children: 
  179
+        for rel,manips in self.children.items(): 
179 180
             if rel.var_name == part:
180 181
                 related = rel
181 182
                 child_manips = manips
182 183
                 break
183 184
         if child_manips == None: 
184  
-            raise BadCommand, "%s : unknown manipulator collection name." % (part,)
  185
+            raise BadCommand, "'%s' : unknown manipulator collection name." % (part,)
185 186
         
186 187
         child_data = expanded_data.get(part, None)
187 188
         if child_data == None: 
188  
-            raise BadCommand, "%s : could not find data for manipulator collection." % (part,)                
  189
+            raise BadCommand, "'%s' : could not find data for manipulator collection." % (part,)                
189 190
             
190 191
             # The next part could be an index of a manipulator,
191 192
             # or it could be a command on the collection.
192  
-            index_part = command_parts.pop(0)
  193
+            try: 
  194
+                part = command_parts.pop(0)
  195
+            except IndexError:
  196
+                raise BadCommand, "Not enough parts in command"
193 197
             try:
194 198
                 index = int(index_part)
195 199
                 manip = child_manips.get(index, None)
  200
+                
196 201
                 if manip == None:
197 202
                     raise BadCommand, "No %s manipulator found for index %s in command." % (part, index)
198  
-                
  203
+                obj_data = child_data.get(index_part, None)
  204
+                if obj_data == None:
  205
+                    raise BadCommand, "Could not find data for manipulator %s in %s collection." % (index, part)
199 206
                 if command_parts == ["delete"]:
200 207
                     child_manips[index] = None
201 208
                 else:
202  
-                    manip._do_command_expanded(expanded_data,command_parts)
  209
+                    manip._do_command_expanded(obj_data,command_parts)
203 210
             except ValueError:
204 211
             # Must be a command on the collection. Possible commands: 
205 212
             # add. 
24  django/db/models/related.py
@@ -87,32 +87,10 @@ def get_manipulators(self,parent_manipulator, follow):

0 notes on commit 1e36a28

Please sign in to comment.
Something went wrong with that request. Please try again.