aboutsummaryrefslogtreecommitdiff
path: root/app/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'app/dispatch')
-rw-r--r--app/dispatch/management/commands/insert_fake_data.py2
-rw-r--r--app/dispatch/migrations/0004_auto_20171110_1400.py20
-rw-r--r--app/dispatch/models.py2
-rw-r--r--app/dispatch/templates/dispatch/companies/list.html64
-rw-r--r--app/dispatch/templates/dispatch/drivers/list.html56
-rw-r--r--app/dispatch/templates/dispatch/invoice/detail-table.html2
-rw-r--r--app/dispatch/templates/dispatch/invoice/detail.html2
-rw-r--r--app/dispatch/templates/dispatch/invoice/list.html97
-rw-r--r--app/dispatch/templates/dispatch/paginator.html82
-rw-r--r--app/dispatch/templatetags/custom_tags.py3
-rw-r--r--app/dispatch/templatetags/dynamic_key.py6
-rw-r--r--app/dispatch/views.py13
12 files changed, 255 insertions, 94 deletions
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 @@
<a href="{% url 'customer_new' %}" class="btn green">Add Customer</a>
</div>
</div>
-<table class="striped bordered">
- <thead>
- <tr>
- <th>Name</th>
- <th>Address</th>
- <th>Phone</th>
- <th>Email</th>
- </tr>
- </thead>
- <tbody>
- {% for customer in object_list %}
- <tr>
- <td>{{ customer.name }}</td>
- <td>{{ customer.address }}</td>
- <td>{{ customer.phone_number }}</td>
- <td>{{ customer.email_address }}</td>
- <td class="right-align">
- {% if user.is_superuser %}
- <a href="{% url 'customer_edit' customer.id %}" class="btn orange">Edit</a>
- {% endif %}
- <a href="{% url 'customer_detail' customer.id %}" class="btn blue">View</a>
- </td>
- </tr>
- {% empty %}
- <tr><td colspan="4">No customers yet.</td></tr>
- {% endfor %}
- </tbody>
-</table>
+
+<div class="row">
+<div class="col s12">
+ <table class="striped bordered">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Address</th>
+ <th>Phone</th>
+ <th>Email</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for customer in object_list %}
+ <tr>
+ <td>{{ customer.name }}</td>
+ <td>{{ customer.address }}</td>
+ <td>{{ customer.phone_number }}</td>
+ <td>{{ customer.email_address }}</td>
+ <td class="right-align">
+ {% if user.is_superuser %}
+ <a href="{% url 'customer_edit' customer.id %}" class="btn orange">Edit</a>
+ {% endif %}
+ <a href="{% url 'customer_detail' customer.id %}" class="btn blue">View</a>
+ </td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="4">No customers yet.</td></tr>
+ {% endfor %}
+ </tbody>
+ </table>
+</div>
+</div>
+
+{% 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 @@
<h1>Drivers</h1>
</div>
</div>
-<table class="striped bordered">
- <thead>
- <tr>
- <th>First Name</th>
- <th>Last Name</th>
- <th>Email</th>
- </tr>
- </thead>
- <tbody>
- {% for driver in object_list %}
- <tr>
- <td>{{ driver.first_name }}</td>
- <td>{{ driver.last_name }}</td>
- <td>{{ driver.email }}</td>
- <td class="right-align">
- <a href="{% url 'driver_details' driver.id %}" class="btn orange">Edit</a>
- <a href="{% url 'driver_summary' driver.id %}" class="btn blue">View</a>
- </td>
- </tr>
- {% empty %}
- <tr><td colspan="4">No drivers yet.</td></tr>
- {% endfor %}
- </tbody>
-</table>
+
+<div class="row">
+<div class="col s12">
+ <table class="striped bordered">
+ <thead>
+ <tr>
+ <th>First Name</th>
+ <th>Last Name</th>
+ <th>Email</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for driver in object_list %}
+ <tr>
+ <td>{{ driver.first_name }}</td>
+ <td>{{ driver.last_name }}</td>
+ <td>{{ driver.email }}</td>
+ <td class="right-align">
+ <a href="{% url 'driver_details' driver.id %}" class="btn orange">Edit</a>
+ <a href="{% url 'driver_summary' driver.id %}" class="btn blue">View</a>
+ </td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="4">No drivers yet.</td></tr>
+ {% endfor %}
+ </tbody>
+ </table>
+</div>
+</div>
+
+{% 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}}
</h4>
</div>
+ {% if object.paid %}
<div class="col s6 right-align">
<h4>PAID</h4>
</div>
+ {% endif %}
</div>
<div class="row">
<div class="col s6">
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 %}
<div class="row hide-print">
<div class="col s12 m6">
- <h1>Invoice for {{object.invoice_date}} by {{object.owner}}</h1>
+ <h1>Invoice for {{object.invoice_date}} by <a href="{% url 'driver_summary' object.owner.pk %}">{{object.owner}}</a></h1>
</div>
<div class="col s12 m6">
<div class="right-align">
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 @@
<h1>Invoices</h1>
</div>
</div>
-<table class="striped bordered">
- <thead>
+
+<div class="row">
+ <div class="col s12">
+ <div class="right-align">
+ {% if request.GET.paid == '1' %}
+ <a class="btn orange" href="?paid=0">Show Unpaid Invoices</a>
+ {% else %}
+ <a class="btn green" href="?paid=1">Show Paid Invoices</a>
+ {% endif %}
+ </div>
+ </div>
+</div>
+
+<div class="row">
+<div class="col s12">
+ <table class="striped bordered">
+ <thead>
+ <tr>
+ <!-- <th>User</th> -->
+ <th>Owner</th>
+ <th>Bill To</th>
+ <th>Invoice ID</th>
+ <th>Invoice Date</th>
+ <th>Due Date</th>
+ <th>Amount</th>
+ <th>Paid</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for invoice in object_list %}
<tr>
- <th>User</th>
- <th>Owner</th>
- <th>Bill To</th>
- <th>Invoice ID</th>
- <th>Invoice Date</th>
- <th>Due Date</th>
- <th>Amount</th>
- <th></th>
+ <!-- <td>{{invoice.user}}</td> -->
+ <td>{{invoice.owner}}</td>
+ <td>{{invoice.bill_to}}</td>
+ <td>{{invoice.invoice_id}}</td>
+ <td>{{invoice.invoice_date}}</td>
+ <td>{{invoice.due_date}}</td>
+ <td>{{invoice.total}}</td>
+ <td>{{invoice.paid}}</td>
+ <td><a class="btn green" href="{% url 'invoice_detail' invoice.pk %}">View</a></td>
</tr>
- </thead>
- <tbody>
- {% for invoice in object_list %}
- <tr>
- <td>{{invoice.user}}</td>
- <td>{{invoice.owner}}</td>
- <td>{{invoice.bill_to}}</td>
- <td>{{invoice.invoice_id}}</td>
- <td>{{invoice.invoice_date}}</td>
- <td>{{invoice.due_date}}</td>
- <td>{{invoice.total}}</td>
- <td><a class="btn green" href="{% url 'invoice_detail' invoice.pk %}">View</a></td>
- </tr>
- {% empty %}
- <tr>
- <td>No Invoices Found</td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- </tr>
- {% endfor %}
+ {% empty %}
+ <tr>
+ <td>No Invoices Found</td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ {% endfor %}
+
+ </tbody>
+ </table>
+</div>
+</div>
+
+{% include "dispatch/paginator.html" %}
+
- </tbody>
-</table>
{% 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 %}
+<div class="row">
+ <div class="col s12 ">
+ <ul class="pagination">
+ {% if page_obj.has_previous %}
+ <li>
+ <a href="#" onClick="insertParam('page', {{page_obj.previous_page_number}})">
+ <i class="material-icons">chevron_left</i>
+ </a>
+ </li>
+ {% else %}
+ <li class="disabled">
+ <a href="#">
+ <i class="material-icons">chevron_left</i>
+ </a>
+ </li>
+ {% endif %}
+ {% load dynamic_key %}
+ {% for number in page_obj.paginator.num_pages|endRange:1 %}
+
+ {% if page_obj.number == number %}
+ <li class="active {{paginate_classes}}">
+ <a href="#" onClick="insertParam('page', {{number}})">{{number}}</a>
+ </li>
+ {% else %}
+ <li class="waves-effect">
+ <a onClick="insertParam('page', {{number}})">{{number}}</a>
+ </li>
+ {% endif %}
+
+ {% endfor %}
+
+ {% if page_obj.has_next %}
+ <li>
+ <a href="#" onClick="insertParam('page', {{page_obj.next_page_number}})">
+ <i class="material-icons">chevron_right</i>
+ </a>
+ </li>
+ {% else %}
+ <li class="disabled">
+ <a href="#">
+ <i class="material-icons">chevron_right</i>
+ </a>
+ </li>
+ {% endif %}
+ </ul>
+ </div>
+</div>
+{% endif %}
+
+
+ <script>
+
+// Shamelessly stolen from here:
+// https://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript
+function insertParam(key, value)
+{
+ key = encodeURI(key); value = encodeURI(value);
+
+ var kvp = document.location.search.substr(1).split('&');
+
+ var i=kvp.length; var x; while(i--)
+ {
+ x = kvp[i].split('=');
+
+ if (x[0]==key)
+ {
+ x[1] = value;
+ kvp[i] = x.join('=');
+ break;
+ }
+ }
+
+ if(i<0) {kvp[kvp.length] = [key,value].join('=');}
+
+ //this will reload the page, it's likely better to store this until finished
+ document.location.search = kvp.join('&');
+}
+
+ </script>
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')