From c80bafec506beef3184381ae7f9b55edd438e45a Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 10 Nov 2017 11:05:05 -0500 Subject: Fix typo in 'payment_identifier' Add pagination to Drivers, Customers and Invoices. Filter invoices by paid/unpaid. --- .../management/commands/insert_fake_data.py | 2 - app/dispatch/migrations/0004_auto_20171110_1400.py | 20 +++++ app/dispatch/models.py | 2 +- .../templates/dispatch/companies/list.html | 64 +++++++------- app/dispatch/templates/dispatch/drivers/list.html | 56 +++++++------ .../templates/dispatch/invoice/detail-table.html | 2 + .../templates/dispatch/invoice/detail.html | 2 +- app/dispatch/templates/dispatch/invoice/list.html | 97 +++++++++++++--------- app/dispatch/templates/dispatch/paginator.html | 82 ++++++++++++++++++ app/dispatch/templatetags/custom_tags.py | 3 + app/dispatch/templatetags/dynamic_key.py | 6 ++ app/dispatch/views.py | 13 ++- 12 files changed, 255 insertions(+), 94 deletions(-) create mode 100644 app/dispatch/migrations/0004_auto_20171110_1400.py create mode 100644 app/dispatch/templates/dispatch/paginator.html (limited to 'app') diff --git a/app/dispatch/management/commands/insert_fake_data.py b/app/dispatch/management/commands/insert_fake_data.py index 2969900..d7169fe 100644 --- a/app/dispatch/management/commands/insert_fake_data.py +++ b/app/dispatch/management/commands/insert_fake_data.py @@ -101,8 +101,6 @@ class Command(BaseCommand): first_name=ffname, last_name=flname, email=self.fake.email(), - # Set the fake user name to be the first initial and last name - username=funame, is_active=True ) new_user.save() diff --git a/app/dispatch/migrations/0004_auto_20171110_1400.py b/app/dispatch/migrations/0004_auto_20171110_1400.py new file mode 100644 index 0000000..5feb900 --- /dev/null +++ b/app/dispatch/migrations/0004_auto_20171110_1400.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-11-10 14:00 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dispatch', '0003_invoice_payment_identifer'), + ] + + operations = [ + migrations.RenameField( + model_name='invoice', + old_name='payment_identifer', + new_name='payment_identifier', + ), + ] diff --git a/app/dispatch/models.py b/app/dispatch/models.py index ef59fe4..5801828 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -103,7 +103,7 @@ class Invoice(models.Model): invoice_date = models.DateField() due_date = models.DateField() paid = models.BooleanField(default=False) - payment_identifer = models.CharField(default="", max_length=256) + payment_identifier = models.CharField(default="", max_length=256) def __str__(self): return "Invoice for {} by {} for ${}".format( diff --git a/app/dispatch/templates/dispatch/companies/list.html b/app/dispatch/templates/dispatch/companies/list.html index e08837b..97e54f7 100644 --- a/app/dispatch/templates/dispatch/companies/list.html +++ b/app/dispatch/templates/dispatch/companies/list.html @@ -11,32 +11,40 @@ Add Customer - - - - - - - - - - - {% for customer in object_list %} - - - - - - - - {% empty %} - - {% endfor %} - -
NameAddressPhoneEmail
{{ customer.name }}{{ customer.address }}{{ customer.phone_number }}{{ customer.email_address }} - {% if user.is_superuser %} - Edit - {% endif %} - View -
No customers yet.
+ +
+
+ + + + + + + + + + + {% for customer in object_list %} + + + + + + + + {% empty %} + + {% endfor %} + +
NameAddressPhoneEmail
{{ customer.name }}{{ customer.address }}{{ customer.phone_number }}{{ customer.email_address }} + {% if user.is_superuser %} + Edit + {% endif %} + View +
No customers yet.
+
+
+ +{% include "dispatch/paginator.html" %} + {% endblock %} diff --git a/app/dispatch/templates/dispatch/drivers/list.html b/app/dispatch/templates/dispatch/drivers/list.html index 8b7508b..c87f99f 100644 --- a/app/dispatch/templates/dispatch/drivers/list.html +++ b/app/dispatch/templates/dispatch/drivers/list.html @@ -8,28 +8,36 @@

Drivers

- - - - - - - - - - {% for driver in object_list %} - - - - - - - {% empty %} - - {% endfor %} - -
First NameLast NameEmail
{{ driver.first_name }}{{ driver.last_name }}{{ driver.email }} - Edit - View -
No drivers yet.
+ +
+
+ + + + + + + + + + {% for driver in object_list %} + + + + + + + {% empty %} + + {% endfor %} + +
First NameLast NameEmail
{{ driver.first_name }}{{ driver.last_name }}{{ driver.email }} + Edit + View +
No drivers yet.
+
+
+ +{% include "dispatch/paginator.html" %} + {% endblock %} diff --git a/app/dispatch/templates/dispatch/invoice/detail-table.html b/app/dispatch/templates/dispatch/invoice/detail-table.html index 508ab31..d09ba76 100644 --- a/app/dispatch/templates/dispatch/invoice/detail-table.html +++ b/app/dispatch/templates/dispatch/invoice/detail-table.html @@ -4,9 +4,11 @@ Invoice #{{object.invoice_id}} + {% if object.paid %}

