aboutsummaryrefslogtreecommitdiff
path: root/app/dispatch/views.py
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2018-02-04 12:31:29 -0500
committerMitch Riedstra <mitch@riedstra.us>2018-02-04 12:31:29 -0500
commit4f2acad7c8ff56bbc41893be3cfaceb9a8d2175f (patch)
treefa9d7246d3e908f272f0c31f8cdb2a57fb84e9d5 /app/dispatch/views.py
parent7c07b1cd3caaf7d7cc16048cfe1bf230f6123ee4 (diff)
downloaddispatch-tracker-4f2acad7c8ff56bbc41893be3cfaceb9a8d2175f.tar.gz
dispatch-tracker-4f2acad7c8ff56bbc41893be3cfaceb9a8d2175f.tar.xz
Fix issue with averages not being displayed due to an invoice existing.
Also fixed filename parsing. Modified django's function and placed it in dispatch/misc.py
Diffstat (limited to 'app/dispatch/views.py')
-rw-r--r--app/dispatch/views.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/app/dispatch/views.py b/app/dispatch/views.py
index b16e551..1042d67 100644
--- a/app/dispatch/views.py
+++ b/app/dispatch/views.py
@@ -18,7 +18,8 @@ from dispatch.forms import AddPaperworkForm, InviteForm
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import UserPassesTestMixin
# from django.http import HttpResponseRedirect
-from .misc import get_week_dates, split_loads_by_day, zip_attachments_for_loads
+from .misc import get_week_dates, split_loads_by_day, zip_attachments_for_loads, \
+ get_valid_filename
import re, os, tempfile, datetime
User = get_user_model()
@@ -156,16 +157,16 @@ class DriverSummary(UserPassesTestMixin, LoadDateSort):
loads_by_date = context['loads']
if len(context['related_invoices']) >= 1:
context['can_invoice'] = False
- else:
- for d in loads_by_date:
- # Iterate over the array for the given date
- for l in loads_by_date[d]:
- stats['count'] += 1
- stats['sum'] += l.amount
- # Any load not up to par will break the chain
- if not l.can_invoice():
- context['can_invoice'] = False
+ for d in loads_by_date:
+ # Iterate over the array for the given date
+ for l in loads_by_date[d]:
+ stats['count'] += 1
+ stats['sum'] += l.amount
+
+ # Any load not up to par will break the chain
+ if not l.can_invoice():
+ context['can_invoice'] = False
if stats['sum'] is not 0 and stats['count'] is not 0:
stats['average'] = stats['sum']/stats['count']
@@ -472,14 +473,14 @@ def PaperworkDownload(request, load_id, pk):
print(e)
ext = '.pdf'
- desc = load.description.replace('"', '')
+ filename = get_valid_filename(load.description + ext)
response = HttpResponse(
fh.read(),
content_type='application/force-download')
response['Content-Disposition'] = \
- 'attachment; filename="{}"'.format(smart_str(desc + ext))
+ 'attachment; filename="{}"'.format(smart_str(filename))
response['X-Sendfile'] = smart_str(paperwork.document.path)
return response
except Exception as e: