Ticket #9094: create_update.patch

File create_update.patch, 5.1 KB (added by das, 16 years ago)
  • django/views/generic/create_update.py

     
    9191                      % (model._meta.verbose_name, lookup_kwargs))
    9292
    9393def 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,
    9595        login_required=False, context_processors=None, form_class=None):
    9696    """
    9797    Generic object-creation function.
     
    112112            new_object = form.save()
    113113            if request.user.is_authenticated():
    114114                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)
    115117            return redirect(post_save_redirect, new_object)
    116118    else:
    117119        form = form_class()
     
    128130
    129131def update_object(request, model=None, object_id=None, slug=None,
    130132        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,
    132134        context_processors=None, template_object_name='object',
    133135        form_class=None):
    134136    """
     
    154156            obj = form.save()
    155157            if request.user.is_authenticated():
    156158                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)
    157161            return redirect(post_save_redirect, obj)
    158162    else:
    159163        form = form_class(instance=obj)
     
    170174    populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.attname))
    171175    return response
    172176
    173 def delete_object(request, model, post_delete_redirect, object_id=None,
     177def delete_object(request, model, post_delete_redirect, post_delete_action=None, object_id=None,
    174178        slug=None, slug_field='slug', template_name=None,
    175179        template_loader=loader, extra_context=None, login_required=False,
    176180        context_processors=None, template_object_name='object'):
     
    178182    Generic object-delete function.
    179183
    180184    The given template will be used to confirm deletetion if this view is
    181     fetched using GET; for safty, deletion will only be performed if this
     185    fetched using GET; for safety, deletion will only be performed if this
    182186    view is POSTed.
    183187
    184188    Templates: ``<app_label>/<model_name>_confirm_delete.html``
     
    196200        obj.delete()
    197201        if request.user.is_authenticated():
    198202            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)
    199205        return HttpResponseRedirect(post_delete_redirect)
    200206    else:
    201207        if not template_name:
  • docs/ref/generic-views.txt

     
    896896
    897897**Optional arguments:**
    898898
     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
    899906    * ``post_save_redirect``: A URL to which the view will redirect after
    900907      saving the object. By default, it's ``object.get_absolute_url()``.
    901908
     
    981988
    982989**Optional arguments:**
    983990
     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
    984998    * ``post_save_redirect``: A URL to which the view will redirect after
    985999      saving the object. By default, it's ``object.get_absolute_url()``.
    9861000
     
    10701084
    10711085**Optional arguments:**
    10721086
     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
    10731094    * ``login_required``: A boolean that designates whether a user must be
    10741095      logged in, in order to see the page and save changes. This hooks into the
    10751096      Django :ref:`authentication system <topics-auth>`. By default, this is
Back to Top