Read log audit for django
Project description
Simple app to log every time an object is displayed, can be used in combination with django-simple-history for a full audit solution. Currently the standard generic class based views: DetailView, UpdateView, DeleteView, ListView are are supported out of the box, since the views deal with displaying objects as part of the functionality. For DeleteView and UpdateView in most cases you want to display the object (GET request) before you allow the user to delete/update the object.
Other custom views can most likely be supported see Using django-read-log in combination with unsupported views
For each view the following data is stored in the audit model (ReadLog):
- user:
Who view the item, can be an anonymous user.
- content_object:
A reference to the viewed object using a generic foreign key, if you delete an object the log entry will still be present.
- operation:
What operation triggered the the log entry to be written(detail, list, update, delete).
- logged_at:
When was the object viewed.
Usage
Easy to use just in 3 simple steps
add the app ‘read_log’ to INSTALLED_APPS in settings.py
run the migration: python manage.py migrate read_log
import and use the mixin
from read_log.view_mixins import ReadLogMixin
from test_read_log.models import TestModel
class TestDetailView(ReadLogMixin, DetailView):
model = TestModel
Customizing logged operations
By default the following views maps to the following operations.
- DetailView:
detail
- UpdateView:
update
- ListView:
list
- Delete:
delete
This can be changed by setting the log_operations attribute to a string of you choice
from read_log.view_mixins import ReadLogMixin
from test_read_log.models import TestModel
class TestDetailView(ReadLogMixin, DetailView):
log_operation = 'my_choice'
model = TestModel
Using django-read-log in combination with unsupported views
Because the view mixin hooks into the get_context_data view function it should be possible to add the mixin to unsupported views as long as they either implement or inherit the get_context_data function (eg. from SingleObjectMixin or MultipleObjectMixin) and define the class attribute ‘log_operation’ to the string you want to have logged as the operations field.
Presentation not included
When audit is needed you normally want to limit the expose of data hench forth no presentation of the ReadLog is included and if you need a way to display the Readlog it is up to you to implement it.
from django.contrib import admin
from read_log.models import ReadLog
admin.site.register(ReadLog)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-read-log-0.80.tar.gz
.
File metadata
- Download URL: django-read-log-0.80.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a252c38b44173f73a23b5a95fba312ac353deb5569c3b997cb3011634d62b6d |
|
MD5 | 21fb79b62c3664fa4967a49156ea875b |
|
BLAKE2b-256 | e161fbb21d4fafd232209d4f4644824fe746a64859686c1c1fb0e992fb4235de |
File details
Details for the file django_read_log-0.80-py3-none-any.whl
.
File metadata
- Download URL: django_read_log-0.80-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4989bc7d478ce8e0bc5bba97892766d1bf23cc7269583da99b7e7e7140ddb9c |
|
MD5 | 0550016cb50d235c7aaf38e7814a6532 |
|
BLAKE2b-256 | 5df61cb58685c7faac31559a2654a7992b83fcd129fe247ec2dacdfa29980e22 |