Audit logging
WOO Publications ships some high and low level Python API’s to ensure user actions are properly logged in the audit log.
You can find these in the top-level module woo_publications.logging.service.
Admin integration
Mixins/helper classes for django.contrib.admin.ModelAdmin and related classes.
- class woo_publications.logging.service.AdminAuditLogMixin
Enable audit logging in the admin.
Add, change, delete and view action will be logged.
- class woo_publications.logging.service.AuditLogInlineformset(*args, **kwargs)
Custom formset class for admin inlines to enable audit logging.
Add and update actions on related objects are logged.
- delete_existing(obj, commit=True)
Deletes an existing model instance.
- save_existing(form, obj, commit=True)
Save and return an existing model instance for the given form.
- save_new(form, commit=True)
Save and return a new model instance for the given form.
- woo_publications.logging.service.get_logs_link(obj: Model) tuple[str, str]
Return a tuple of
urlandlabelto display logs related toobj.
DRF integration
Mixins are available to drop into a rest_framework.views.APIView or
rest_framework.viewsets.ViewSet class.
- class woo_publications.logging.service.AuditTrailViewSetMixin
Add support for audit trails.
This includes all the CRUD operations.
Individual mixins
- class woo_publications.logging.service.AuditTrailCreateMixin
Add support for audit trails to the
rest_framework.mixins.CreateModelMixin.
- class woo_publications.logging.service.AuditTrailRetrieveMixin
Add support for audit trails to the
rest_framework.mixins.RetrieveModelMixin.
- class woo_publications.logging.service.AuditTrailUpdateMixin
Add support for audit trails to the
rest_framework.mixins.UpdateModelMixin.
- class woo_publications.logging.service.AuditTrailDestroyMixin
Add support for audit trails to the
rest_framework.mixins.DestroyModelMixin.
Low level API
The low-level API is used by the high-level API above. It may be required in certain specialized cases.
- woo_publications.logging.service.audit_api_create(*, content_object: Model, user_id: str, user_display: str, object_data: JSONObject, remarks: str) None
- woo_publications.logging.service.audit_api_read(*, content_object: Model, user_id: str, user_display: str, remarks: str) None
- woo_publications.logging.service.audit_api_update(*, content_object: Model, user_id: str, user_display: str, object_data: JSONObject, remarks: str) None
- woo_publications.logging.service.audit_api_delete(*, content_object: Model, user_id: str, user_display: str, object_data: JSONObject, remarks: str) None
- woo_publications.logging.service.audit_admin_create(*, content_object: Model, django_user: User, object_data: JSONObject) None
- woo_publications.logging.service.audit_admin_read(*, content_object: Model, django_user: User) None
- woo_publications.logging.service.audit_admin_update(*, content_object: Model, django_user: User, object_data: JSONObject) None
- woo_publications.logging.service.audit_admin_delete(*, content_object: Model, django_user: User, object_data: JSONObject) None