I make extensive use of generic views in one of my apps. Now that the
app is nearly finished, I'm being asked to do change tracking/audit
trail on the objects managed in the generic views. Recognizing that I
could just create and save django.contrib.admin.models.LogEntry()
objects and possibly create a view or two to view only the audit
records associated with my application. The trouble comes in from not
having a particularly good insertion point to create the LogEntry()
objects while using a generic view.

The closest I've been able to figure out is to create a custom view and
call create_object from my view. Then, depending on whether the
returned object from create_object is an instance of
HttpResponseRedirect() I can determine if the addition/edit was
successful; however, I still don't have access to the new/editted
object.

I did consider creating a custom view that would be called via access
to a URL accessed as result of a post_save_redirect parameter on the
generic view; however, I'm uncomfortable depending upon a redirect to
create audit records. For one, it'd be easy for a browser to disregard
the redirect in order to avoid log creation. Additionally, it would be
easy to "forge" audit records by direct access to the URL attached to
the audit records creation view.

Would it be possible to add a generic view parameter along the lines of
'post_save_hook' which is expected to be callable object which is
passed the newly created object (in the case of create_object()) and
ideally a copy of the original (non-updated) object along with the
updated object in the case of update_object. These hooks would only be
called in case of a successful model validation and database save.

If there is agreement that the post_save_hook would provide value and
is the proper way to accomplish what I would assume is a fairly common
need (do something with the newly updated/created object from a generic
view), then I'll go ahead and submit it as a bug feature and may even
be able to submit a patch along with the request.

  -- William


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to