PAID

+ {% endif %}
diff --git a/app/dispatch/templates/dispatch/invoice/detail.html b/app/dispatch/templates/dispatch/invoice/detail.html index 850c427..c66e545 100644 --- a/app/dispatch/templates/dispatch/invoice/detail.html +++ b/app/dispatch/templates/dispatch/invoice/detail.html @@ -5,7 +5,7 @@ {% block content %}
-

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

+

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

diff --git a/app/dispatch/templates/dispatch/invoice/list.html b/app/dispatch/templates/dispatch/invoice/list.html index d98fb5a..d30c8d8 100644 --- a/app/dispatch/templates/dispatch/invoice/list.html +++ b/app/dispatch/templates/dispatch/invoice/list.html @@ -8,44 +8,67 @@

Invoices

- - + +
+
+
+ {% if request.GET.paid == '1' %} + Show Unpaid Invoices + {% else %} + Show Paid Invoices + {% endif %} +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + {% for invoice in object_list %} - - - - - - - - + + + + + + + + + - - - {% for invoice in object_list %} - - - - - - - - - - - {% empty %} - - - - - - - - - - - {% endfor %} + {% empty %} + + + + + + + + + + + {% endfor %} + + +
OwnerBill ToInvoice IDInvoice DateDue DateAmountPaid
UserOwnerBill ToInvoice IDInvoice DateDue DateAmount{{invoice.owner}}{{invoice.bill_to}}{{invoice.invoice_id}}{{invoice.invoice_date}}{{invoice.due_date}}{{invoice.total}}{{invoice.paid}}View
{{invoice.user}}{{invoice.owner}}{{invoice.bill_to}}{{invoice.invoice_id}}{{invoice.invoice_date}}{{invoice.due_date}}{{invoice.total}}View
No Invoices Found
No Invoices Found
+
+
+ +{% include "dispatch/paginator.html" %} + - - {% endblock %} diff --git a/app/dispatch/templates/dispatch/paginator.html b/app/dispatch/templates/dispatch/paginator.html new file mode 100644 index 0000000..82f5d3c --- /dev/null +++ b/app/dispatch/templates/dispatch/paginator.html @@ -0,0 +1,82 @@ +{% load custom_tags %} +{% echo "blue" as paginate_classes %} +{% if is_paginated %} +
+
+ +
+
+{% endif %} + + + diff --git a/app/dispatch/templatetags/custom_tags.py b/app/dispatch/templatetags/custom_tags.py index 7c5d3f0..60ad224 100644 --- a/app/dispatch/templatetags/custom_tags.py +++ b/app/dispatch/templatetags/custom_tags.py @@ -6,3 +6,6 @@ register = template.Library() def listForCommaString(string): return string.split(',') +@register.simple_tag +def echo(string): + return string diff --git a/app/dispatch/templatetags/dynamic_key.py b/app/dispatch/templatetags/dynamic_key.py index 47a7ef8..91a3a13 100644 --- a/app/dispatch/templatetags/dynamic_key.py +++ b/app/dispatch/templatetags/dynamic_key.py @@ -9,3 +9,9 @@ def keyvalue(dictionary, key): @register.filter def getindex(my_list, index): return my_list[index] + +@register.filter +def endRange(number, start): + # +1 because 1 based index instead of 0 + return range(start, number+1) + diff --git a/app/dispatch/views.py b/app/dispatch/views.py index b729922..62fc73f 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -81,6 +81,7 @@ class FilteredDeleteView(DeleteView): class DriverList(UserPassesTestMixin, ListView): template_name = "dispatch/drivers/list.html" model = User + paginate_by = 10 def test_func(self): return self.request.user.is_superuser @@ -214,6 +215,7 @@ class DriverUpdate(UserPassesTestMixin, UpdateView): class CustomerList(ListView): template_name = "dispatch/companies/list.html" model = Customer + paginate_by = 10 class CustomerCreate(UserPassesTestMixin, CreateView): @@ -535,7 +537,7 @@ class InvoiceEdit(UserPassesTestMixin, FilteredUpdateView): default_fields = [] superuser_fields = ['user', 'owner', 'bill_to', 'invoice_id', 'invoice_date', 'due_date', 'paid', - 'payment_identifer'] + 'payment_identifier'] def set_fields(self, user): if user.is_superuser: @@ -559,10 +561,19 @@ class InvoiceEdit(UserPassesTestMixin, FilteredUpdateView): class InvoiceList(FilteredListView): template_name = "dispatch/invoice/list.html" model = Invoice + paginate_by = 10 def get_queryset(self): # TODO: allow for a pagination base_qs = super(InvoiceList, self).get_queryset() + + # I don't really like this hack, but whatever + if self.request.GET.get('paid') == "1": + base_qs = base_qs.filter(paid=True) + else: + # Show the unpaid ones by default + base_qs = base_qs.filter(paid=False) + # Give me the newest ones first return base_qs.order_by('-pk') -- cgit v1.2.3