From fae5a7e38ef7084990724df51488f54c52ec592d Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Wed, 25 Oct 2017 00:33:14 -0400 Subject: Better driver edit page as well as pages for working with Identity --- README.md | 3 +- app/dispatch/models.py | 3 + .../templates/dispatch/drivers/detail.html | 136 +++++++++------------ app/dispatch/templates/dispatch/drivers/list.html | 6 +- .../templates/dispatch/drivers/summary.html | 115 +++++++++++++++++ .../templates/dispatch/generic_load_listing.html | 2 +- .../templates/dispatch/identity/create.html | 15 +++ .../templates/dispatch/identity/detail.html | 42 +++++++ app/dispatch/templates/dispatch/identity/edit.html | 18 +++ app/dispatch/templates/dispatch/loads/detail.html | 2 +- app/dispatch/templates/dispatch/nav.html | 4 +- app/dispatch/urls.py | 9 +- app/dispatch/views.py | 90 +++++++++----- 13 files changed, 322 insertions(+), 123 deletions(-) create mode 100644 app/dispatch/templates/dispatch/drivers/summary.html create mode 100644 app/dispatch/templates/dispatch/identity/create.html create mode 100644 app/dispatch/templates/dispatch/identity/detail.html create mode 100644 app/dispatch/templates/dispatch/identity/edit.html diff --git a/README.md b/README.md index e413e29..e23bae5 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,10 @@ Requirements going forward: * Settings: * `default_bill_to` must be set + * Identity Edit page needs a little bit of work for regular users * Delete Views are completely fucked--this needs to be fixed - * Drivers will be able to generate a weekly PDF invoice * Upload Invoice logos on Identity Objects for use in Invoices * Change "user" to Vendor on the "Add Load Page" - * Users must be able to initially create new load objects * Change Name To "Load Pay System" -- we're going to think about it * Freight Invoicing System * Weekly Total Invoices from the Company(Driver) to software owner diff --git a/app/dispatch/models.py b/app/dispatch/models.py index d525818..13650ac 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -65,6 +65,9 @@ class Identity(models.Model): st = Settings(key="default_bill_to", value=int(self.pk)) st.save() + def get_absolute_url(self): + return '/drivers/view/{:d}'.format(self.user.pk) + class Settings(models.Model): key = models.CharField(max_length=256) value = models.CharField(max_length=256) diff --git a/app/dispatch/templates/dispatch/drivers/detail.html b/app/dispatch/templates/dispatch/drivers/detail.html index fc197b5..8ce409d 100644 --- a/app/dispatch/templates/dispatch/drivers/detail.html +++ b/app/dispatch/templates/dispatch/drivers/detail.html @@ -1,115 +1,97 @@ {% extends 'dispatch/base.html' %} -{% block title %}Details - {{ object.first_name }} {{ object.last_name }}{% endblock %} +{% block title %}View User {{object.username}}{% endblock %} {% block content %}
-

Summary for {{ object.first_name }} {{ object.last_name }}

-

Loads for {{week_dates.start_date|date:"l, F, d"}} to {{week_dates.end_date|date:"l, F, d"}}

+

+ User: {{object.first_name}} {{object.last_name}} ( {{object.username}} ) +

