Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove unused parameters for exercise PDF
Roland Geiderf2f5406e8392
diff --git a/wger/manager/helpers.py b/wger/manager/helpers.pyindex 209e1f8d4..ba1fde058 100644--- a/wger/manager/helpers.py+++ b/wger/manager/helpers.py@@ -46,8 +46,6 @@ from wger.utils.pdf import (def render_workout_day(day_data: WorkoutDayData,nr_of_weeks=7,- images=False,- comments=False,only_table=False,):"""@@ -78,28 +76,23 @@ def render_workout_day(set_count = 1day_markers.append(len(data))- data.append(- [- Paragraph(- f'<para align="center">{day_data.day.name if not day_data.day.is_rest else _("Rest day")}</para>',- styleSheet['SubHeader'],- ),- # Paragraph(- # f'<para align="center">{day_data.day.description}</para>',- # styleSheet['SubHeader'],- # )- ]+ data.append([+ Paragraph(+ f'<para align="center">{_("Rest day") if day_data.day.is_rest else day_data.day.name}</para>',+ styleSheet['SubHeader'],+ )])# Note: the _('Date') will be on the 3rd cell, but since we make a span# over 3 cells, the value has to be on the 1st one- data.append([_('Date') + ' ', '', ''] + [''] * nr_of_weeks)+ data.append(['' if only_table else _('Date') + ' ', '', ''] + [''] * nr_of_weeks)data.append([_('Nr.'), _('Exercise'), _('Reps')] + [_('Weight')] * nr_of_weeks)# Setsexercise_start = len(data)slot_count = 0for slot in day_data.slots_display_mode:+slot_count += 1group_exercise_marker[slot_count] = {'start': len(data), 'end': len(data)}@@ -113,24 +106,24 @@ def render_workout_day(slot_entries_out = [Paragraph(slot_set.text_repr, styleSheet['Small'], bulletText='')]# Add the exercise's main image- image = Paragraph('', styleSheet['Small'])- if images:- if exercise.main_image:- # Make the images somewhat larger when printing only the workout and not- # also the columns for weight logs- if only_table:- image_size = 2- else:- image_size = 1.5-- image = Image(exercise.main_image.image)- image.drawHeight = image_size * cm * image.drawHeight / image.drawWidth- image.drawWidth = image_size * cm+ # image = Paragraph('', styleSheet['Small'])+ # if images:+ # if exercise.main_image:+ # # Make the images somewhat larger when printing only the workout and not+ # # also the columns for weight logs+ # if only_table:+ # image_size = 2+ # else:+ # image_size = 1.5+ #+ # image = Image(exercise.main_image.image)+ # image.drawHeight = image_size * cm * image.drawHeight / image.drawWidth+ # image.drawWidth = image_size * cm# Put the name and images and comments togetherexercise_content = [Paragraph(exercise.get_translation().name, styleSheet['Small']),- image,+ # image,]data.append([f'#{set_count}', exercise_content, slot_entries_out] + [''] * nr_of_weeks)diff --git a/wger/manager/tests/test_pdf.py b/wger/manager/tests/test_pdf.pyindex 999ff8053..1a8e274fa 100644--- a/wger/manager/tests/test_pdf.py+++ b/wger/manager/tests/test_pdf.py@@ -37,10 +37,6 @@ class RoutinePdfLogExportTestCase(WgerTestCase):else:self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')- self.assertEqual(- response['Content-Disposition'],- 'attachment; filename=Routine-3-log.pdf',- )# Approximate size onlyself.assertGreater(int(response['Content-Length']), 38000)@@ -60,55 +56,6 @@ class RoutinePdfLogExportTestCase(WgerTestCase):else:self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')- self.assertEqual(- response['Content-Disposition'],- 'attachment; filename=Routine-3-log.pdf',- )-- # Approximate size only- self.assertGreater(int(response['Content-Length']), 38000)- self.assertLess(int(response['Content-Length']), 42000)-- def export_pdf_with_images(self, fail=False):- """- Helper function to test exporting a workout as a pdf, with exercise images- """-- response = self.client.get(- reverse('manager:routine:pdf-log', kwargs={'id': 3, 'images': 1})- )-- if fail:- self.assertIn(response.status_code, (403, 404, 302))- else:- self.assertEqual(response.status_code, 200)- self.assertEqual(response['Content-Type'], 'application/pdf')- self.assertEqual(- response['Content-Disposition'],- 'attachment; filename=Routine-3-log.pdf',- )-- # Approximate size only- self.assertGreater(int(response['Content-Length']), 38000)- self.assertLess(int(response['Content-Length']), 42000)-- def export_pdf_with_images_and_comments(self, fail=False):- """- Helper function to test exporting a workout as a pdf, with images and comments- """-- response = self.client.get(- reverse('manager:routine:pdf-log', kwargs={'id': 3, 'images': 1, 'comments': 1})- )-- if fail:- self.assertIn(response.status_code, (403, 404, 302))- else:- self.assertEqual(response.status_code, 200)- self.assertEqual(response['Content-Type'], 'application/pdf')- self.assertEqual(- response['Content-Disposition'], 'attachment; filename=Routine-3-log.pdf'- )# Approximate size onlyself.assertGreater(int(response['Content-Length']), 38000)@@ -155,10 +102,6 @@ class RoutinePdfTableExportTestCase(WgerTestCase):else:self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')- self.assertEqual(- response['Content-Disposition'],- 'attachment; filename=Routine-3-table.pdf',- )# Approximate size onlyself.assertGreater(int(response['Content-Length']), 38000)diff --git a/wger/manager/urls.py b/wger/manager/urls.pyindex e78af3e85..f6ac93186 100644--- a/wger/manager/urls.py+++ b/wger/manager/urls.py@@ -36,7 +36,6 @@ from wger.manager.views import (workout_session,)-# sub patterns for workout logspatterns_log = [path(diff --git a/wger/manager/views/pdf.py b/wger/manager/views/pdf.pyindex 433c4e0e0..7775c32da 100644--- a/wger/manager/views/pdf.py+++ b/wger/manager/views/pdf.py@@ -49,12 +49,10 @@ from wger.utils.pdf import (logger = logging.getLogger(__name__)-def workout_log(request, pk: int, images=False):+def workout_log(request, pk: int):"""Generates a PDF with the contents of the given routine"""- comments = False- images = bool(int(images))# Load the workoutif request.user.is_anonymous:@@ -100,7 +98,7 @@ def workout_log(request, pk: int, images=False):for day_data in routine.data_for_iteration():if day_data.day is None:continue- elements.append(render_workout_day(day_data, images=images, comments=comments))+ elements.append(render_workout_day(day_data))elements.append(Spacer(10 * cm, 0.5 * cm))# Footer, date and info@@ -111,12 +109,11 @@ def workout_log(request, pk: int, images=False):doc.build(elements)# Create the HttpResponse object with the appropriate PDF headers.- response['Content-Disposition'] = f'attachment; filename=Routine-{pk}-log.pdf'response['Content-Length'] = len(response.content)return response-def workout_view(request, pk, images: bool = False):+def workout_view(request, pk):"""Generates a PDF with the contents of the workout, without table for logs"""@@ -126,8 +123,6 @@ def workout_view(request, pk, images: bool = False):* http://www.blog.pythonlibrary.org/2010/09/21/reportlab* http://www.reportlab.com/apis/reportlab/dev/platypus.html"""- comments = False- images = bool(int(images))if request.user.is_anonymous:return HttpResponseForbidden()@@ -169,9 +164,7 @@ def workout_view(request, pk, images: bool = False):for day_data in routine.data_for_iteration():if day_data.day is None:continue- elements.append(- render_workout_day(day_data, images=images, comments=comments, only_table=True),- )+ elements.append(render_workout_day(day_data, only_table=True))elements.append(Spacer(10 * cm, 0.5 * cm))# Footer, date and info@@ -182,6 +175,5 @@ def workout_view(request, pk, images: bool = False):doc.build(elements)# Create the HttpResponse object with the appropriate PDF headers.- response['Content-Disposition'] = f'attachment; filename=Routine-{pk}-table.pdf'response['Content-Length'] = len(response.content)return responsediff --git a/wger/manager/views/schedule.py b/wger/manager/views/schedule.pyindex 4ab31f927..ee7c1231f 100644--- a/wger/manager/views/schedule.py+++ b/wger/manager/views/schedule.py@@ -70,7 +70,6 @@ from wger.utils.pdf import (styleSheet,)-logger = logging.getLogger(__name__)@@ -124,9 +123,6 @@ def export_pdf_log(request, pk, images=False, comments=False, uidb64=None, token"""user = request.user- comments = bool(int(comments))- images = bool(int(images))-# Load the workoutif uidb64 is not None and token is not None:if check_token(uidb64, token):@@ -171,9 +167,7 @@ def export_pdf_log(request, pk, images=False, comments=False, uidb64=None, tokenelements.append(Spacer(10 * cm, 0.5 * cm))for day in step.workout.day_set.all():- elements.append(- render_workout_day(day, images=images, comments=comments, nr_of_weeks=7)- )+ elements.append(render_workout_day(day, nr_of_weeks=7))elements.append(Spacer(10 * cm, 0.5 * cm))# Footer, date and info@@ -194,7 +188,6 @@ def export_pdf_table(request, pk, images=False, comments=False, uidb64=None, tok"""user = request.user- comments = bool(int(comments))images = bool(int(images))# Load the workout@@ -244,8 +237,6 @@ def export_pdf_table(request, pk, images=False, comments=False, uidb64=None, tokelements.append(render_workout_day(day,- images=images,- comments=comments,nr_of_weeks=7,only_table=True,)