Self hosted FLOSS fitness/workout, nutrition and weight tracker
Start working on flexible PDFs
Roland Geider105c63197767
diff --git a/wger/manager/helpers.py b/wger/manager/helpers.pyindex 364484dfd..c7eeb9365 100644--- a/wger/manager/helpers.py+++ b/wger/manager/helpers.py@@ -23,7 +23,9 @@ from reportlab.lib.units import cmfrom reportlab.platypus import (Paragraph,Table,- KeepTogether+ KeepTogether,+ ListFlowable,+ ListItem)from django.core.urlresolvers import reverse@@ -33,7 +35,7 @@ from wger.utils.helpers import normalize_decimalfrom wger.utils.pdf import styleSheet-def render_workout_day(day, nr_of_weeks):+def render_workout_day(day, nr_of_weeks, comments=False):'''Render a table with reportlab with the contents of the training day'''@@ -84,8 +86,21 @@ def render_workout_day(day, nr_of_weeks):else:setting_out = Paragraph(exercise['setting_text'], styleSheet["Small"])+ # Append a list of the exercise comments+ if comments:+ item_list = [ListItem(Paragraph(i, style=styleSheet["ExerciseComments"]))+ for i in exercise['comment_list']]+ exercise_content = [Paragraph(exercise['obj'].name, styleSheet["Small"]),+ ListFlowable(item_list,+ bulletType='bullet',+ bulletFontSize=5,+ start='square')]+ # Only show the exercise name+ else:+ exercise_content = Paragraph(exercise['obj'].name, styleSheet["Small"])+data.append([set_count,- Paragraph(exercise['obj'].name, styleSheet["Small"]),+ exercise_content,setting_out]+ [''] * nr_of_weeks)set_count += 1diff --git a/wger/manager/urls.py b/wger/manager/urls.pyindex d8328ce52..e5932396c 100644--- a/wger/manager/urls.py+++ b/wger/manager/urls.py@@ -88,6 +88,9 @@ patterns_workout = [url(r'^(?P<pk>\d+)/ical$',ical.export,name='ical'),+ url(r'^(?P<id>\d+)/pdf/log/(?P<images>[01]+)/(?P<comments>[01]+)/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$',+ pdf.workout_log,+ name='pdf-log'),url(r'^(?P<id>\d+)/pdf/log/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$',pdf.workout_log,name='pdf-log'),diff --git a/wger/manager/views/pdf.py b/wger/manager/views/pdf.pyindex f5edd6047..78e30d90c 100644--- a/wger/manager/views/pdf.py+++ b/wger/manager/views/pdf.py@@ -43,7 +43,7 @@ from wger import get_versionlogger = logging.getLogger(__name__)-def workout_log(request, id, uidb64=None, token=None):+def workout_log(request, id, images=False, comments=False, uidb64=None, token=None):'''Generates a PDF with the contents of the given workout@@ -51,6 +51,8 @@ def workout_log(request, id, uidb64=None, token=None):* http://www.blog.pythonlibrary.org/2010/09/21/reportlab* http://www.reportlab.com/apis/reportlab/dev/platypus.html'''+ comments = bool(int(comments))+ images = bool(int(images))# Load the workoutif uidb64 is not None and token is not None:@@ -90,7 +92,7 @@ def workout_log(request, id, uidb64=None, token=None):# Iterate through the Workout and render the training daysfor day in workout.canonical_representation['day_list']:- elements.append(render_workout_day(day, nr_of_weeks=7))+ elements.append(render_workout_day(day, nr_of_weeks=7, comments=comments))elements.append(Spacer(10 * cm, 0.5 * cm))# Footer, date and info@@ -101,7 +103,7 @@ def workout_log(request, id, uidb64=None, token=None):doc.build(elements)# Create the HttpResponse object with the appropriate PDF headers.- response['Content-Disposition'] = 'attachment; filename=Workout-{0}-log.pdf'.format(id)+ # response['Content-Disposition'] = 'attachment; filename=Workout-{0}-log.pdf'.format(id)response['Content-Length'] = len(response.content)return responsediff --git a/wger/utils/pdf.py b/wger/utils/pdf.pyindex dbff0079c..c9af600fd 100644--- a/wger/utils/pdf.py+++ b/wger/utils/pdf.py@@ -118,6 +118,12 @@ styleSheet.add(ParagraphStyle(fontSize=8,name='Small',))+styleSheet.add(ParagraphStyle(+ parent=styleSheet['Normal'],+ fontSize=8,+ textColor='gray',+ name='ExerciseComments',+ ))styleSheet.add(ParagraphStyle(parent=styleSheet['Normal'],name='HeaderBold',