aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <Mitch@riedstra.us>2017-10-30 17:06:23 -0400
committerMitch Riedstra <Mitch@riedstra.us>2017-10-30 17:06:23 -0400
commitec9428fdf76b5d70d0f3bcdff3b85e3a83d5f3d5 (patch)
tree6ae862656a003d683f537d078599f98bbfa2675d
parent1949503b55ea622d7c466e4b433f4d90e7eff125 (diff)
downloaddispatch-tracker-ec9428fdf76b5d70d0f3bcdff3b85e3a83d5f3d5.tar.gz
dispatch-tracker-ec9428fdf76b5d70d0f3bcdff3b85e3a83d5f3d5.tar.xz
Proper redirect on edit for users. Delete for loads, warning on delete. Invoice view ordered by PK desc
-rw-r--r--README.md6
-rw-r--r--app/dispatch/models.py2
-rw-r--r--app/dispatch/monkey_patch.py7
-rw-r--r--app/dispatch/static/base.js7
-rw-r--r--app/dispatch/templates/dispatch/invoice/detail.html26
-rw-r--r--app/dispatch/templates/dispatch/loads/delete.html0
-rw-r--r--app/dispatch/templates/dispatch/loads/detail.html54
-rw-r--r--app/dispatch/views.py13
8 files changed, 74 insertions, 41 deletions
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 %}
<div class="row hide-print">
- <div class="col s12">
+ <div class="col s12 m6">
<h1>Invoice for {{object.invoice_date}} by {{object.owner}}</h1>
</div>
+ <div class="col s12 m6">
+ <div class="right-align">
+ <form action="{% url 'invoice_delete' object.pk %}" id="invoice_delete" method="POST">
+ <!-- <input type="submit" class="btn red" value="Delete" /> -->
+ {% csrf_token %}
+ <a class="btn red" href="#" onClick="warn_submit('Are you sure?', '#invoice_delete')">Delete</a>
+ <a class="btn green" href="#" onClick="window.print()">Print</a>
+ </form>
+ </div>
+ </div>
</div>
<div style="padding-top:30px;" class="hide-print"></div>
@@ -22,7 +32,7 @@
<form action="{% url 'invoice_delete' object.pk %}" id="invoice_delete" method="POST">
<!-- <input type="submit" class="btn red" value="Delete" /> -->
{% csrf_token %}
- <a class="btn red" href="#" onClick="delete_load('Are you sure?', '#invoice_delete')">Delete</a>
+ <a class="btn red" href="#" onClick="warn_submit('Are you sure?', '#invoice_delete')">Delete</a>
<a class="btn green" href="#" onClick="window.print()">Print</a>
</form>
</div>
@@ -39,16 +49,4 @@
<link rel="stylesheet" href="/static/print.css" media="print">
<link rel="stylesheet" href="/static/materialize/css/materialize.min.css" media="print">
-<script>
-
-function delete_load(text, form) {
- if(confirm(text)) {
- form = document.querySelector(form)
- form.submit()
- // window.location.href = "{% url 'invoice_delete' object.pk%}";
- }
-}
-
-</script>
-
{%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
--- /dev/null
+++ b/app/dispatch/templates/dispatch/loads/delete.html
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 %}
<div class="row">
- <div class="col s12 m6">
+ <div class="col s6">
<h1>Details for {{object.description}}</h1>
</div>
+ <div class="col s6">
+ <div class="right-align">
+ <form action="{% url 'load_delete' object.id %}" id="load_delete" method="POST">
+ {% csrf_token %}
+ <a class="btn red" href="#" onClick="warn_submit('Are you sure?\nThis cannot be undone!', '#load_delete')">Delete</a>
+ <a class="btn blue" href="{% url 'load_edit' object.id %}">Edit</a>
+ </form>
+ </div>
+ </div>
</div>
<div class="row">
<div class="col s12">
- <div class="right-align">
- <a class="btn blue" href="{%url 'load_edit' object.id %}">Edit</a>
- </div>
<table class="bordered">
<tr>
<th>Date</th>
@@ -51,36 +57,45 @@
</table>
</div>
+ </div>
+
<div class="row">
- <div class="col s12" style="padding-top: 50px;">
+ <div class="col s6">
<h4>Attached Files:</h4>
-
- <div class="right-align">
- <a class="btn blue" href="{% url 'paperwork_upload' object.id %}">Upload</a>
+ </div>
+ <div class="col s6">
+ <h4></h4>
+ <div class="right-align">
+ <a class="btn blue" href="{% url 'paperwork_upload' object.id %}">Upload</a>
+ </div>
</div>
+ </div>
+
- <table>
+ <div class="row">
+ <div class="col s12">
+ <table>
<thead>
<th>Description: </th>
<th></th>
</thead>
<tbody>
{% for p in paperwork_list %}
- <tr>
- <td>{{p.description}}</td>
- <td class="right-align">
- <a class="btn red" href="{% url 'paperwork_delete' object.id p.id %}">Delete</a>
- <!-- <a class="btn green" target="_blank" href="{{p.document.url}}">Download</a> -->
- <a class="btn green" href="{% url 'paperwork_download' load.id p.id %}">Download</a>
- </td>
- </tr>
+ <tr>
+ <td>{{p.description}}</td>
+ <td class="right-align">
+ <a class="btn red" href="{% url 'paperwork_delete' object.id p.id %}">Delete</a>
+ <!-- <a class="btn green" target="_blank" href="{{p.document.url}}">Download</a> -->
+ <a class="btn green" href="{% url 'paperwork_download' load.id p.id %}">Download</a>
+ </td>
+ </tr>
{% endfor %}
</tbody>
- </table>
+ </table>
+ </div>
</div>
- </div>
<div class="row">
@@ -118,7 +133,6 @@
</ul>
</div>
</div>
- </div>
</div>
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"