Extended logging module

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
xlogging.py:

from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_unicode

VIEW = 4

def log_view(request, object):
    """    Log that an object is being viewed by the user.
    """
    from django.contrib.admin.models import LogEntry
    LogEntry.objects.log_action(
        user_id         = request.user.pk,
        content_type_id = ContentType.objects.get_for_model(object).pk,
        object_id       = object.pk,
        object_repr     = force_unicode(object),
        action_flag     = VIEW,
        change_message  = "Accessed object %s in %s." % (force_unicode(object), ContentType.objects.get_for_model(object))
    )

admin.py

from some.application.module.xlogging import log_view

class SomeAdmin(admin.ModelAdmin):
    def change_view(self, request, object_id, extra_context=None):
        object = self.queryset(request).get(pk=unquote(object_id))
        log_view(request, object)
        return super(SomeAdmin, self).change_view(request, object_id, extra_context)

More like this

  1. Decorator that limits request methods by schinckel 3 years, 9 months ago
  2. Cached lookup model mixin by isagalaev 5 years, 3 months ago
  3. Compact list_filter by onlinehero 3 years, 3 months ago
  4. Confirm alert if the user navigates away without saving changes by mrazzari 3 years, 10 months ago
  5. Action that respects the filters in changeview_list by grillermo 7 months, 1 week ago

Comments

(Forgotten your password?)