diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2018-02-13 21:40:48 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2018-02-13 21:40:48 -0500 |
| commit | 49f9df9b774b48ceef6f3a99f7a6f4912730dc5f (patch) | |
| tree | 5014e304fa69c0d48ae842780c488440314f0576 /app/dispatch | |
| parent | 1d5d056670d9d63d27d6363de4563435d5ff4cdb (diff) | |
| download | dispatch-tracker-49f9df9b774b48ceef6f3a99f7a6f4912730dc5f.tar.gz dispatch-tracker-49f9df9b774b48ceef6f3a99f7a6f4912730dc5f.tar.xz | |
Add logging for Invoices, User Invoice Number, and Identity. Added template to show audit logs as well as a view
Diffstat (limited to 'app/dispatch')
| -rw-r--r-- | app/dispatch/models.py | 5 | ||||
| -rw-r--r-- | app/dispatch/templates/dispatch/log/summary.html | 74 | ||||
| -rw-r--r-- | app/dispatch/templatetags/dynamic_key.py | 1 | ||||
| -rw-r--r-- | app/dispatch/urls.py | 5 | ||||
| -rw-r--r-- | app/dispatch/views.py | 9 |
5 files changed, 93 insertions, 1 deletions
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 %} +<div class="row"> + <div class="col s12"> + <h1>Recent User Activities</h1> + </div> +</div> + +{% load dynamic_key %} + + +<!-- {{object_list}} --> + + <div class="row"> + <div class="col s12"> + <!-- <h4>Recent Changes</h4> --> + <ul class="collapsible popout" data-collapsible="accordion"> + {% for h in object_list %} + {% if h.actor is not None %} + <li> + <div class="collapsible-header"> + <!-- this seems to be a shitty hack, but I'm going to leave it --> + <div class="col s12"> + Change By: {{h.actor}} + </div> + + <div class="col s12"> + Date: {{h.timestamp}} + </div> + + <div class="col s12"> + Model: {{h.content_type.model}} + </div> + + <div class="col s12"> + Action: + {% if h.action == h.Action.CREATE %} + <td>Create</td> + {% elif h.action == h.Action.UPDATE %} + <td>Update</td> + {% elif h.action == h.Action.DELETE %} + <td>Delete</td> + {% endif %} + </div> + </div> + <div class="collapsible-body"> + <table> + <thead> + <th>Field</th> + <th>From</th> + <th>To</th> + </thead> + <tbody> + {% for field, changes in h.changes_dict.items %} + <tr> + <th>{{field}}</th> + <td>{{changes|getindex:0}}</td> + <td>{{changes|getindex:1}}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </li> + {% endif %} + {% endfor %} + </ul> + </div> + </div> + +{% 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<pk>\d+)$', views.InvoiceDelete.as_view(), name='invoice_delete'), url(r'^drivers/view/(?P<pk>\d+)/generate/$', views.InvoiceGenerateForDates, name='invoice_generate'), + # url(r'^audit_log/summary/(?P<pk>\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 |