-
+
- -{% if not request.user.is_superuser %}
- - - - - - - - - - {% for load in loads_nosplit %} - - - - - - - {% endfor %} - + + + + + + + + + + + + + + + +
DateDescriptionTotal
{{load.date}}{{load.description}}{{load.amount}} - - View - -
First Name:{{object.first_name}}
Last Name:{{object.last_name}}
Username:{{object.username}}
Email:{{object.email}}
-{% endif %} + + +{% if ident is not None %} +
+
+ +
+
- - - - - - - - - - + + + + + + + + + + + + + + + + + +
Number of LoadsAverage Load costTotal Load cost
{{stats.count}}${{stats.average|stringformat:".3f"}}${{stats.sum}}Name:{{ident.name}}
Address:{{ident.address}}
City:{{ident.city}}
State:{{ident.state}}
Zip Code:{{ident.zip_code}}
- - - - - +{% else %}
- - - -{% if stats.incomplete_loads > 0 %}
-
-
-
- - Note: One or more loads has a 0 amount that needs attention - -
-
+
+ No Identity found.
{% endif %} -{% if request.user.is_superuser %} - {% load custom_tags %} - {% listForCommaString "Customer,Amount,Description" as load_headers %} - {% include "dispatch/generic_load_listing.html" %} -{% endif %} - - - {% endblock %} diff --git a/app/dispatch/templates/dispatch/drivers/list.html b/app/dispatch/templates/dispatch/drivers/list.html index 4153fe9..8b7508b 100644 --- a/app/dispatch/templates/dispatch/drivers/list.html +++ b/app/dispatch/templates/dispatch/drivers/list.html @@ -23,10 +23,8 @@ {{ driver.last_name }} {{ driver.email }} - {% if user.is_superuser %} - Edit - {% endif %} - View + Edit + View {% empty %} diff --git a/app/dispatch/templates/dispatch/drivers/summary.html b/app/dispatch/templates/dispatch/drivers/summary.html new file mode 100644 index 0000000..d849e9d --- /dev/null +++ b/app/dispatch/templates/dispatch/drivers/summary.html @@ -0,0 +1,115 @@ +{% extends 'dispatch/base.html' %} + +{% block title %}Details - {{ object.first_name }} {{ object.last_name }}{% endblock %} + +{% block content %} +
+
+

Summary for {{ object.first_name }} {{ object.last_name }}

+

Loads for {{week_dates.start_date|date:"l, F, d"}} to {{week_dates.end_date|date:"l, F, d"}}

+
+
+ + + +{% if not request.user.is_superuser %} +
+
+ + + + + + + + + + + {% for load in loads_nosplit %} + + + + + + + {% endfor %} + +
DateDescriptionTotal
{{load.date}}{{load.description}}{{load.amount}} + + View + +
+
+
+{% endif %} + +
+
+ + + + + + + + + + + + + +
Number of LoadsAverage Load costTotal Load cost
{{stats.count}}${{stats.average|stringformat:".3f"}}${{stats.sum}}
+
+
+ + + + + + + +{% if stats.incomplete_loads > 0 %} +
+
+
+
+ + Note: One or more loads has a 0 amount that needs attention + +
+
+
+
+{% endif %} + +{% if request.user.is_superuser %} + {% load custom_tags %} + {% listForCommaString "Customer,Amount,Description" as load_headers %} + {% include "dispatch/generic_load_listing.html" %} +{% endif %} + + + +{% endblock %} diff --git a/app/dispatch/templates/dispatch/generic_load_listing.html b/app/dispatch/templates/dispatch/generic_load_listing.html index 7fb42f1..5512184 100644 --- a/app/dispatch/templates/dispatch/generic_load_listing.html +++ b/app/dispatch/templates/dispatch/generic_load_listing.html @@ -37,7 +37,7 @@ {% endif %} {% endif %} {% if "Driver" in load_headers %} - {{ load.user.first_name }} {{ load.user.last_name }} + {{ load.user.first_name }} {{ load.user.last_name }} {% endif %} {% if "Amount" in load_headers %} diff --git a/app/dispatch/templates/dispatch/identity/create.html b/app/dispatch/templates/dispatch/identity/create.html new file mode 100644 index 0000000..90cdd8e --- /dev/null +++ b/app/dispatch/templates/dispatch/identity/create.html @@ -0,0 +1,15 @@ +{% extends 'dispatch/base.html' %} + + +{% block content %} +
+
+

New Identity

