From 315e44adb15b372ee644a44e78bc6c4447b15960 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Thu, 1 Aug 2019 16:28:52 +0200 Subject: [PATCH] Fixed safari download bug --- counter/views.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/counter/views.py b/counter/views.py index 630e5cd..aad16ab 100644 --- a/counter/views.py +++ b/counter/views.py @@ -28,8 +28,6 @@ def tofirstdayinisoweek(year, week): return ret def index(request): - template = loader.get_template('index.html') - if request.user.is_authenticated: now = datetime.today() @@ -57,19 +55,18 @@ def index(request): now + timedelta(days=6-weekday))) \ .aggregate(s=Sum('count')) - return HttpResponse(template.render({ + context = { 'yearArrows': yearArrows, 'monthArrows': 0 if monthArrows['s'] is None else monthArrows['s'], 'weekArrows': 0 if weekArrows['s'] is None else weekArrows['s'], 'diffTarget': diff_target - }, request)) + } + return render(request, 'index.html', context) else: - return HttpResponse(template.render({}), request) + return render(request, 'index.html', {}) @login_required def count_stats(request): - template = loader.get_template('stats.html') - # Group counts by week (extract isoyear works only on psql and DB2) weeklyArrows = ArrowCount.objects \ .filter(user = request.user) \ @@ -83,9 +80,9 @@ def count_stats(request): w['weekStarts'] = tofirstdayinisoweek(w['isoyear'], w['week']) w['weekEnds'] = w['weekStarts'] + timedelta(days=6) - return HttpResponse(template.render({ + return render(request, 'counter/stats.html', { 'weeklyArrows': json.dumps(list(weeklyArrows), cls=DjangoJSONEncoder) - }, request)) + }) @login_required def arrow_count_export(request): @@ -125,12 +122,11 @@ def arrow_count_list(request): pageCount = math.ceil(ArrowCount.objects.filter(user = request.user).count() / \ settings.ITEMS_PER_PAGE) - template = loader.get_template('counter/list.html') - return HttpResponse(template.render({ + return render(request, 'counter/list.html', { 'counts': counts, 'pageCount': pageCount, 'page': page - }, request)) + }) class NewArrowCount(generic.CreateView): form_class = ArrowCountForm