From ec9428fdf76b5d70d0f3bcdff3b85e3a83d5f3d5 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Mon, 30 Oct 2017 17:06:23 -0400 Subject: Proper redirect on edit for users. Delete for loads, warning on delete. Invoice view ordered by PK desc --- README.md | 6 +-- app/dispatch/models.py | 2 + app/dispatch/monkey_patch.py | 7 +++ app/dispatch/static/base.js | 7 +++ .../templates/dispatch/invoice/detail.html | 26 +++++------ app/dispatch/templates/dispatch/loads/delete.html | 0 app/dispatch/templates/dispatch/loads/detail.html | 54 ++++++++++++++-------- app/dispatch/views.py | 13 ++++-- 8 files changed, 74 insertions(+), 41 deletions(-) create mode 100644 app/dispatch/monkey_patch.py create mode 100644 app/dispatch/templates/dispatch/loads/delete.html diff --git a/README.md b/README.md index 87c12fe..2d3222c 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,8 @@ Requirements going forward: - * Javascript confirmation on Delete button - * Redirect properly on Invoice Delete - * Delete Views are completely fucked--this needs to be fixed - * Cannot delete invoice at this time + * Users still can't edit their own profiles? + * Pagination for the Invoices page * Settings: * `default_bill_to` must be set * Identity Edit page needs a little bit of work for regular users diff --git a/app/dispatch/models.py b/app/dispatch/models.py index a1e06d7..21c06e0 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -7,6 +7,8 @@ from datetime import datetime from django.core.exceptions import ObjectDoesNotExist from .misc import get_week_dates, paperwork_user_directory_path +from . import monkey_patch + # Create your models here. class Customer(models.Model): diff --git a/app/dispatch/monkey_patch.py b/app/dispatch/monkey_patch.py new file mode 100644 index 0000000..3b87287 --- /dev/null +++ b/app/dispatch/monkey_patch.py @@ -0,0 +1,7 @@ +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse + +def get_absolute_url(self): + return reverse('driver_details', kwargs={'pk': self.pk}) + +User.add_to_class("get_absolute_url", get_absolute_url) diff --git a/app/dispatch/static/base.js b/app/dispatch/static/base.js index 5f57441..a0f2493 100644 --- a/app/dispatch/static/base.js +++ b/app/dispatch/static/base.js @@ -1,3 +1,10 @@ +function warn_submit(text, form) { + if(confirm(text)) { + form = document.querySelector(form) + form.submit() + } +} + $( document ).ready(function(){ all_date_fields = document.querySelectorAll("[name='date']"); diff --git a/app/dispatch/templates/dispatch/invoice/detail.html b/app/dispatch/templates/dispatch/invoice/detail.html index 0d83569..033747c 100644 --- a/app/dispatch/templates/dispatch/invoice/detail.html +++ b/app/dispatch/templates/dispatch/invoice/detail.html @@ -4,9 +4,19 @@ {% block content %}
-
+

Invoice for {{object.invoice_date}} by {{object.owner}}

+
+
+
+ + {% csrf_token %} + Delete + Print +
+
+
@@ -22,7 +32,7 @@
{% csrf_token %} - Delete + Delete Print
@@ -39,16 +49,4 @@ - - {%endblock%} diff --git a/app/dispatch/templates/dispatch/loads/delete.html b/app/dispatch/templates/dispatch/loads/delete.html new file mode 100644 index 0000000..e69de29 diff --git a/app/dispatch/templates/dispatch/loads/detail.html b/app/dispatch/templates/dispatch/loads/detail.html index 62a8b30..3b2ba8d 100644 --- a/app/dispatch/templates/dispatch/loads/detail.html +++ b/app/dispatch/templates/dispatch/loads/detail.html @@ -5,16 +5,22 @@ {% block content %} {% load dynamic_key %}
-
+

Details for {{object.description}}

+
+
+
+ {% csrf_token %} + Delete + Edit +
+
+
-
- Edit -
@@ -51,36 +57,45 @@
Date
+
+
-
+

Attached Files:

- -
- Upload +
+
+

+
+ Upload +
+
+ - +
+
+
{% for p in paperwork_list %} - - - - + + + + {% endfor %} -
Description:
{{p.description}} - Delete - - Download -
{{p.description}} + Delete + + Download +
+ +
-
@@ -118,7 +133,6 @@
- diff --git a/app/dispatch/views.py b/app/dispatch/views.py index 63cc1aa..95aff28 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -151,7 +151,6 @@ class DriverSummary(UserPassesTestMixin, LoadDateSort): class DriverUpdate(UserPassesTestMixin, UpdateView): template_name = "dispatch/drivers/edit.html" model = User - success_url = reverse_lazy('driver_list') # fields = ['username', 'first_name','last_name','email','groups'] fields = [] @@ -174,8 +173,10 @@ class DriverUpdate(UserPassesTestMixin, UpdateView): def test_func(self): # Seems a little hacky at first but it works! - return self.request.user.is_superuser or \ + test = self.request.user.is_superuser or \ self.get_object().pk is self.request.user.id + print(test) + return test # Customer CRUD @@ -434,7 +435,7 @@ class IdentityUpdate(UserPassesTestMixin, UpdateView): model = Identity fields = [] - defualt_fields = ['name', 'address', 'city', 'state', 'zip_code'] + default_fields = ['name', 'address', 'city', 'state', 'zip_code'] superuser_fields = ['user', 'name', 'address', 'city', 'state', 'zip_code'] def get(self, request, *args, **kwargs): @@ -454,6 +455,12 @@ class InvoiceList(FilteredListView): template_name = "dispatch/invoice/list.html" model = Invoice + def get_queryset(self): + # TODO: allow for a pagination + base_qs = super(InvoiceList, self).get_queryset() + # Give me the newest ones first + return base_qs.order_by('-pk') + class InvoiceDetail(DetailView): template_name = "dispatch/invoice/detail.html" -- cgit v1.2.3