Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Send the Content-Length response header for generated files

Roland Geider645d0289a8ed
diff --git a/wger/manager/pdf.py b/wger/manager/pdf.py
index c63c8696b..2917c20bf 100644
--- a/wger/manager/pdf.py
+++ b/wger/manager/pdf.py
@@ -45,12 +45,11 @@ def workout_log(request, id):
* http://www.reportlab.com/apis/reportlab/dev/platypus.html
'''
- #Load the workout
- workout = get_object_or_404(Workout, pk=id, user=request.user)
-
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
- response['Content-Disposition'] = 'attachment; filename=Workout-{0}.pdf'.format(id)
+
+ #Load the workout
+ workout = get_object_or_404(Workout, pk=id, user=request.user)
# Create the PDF object, using the response object as its "file."
doc = SimpleDocTemplate(response,
@@ -274,4 +273,7 @@ def workout_log(request, id):
# write the document and send the response to the browser
doc.build(elements)
+ # Create the HttpResponse object with the appropriate PDF headers.
+ response['Content-Disposition'] = 'attachment; filename=Workout-{0}.pdf'.format(id)
+ response['Content-Length'] = len(response.content)
return response
diff --git a/wger/manager/templates/workout/view.html b/wger/manager/templates/workout/view.html
index 22cc8f2e8..7628e75cf 100644
--- a/wger/manager/templates/workout/view.html
+++ b/wger/manager/templates/workout/view.html
@@ -123,8 +123,7 @@ $(document).ready(function() {
<h3>{% trans "Options" %}</h3>
<p>
-<a href="{% url 'wger.manager.pdf.workout_log' workout.id %}"
- target="_blank">
+<a href="{% url 'wger.manager.pdf.workout_log' workout.id %}">
<img src="{% static 'images/icons/save.svg' %}"
width="32"
height="32"
diff --git a/wger/manager/views/ical.py b/wger/manager/views/ical.py
index 7921de9a0..483c1a351 100644
--- a/wger/manager/views/ical.py
+++ b/wger/manager/views/ical.py
@@ -122,6 +122,7 @@ def export(request, pk):
response['Content-Disposition'] = \
'attachment; filename=Calendar-workout-{0}.ics'.format(workout.pk)
response.write(calendar.to_ical())
+ response['Content-Length'] = len(response.content)
return response
@@ -148,4 +149,5 @@ def export_schedule(request, pk):
response['Content-Disposition'] = \
'attachment; filename=Calendar-schedule-{0}.ics'.format(schedule.pk)
response.write(calendar.to_ical())
+ response['Content-Length'] = len(response.content)
return response
diff --git a/wger/weight/views.py b/wger/weight/views.py
index 749f3291d..ac9ff49ec 100644
--- a/wger/weight/views.py
+++ b/wger/weight/views.py
@@ -124,7 +124,6 @@ def export_csv(request):
# Prepare the response headers
filename = u"{0}-{1}".format('weightdata', request.user.username)
response = HttpResponse(mimetype='text/csv')
- response['Content-Disposition'] = 'attachment; filename=%s.csv' % filename
# Convert all weight data to CSV
writer = csv.writer(response)
@@ -136,6 +135,8 @@ def export_csv(request):
writer.writerow([entry.weight, entry.creation_date])
# Send the data to the browser
+ response['Content-Disposition'] = 'attachment; filename=%s.csv' % filename
+ response['Content-Length'] = len(response.content)
return response