From 4f2acad7c8ff56bbc41893be3cfaceb9a8d2175f Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Sun, 4 Feb 2018 12:31:29 -0500 Subject: 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 --- app/dispatch/views.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'app/dispatch/views.py') 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: -- cgit v1.2.3