Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Stub function to output PDFs

Roland Geider096d59528b11
diff --git a/manager/templates/workout/view.html b/manager/templates/workout/view.html
index f73ea1afa..262f2e290 100644
--- a/manager/templates/workout/view.html
+++ b/manager/templates/workout/view.html
@@ -108,6 +108,6 @@
</ol>
<h3>{% trans "Options" %}</h3>
-<a href="">{% trans "Download as PDF" %}</a>
+<a href="/workout/{{ workout.id }}/pdf">{% trans "Download as PDF" %}</a>
{% endblock %}
diff --git a/manager/urls.py b/manager/urls.py
index 821dec86e..73397d4d8 100644
--- a/manager/urls.py
+++ b/manager/urls.py
@@ -6,6 +6,7 @@ urlpatterns = patterns('manager.views',
url(r'^logout$', 'logout'),
url(r'^workout/add$', 'add'),
+ url(r'^workout/(?P<id>\d+)/pdf/$', 'pdf_workout'),
url(r'^workout/(?P<id>\d+)/view/$', 'view_workout'),
url(r'^workout/(?P<id>\d+)/delete/$', 'delete_workout'),
url(r'^workout/(?P<id>\d+)/edit/day/(?P<day_id>\d*)$', 'edit_day'),
diff --git a/manager/views.py b/manager/views.py
index 6dc35cf72..cfb2d7850 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -32,6 +32,7 @@ from manager.models import Day
from manager.models import Set
from manager.models import Setting
+from reportlab.pdfgen import canvas
logger = logging.getLogger('workout_manager.custom')
@@ -69,9 +70,32 @@ def view_workout(request, id):
workout = get_object_or_404(TrainingSchedule, pk=id)
template_data['workout'] = workout
- #days = workout.day_set.all()
return render_to_response('workout/view.html', template_data)
+
+def pdf_workout(request, id):
+ """Generates a PDF with the contents of the given workout
+ """
+
+ #Load the workout
+ workout = get_object_or_404(TrainingSchedule, pk=id)
+
+ # Create the HttpResponse object with the appropriate PDF headers.
+ response = HttpResponse(mimetype='application/pdf')
+ response['Content-Disposition'] = 'attachment; filename=workout.pdf'
+ # Create the PDF object, using the response object as its "file."
+ p = canvas.Canvas(response)
+
+ # Draw things on the PDF. Here's where the PDF generation happens.
+ # See the ReportLab documentation for the full list of functionality.
+ p.drawString(100, 100, "Hello world.")
+
+ # Close the PDF object cleanly, and we're done.
+ p.showPage()
+ p.save()
+ return response
+
+
def add(request):
"""Add a new workout and redirect to its page
"""