From 2555f2358071782105944157f74b6ab9ae34feb3 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Thu, 14 May 2020 14:32:10 +0200 Subject: [PATCH] Adding check for empty values and add a 60s cache. --- hypha/apply/funds/views.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hypha/apply/funds/views.py b/hypha/apply/funds/views.py index 44c6b5d12..5c45c7178 100644 --- a/hypha/apply/funds/views.py +++ b/hypha/apply/funds/views.py @@ -14,6 +14,7 @@ from django.utils.decorators import method_decorator from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from django.views import View +from django.views.decorators.cache import cache_page from django.views.generic import ( CreateView, DeleteView, @@ -1103,6 +1104,7 @@ class SubmissionDetailPDFView(SingleObjectMixin, View): ) +@method_decorator(cache_page(60), name='dispatch') @method_decorator(staff_required, name='dispatch') class SubmissionResultView(FilterView): template_name = 'funds/submissions_result.html' @@ -1150,6 +1152,8 @@ class SubmissionResultView(FilterView): def get_submission_values(self): import re values = [] + total = 0 + average = 0 for submission in self.object_list: try: value = submission.data('value') @@ -1170,4 +1174,8 @@ class SubmissionResultView(FilterView): finally: values.append(value) - return {'total': sum(values), 'average': round(mean(values))} + if values: + total = sum(values) + average = round(mean(values)) + + return {'total': total, 'average': average} -- GitLab