+
+
+ +
{% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/app/dispatch/templates/dispatch/identity/detail.html b/app/dispatch/templates/dispatch/identity/detail.html new file mode 100644 index 0000000..491c59e --- /dev/null +++ b/app/dispatch/templates/dispatch/identity/detail.html @@ -0,0 +1,42 @@ +{% extends 'dispatch/base.html' %} + +{% block title %}Identity for {{object.user.username}}{% endblock %} + +{% block content %} +
+
+

+ Identity for {{object.user.username}} +

+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + +
Name:{{object.name}}
Address:{{object.address}}
City:{{object.city}}
State:{{object.state}}
Zip Code:{{object.zip_code}}
+
+
+ +{% endblock %} + diff --git a/app/dispatch/templates/dispatch/identity/edit.html b/app/dispatch/templates/dispatch/identity/edit.html new file mode 100644 index 0000000..a48a8d1 --- /dev/null +++ b/app/dispatch/templates/dispatch/identity/edit.html @@ -0,0 +1,18 @@ +{% extends 'dispatch/base.html' %} + +{% block title %}Edit Identity for {{object.user.username}}{% endblock %} + +{% block content %} +
+
+

+ Identity for {{object.user.username}} +

+
+
+ +
{% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/app/dispatch/templates/dispatch/loads/detail.html b/app/dispatch/templates/dispatch/loads/detail.html index d8feea3..62a8b30 100644 --- a/app/dispatch/templates/dispatch/loads/detail.html +++ b/app/dispatch/templates/dispatch/loads/detail.html @@ -23,7 +23,7 @@ User - {{object.user}} + {{object.user}} diff --git a/app/dispatch/templates/dispatch/nav.html b/app/dispatch/templates/dispatch/nav.html index 532b2a9..a4fc8cb 100644 --- a/app/dispatch/templates/dispatch/nav.html +++ b/app/dispatch/templates/dispatch/nav.html @@ -5,8 +5,8 @@
  • Customers
  • Invoices
  • {% else %} -
  • Summary -
  • My Account
  • +
  • Summary +
  • My Account
  • {% endif %}
  • Logout
  • {% else %} diff --git a/app/dispatch/urls.py b/app/dispatch/urls.py index 71f886a..9992489 100644 --- a/app/dispatch/urls.py +++ b/app/dispatch/urls.py @@ -11,9 +11,14 @@ urlpatterns = [ url(r'^logout/$', authviews.LogoutView.as_view(next_page='/'), name='logout'), url(r'^drivers/$', views.DriverList.as_view(), name='driver_list'), - url(r'^drivers/view/(?P\d+)$', views.DriverDetail.as_view(), name='driver_detail'), + url(r'^drivers/summary/(?P\d+)$', views.DriverSummary.as_view(), name='driver_summary'), + url(r'^drivers/view/(?P\d+)$', views.DriverDetail.as_view(), name='driver_details'), url(r'^drivers/edit/(?P\d+)$', views.DriverUpdate.as_view(), name='driver_edit'), + url(r'^drivers/(?P\d+)/identity/(?P\d+)$', views.IdentityDetail.as_view(), name='identity_detail'), + url(r'^drivers/(?P\d+)/identity/new/$', views.IdentityCreate.as_view(), name='identity_create'), + url(r'^identity/edit/(?P\d+)$', views.IdentityUpdate.as_view(), name='identity_edit'), + url(r'^customers/$', views.CustomerList.as_view(), name='customer_list'), url(r'^customers/new$', views.CustomerCreate.as_view(), name='customer_new'), url(r'^customers/view/(?P\d+)$', views.CustomerDetail.as_view(), name='customer_detail'), @@ -26,14 +31,12 @@ urlpatterns = [ url(r'^loads/edit/(?P\d+)$', views.LoadUpdate.as_view(), name='load_edit'), url(r'^loads/delete/(?P\d+)$', views.LoadDelete.as_view(), name='load_delete'), - url(r'^loads/upload/(?P\d+)$', views.PaperworkUpload, name='paperwork_upload'), url(r'^loads/(?P\d+)/paperwork/delete/(?P\d+)$', \ views.PaperworkDelete, name='paperwork_delete'), url(r'^loads/(?P\d+)/paperwork/dl/(?P\d+)$', \ views.PaperworkDownload, name='paperwork_download'), - url(r'^invoices/$', views.InvoiceList.as_view(), name='invoice_list'), url(r'^invoices/view/(?P\d+)$', views.InvoiceDetail.as_view(), name='invoice_detail'), # url(r'^invoices/edit/(?P\d+)$', views.InvoiceEdit.as_view(), name='invoice_edit'), diff --git a/app/dispatch/views.py b/app/dispatch/views.py index 32be26c..ac399f6 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -10,7 +10,7 @@ from django.views.generic import TemplateView,ListView from django.views.generic.detail import DetailView from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.core.urlresolvers import reverse_lazy -from dispatch.models import Customer, Load, Paperwork, Invoice, Settings +from dispatch.models import Customer, Load, Paperwork, Invoice, Settings, Identity from dispatch.forms import AddPaperworkForm from django.contrib.auth.models import User from django.contrib.auth.mixins import UserPassesTestMixin @@ -72,7 +72,7 @@ class DriverList(UserPassesTestMixin, ListView): def test_func(self): return self.request.user.is_superuser -class DriverDetail(UserPassesTestMixin, LoadDateSort): +class DriverDetail(UserPassesTestMixin, DetailView): template_name = "dispatch/drivers/detail.html" model = User @@ -85,6 +85,27 @@ class DriverDetail(UserPassesTestMixin, LoadDateSort): # Shit gets fucky with super() really fast, but this seems to work context = super(DriverDetail, self).get_context_data(**kwargs) + try: + context['ident'] = Identity.objects.get(user=self.get_object().pk) + except: + context['ident'] = None + + return context + + +class DriverSummary(UserPassesTestMixin, LoadDateSort): + template_name = "dispatch/drivers/summary.html" + model = User + + def test_func(self): + # Seems a little hacky at first but it works! + return self.request.user.is_superuser or \ + self.get_object().pk is self.request.user.id + + def get_context_data(self, **kwargs): + # Shit gets fucky with super() really fast, but this seems to work + context = super(DriverSummary, self).get_context_data(**kwargs) + stats = {}; stats['count'], stats['average'], stats['sum'] = (0,0,0) stats['incomplete_loads'] = 0 @@ -113,6 +134,13 @@ class DriverUpdate(UserPassesTestMixin, UpdateView): success_url = reverse_lazy('driver_list') fields = ['username', 'first_name','last_name','email','groups', 'is_active'] + def get_context_data(self, **kwargs): + # Shit gets fucky with super() really fast, but this seems to work + context = super(DriverUpdate, self).get_context_data(**kwargs) + + + return context + def test_func(self): # Seems a little hacky at first but it works! return self.request.user.is_superuser or \ @@ -279,6 +307,33 @@ def PaperworkDownload(request, load_id, pk): except Exception as e: print(e) +# Identity +class IdentityDetail(DetailView): + template_name = "dispatch/identity/detail.html" + model = Identity + +def SetDefaultIdentity(request, pk): + ident = Ident.objects.get(pk=pk) + ident.set_default() + return redirect(reverse('identity_detail', kwargs={'pk': pk})) + +class IdentityCreate(UserPassesTestMixin, CreateView): + template_name = "dispatch/identity/edit.html" + model = Identity + fields = ['user', 'name', 'address', 'city', 'state', 'zip_code'] + + def test_func(self): + return self.request.user.is_superuser or \ + self.get_object().user.pk is self.request.user.pk + +class IdentityUpdate(UserPassesTestMixin, UpdateView): + template_name = "dispatch/identity/edit.html" + model = Identity + fields = ['user', 'name', 'address', 'city', 'state', 'zip_code'] + + def test_func(self): + return self.request.user.is_superuser or \ + self.get_object().user.pk is self.request.user.pk # Invoice @@ -309,42 +364,11 @@ def InvoiceGenerateForDates(request, pk): return redirect(reverse('invoice_list')) - - - -# class InvoiceEdit(UserPassesTestMixin, UpdateView): -# template_name = "dispatch/invoice/edit.html" -# model = Invoice -# fields = ['invoice_date','due_date'] -# -# def test_func(self): -# # Seems a little hacky at first but it works! -# return self.request.user.is_superuser or \ -# self.get_object().user.pk is self.request.user.pk -# -# class InvoiceCreate(CreateView): -# template_name = "dispatch/invoice/create.html" -# model = Invoice -# fields = ['invoice_date', 'due_date'] -# -# def get(self,request): -# if request.user.is_superuser: -# self.fields.insert(1,'user') -# return super(LoadCreate, self).get(request) -# -# def form_valid(self, form): -# if not self.request.user.is_superuser: -# load = form.save(commit=False) -# load.user = self.request.user -# return super(LoadCreate, self).form_valid(form) - class InvoiceDelete(UserPassesTestMixin, DeleteView): template_name = "dispatch/invoice/list.html" model = Invoice success_url = reverse_lazy('invoice_list') def test_func(self): - print (self.request.user.is_superuser) - print(self.get_object().user.pk is self.request.user.pk) return self.request.user.is_superuser or \ self.get_object().user.pk is self.request.user.pk -- cgit v1.2.3