Ticket #9094: create_update.patch
File create_update.patch, 5.1 KB (added by , 16 years ago) |
---|
-
django/views/generic/create_update.py
91 91 % (model._meta.verbose_name, lookup_kwargs)) 92 92 93 93 def create_object(request, model=None, template_name=None, 94 template_loader=loader, extra_context=None, post_save_ redirect=None,94 template_loader=loader, extra_context=None, post_save_action=None, post_save_redirect=None, 95 95 login_required=False, context_processors=None, form_class=None): 96 96 """ 97 97 Generic object-creation function. … … 112 112 new_object = form.save() 113 113 if request.user.is_authenticated(): 114 114 request.user.message_set.create(message=ugettext("The %(verbose_name)s was created successfully.") % {"verbose_name": model._meta.verbose_name}) 115 if post_save_action: 116 post_save_action(new_object.pk) 115 117 return redirect(post_save_redirect, new_object) 116 118 else: 117 119 form = form_class() … … 128 130 129 131 def update_object(request, model=None, object_id=None, slug=None, 130 132 slug_field='slug', template_name=None, template_loader=loader, 131 extra_context=None, post_save_ redirect=None, login_required=False,133 extra_context=None, post_save_action=None, post_save_redirect=None, login_required=False, 132 134 context_processors=None, template_object_name='object', 133 135 form_class=None): 134 136 """ … … 154 156 obj = form.save() 155 157 if request.user.is_authenticated(): 156 158 request.user.message_set.create(message=ugettext("The %(verbose_name)s was updated successfully.") % {"verbose_name": model._meta.verbose_name}) 159 if post_save_action: 160 post_save_action(object_id, slug, slug_field) 157 161 return redirect(post_save_redirect, obj) 158 162 else: 159 163 form = form_class(instance=obj) … … 170 174 populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.attname)) 171 175 return response 172 176 173 def delete_object(request, model, post_delete_redirect, object_id=None,177 def delete_object(request, model, post_delete_redirect, post_delete_action=None, object_id=None, 174 178 slug=None, slug_field='slug', template_name=None, 175 179 template_loader=loader, extra_context=None, login_required=False, 176 180 context_processors=None, template_object_name='object'): … … 178 182 Generic object-delete function. 179 183 180 184 The given template will be used to confirm deletetion if this view is 181 fetched using GET; for saf ty, deletion will only be performed if this185 fetched using GET; for safety, deletion will only be performed if this 182 186 view is POSTed. 183 187 184 188 Templates: ``<app_label>/<model_name>_confirm_delete.html`` … … 196 200 obj.delete() 197 201 if request.user.is_authenticated(): 198 202 request.user.message_set.create(message=ugettext("The %(verbose_name)s was deleted.") % {"verbose_name": model._meta.verbose_name}) 203 if post_delete_action: 204 post_delete_action(object_id, slug, slug_field) 199 205 return HttpResponseRedirect(post_delete_redirect) 200 206 else: 201 207 if not template_name: -
docs/ref/generic-views.txt
896 896 897 897 **Optional arguments:** 898 898 899 * ``post_save_action``: A method to invoke after saving the object. By 900 default, it's ``None``. 901 902 If ``post_save_action`` is not ``None``, the method is invoked before 903 redirecting to the URL of ``post_save_redirect``. The parameters 904 ``object_id``, ``slug`` and ``slug_field`` are passed. 905 899 906 * ``post_save_redirect``: A URL to which the view will redirect after 900 907 saving the object. By default, it's ``object.get_absolute_url()``. 901 908 … … 981 988 982 989 **Optional arguments:** 983 990 991 * ``post_save_action``: A method to invoke after saving the object. By 992 default, it's ``None``. 993 994 If ``post_save_action`` is not ``None``, the method is invoked before 995 redirecting to the URL of ``post_save_redirect``. The parameters 996 ``object_id``, ``slug`` and ``slug_field`` are passed. 997 984 998 * ``post_save_redirect``: A URL to which the view will redirect after 985 999 saving the object. By default, it's ``object.get_absolute_url()``. 986 1000 … … 1070 1084 1071 1085 **Optional arguments:** 1072 1086 1087 * ``post_delete_action``: A method to invoke after saving the object. By 1088 default, it's ``None``. 1089 1090 If ``post_delete_action`` is not ``None``, the method is invoked before 1091 redirecting to the URL of ``post_delete_redirect``. The parameters 1092 ``object_id``, ``slug`` and ``slug_field`` are passed. 1093 1073 1094 * ``login_required``: A boolean that designates whether a user must be 1074 1095 logged in, in order to see the page and save changes. This hooks into the 1075 1096 Django :ref:`authentication system <topics-auth>`. By default, this is