From 49f9df9b774b48ceef6f3a99f7a6f4912730dc5f Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Tue, 13 Feb 2018 21:40:48 -0500 Subject: Add logging for Invoices, User Invoice Number, and Identity. Added template to show audit logs as well as a view --- app/dispatch/models.py | 5 +- app/dispatch/templates/dispatch/log/summary.html | 74 ++++++++++++++++++++++++ app/dispatch/templatetags/dynamic_key.py | 1 + app/dispatch/urls.py | 5 ++ app/dispatch/views.py | 9 +++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 app/dispatch/templates/dispatch/log/summary.html (limited to 'app') diff --git a/app/dispatch/models.py b/app/dispatch/models.py index 0dde07b..451eb31 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -51,7 +51,7 @@ class Load(models.Model): amount = models.DecimalField(max_digits=10,decimal_places=2, default="0") def __str__(self): - return "{c}, {d} ( {a} )".format( + return "Load, Customer: {c}, Description: {d} Amount: {a}".format( c=self.customer, d=self.description, a=self.amount) def get_absolute_url(self): @@ -206,5 +206,8 @@ class InvoiceItem(models.Model): +auditlog.register(Invoice) +auditlog.register(UserInvoiceNumber) +auditlog.register(Identity) auditlog.register(Customer) auditlog.register(Load) diff --git a/app/dispatch/templates/dispatch/log/summary.html b/app/dispatch/templates/dispatch/log/summary.html new file mode 100644 index 0000000..37e7d13 --- /dev/null +++ b/app/dispatch/templates/dispatch/log/summary.html @@ -0,0 +1,74 @@ +{% extends 'dispatch/base.html' %} + +{% block title %}Recent User Activities{% endblock %} + +{% block content %} +
+
+

Recent User Activities

+
+
+ +{% load dynamic_key %} + + + + +
+
+ +
    + {% for h in object_list %} + {% if h.actor is not None %} +
  • +
    + +
    + Change By: {{h.actor}} +
    + +
    + Date: {{h.timestamp}} +
    + +
    + Model: {{h.content_type.model}} +
    + +
    + Action: + {% if h.action == h.Action.CREATE %} + Create + {% elif h.action == h.Action.UPDATE %} + Update + {% elif h.action == h.Action.DELETE %} + Delete + {% endif %} +
    +
    +
    + + + + + + + + {% for field, changes in h.changes_dict.items %} + + + + + + {% endfor %} + +
    FieldFromTo
    {{field}}{{changes|getindex:0}}{{changes|getindex:1}}
    +
    +
  • + {% endif %} + {% endfor %} +
+
+
+ +{% endblock %} diff --git a/app/dispatch/templatetags/dynamic_key.py b/app/dispatch/templatetags/dynamic_key.py index b3cd165..7d10079 100644 --- a/app/dispatch/templatetags/dynamic_key.py +++ b/app/dispatch/templatetags/dynamic_key.py @@ -40,3 +40,4 @@ def customer_loads_this_week(cu): wk = get_week_dates() return len(cu.load_set.filter(date__range=(wk['start_date'], wk['end_date']))) + diff --git a/app/dispatch/urls.py b/app/dispatch/urls.py index 046acee..1b7d71f 100644 --- a/app/dispatch/urls.py +++ b/app/dispatch/urls.py @@ -49,4 +49,9 @@ urlpatterns = [ url(r'^invoices/delete/(?P\d+)$', views.InvoiceDelete.as_view(), name='invoice_delete'), url(r'^drivers/view/(?P\d+)/generate/$', views.InvoiceGenerateForDates, name='invoice_generate'), + # url(r'^audit_log/summary/(?P\d+)$', views.AuditLog.as_view(), name='driver_summary'), + url(r'^audit_log/summary/$', views.AuditLog.as_view(), name='log_summary'), + # url(r'^audit_log/unusual/$', views.AuditLogUnusual.as_view(), name='log_unusual'), + # url(r'^drivers/activity/summary$', views.DriverActivitySummary.as_view(), name='driver_activity_summary'), + ] diff --git a/app/dispatch/views.py b/app/dispatch/views.py index 2aa82f5..f4e9a92 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render, redirect from django.http import HttpResponse from django.utils.encoding import smart_str +from auditlog.models import LogEntry # from django.template import loader from django.core.urlresolvers import reverse # import django.contrib.auth as auth @@ -177,6 +178,14 @@ class DriverSummary(UserPassesTestMixin, LoadDateSort): return context +class AuditLog(UserPassesTestMixin, ListView): + template_name = "dispatch/log/summary.html" + model = LogEntry + + def test_func(self): + return self.request.user.is_superuser + + class DriverUpdate(UserPassesTestMixin, UpdateView): template_name = "dispatch/drivers/edit.html" model = User -- cgit v1.2.3