adminjournal.mixins module

class adminjournal.mixins.JournaledModelAdminMixin[source]

Bases: object

Mixin for ModelAdmin classes to issue journal entries on various actions via the model admin.

Tracked actions:
  • View changelist (w/ and w/o filters)
  • View object change view
  • Change object
  • Add object
  • Delete object
  • Changelist actions (selected action and selected objects)
log_to_adminjournal(action, user, message, model=None, payload=None)[source]

The log_to_adminjournal method requires at least the action type and the issuing user together with a human readable message or a change_message-style list from Django’s LogEntry.

The method might use change_message-style lists to generate a human readable version of the data.

If a change_message-style input is provided, the payload is ignored.

If a str message is provided and the payload is a dictionary, the data is passed to the persistence layer.

log_addition(request, model, message)[source]

In addition to the Django LogEntry, add another entry to the adminjournal.

log_change(request, model, message)[source]

In addition to the Django LogEntry, add another entry to the adminjournal.

log_deletion(request, model, object_repr)[source]

In addition to the Django LogEntry, add another entry to the adminjournal.

render_change_form(request, *args, **kwargs)[source]

If a object change view is requested (GET request on change view), a ACTION_VIEW entry is generated to track read access to single objects.

response_action(request, queryset)[source]

Actions on change lists are tracked too. To achieve this, this method parses the POST request and checks for various action fields to

  • Learn what action was triggered
  • What obejects are included in the action call
  • Are all objects involved or just some selected ones

We don’t know what the action does, therefore all actions are tracked as ACTION_VIEW.

changelist_view(request, *args, **kwargs)[source]

GET requests on the changelist are tracked as ACTION_VIEW entries. The changelist view might also return redirects. This case is handled by ensuring that a proper TemplateResponse is available and the “cl” context (which is the ChangeList instance) is present.

Parameters passed to the change list are tracked too. This allows to reconstruct the subset of objects a user viewed.