Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove other uses of canonical form

Roland Geider081216f5b167
diff --git a/wger/manager/helpers.py b/wger/manager/helpers.py
index cee3d77a3..ba0be4ec7 100644
--- a/wger/manager/helpers.py
+++ b/wger/manager/helpers.py
@@ -76,8 +76,8 @@ def render_workout_day(day, nr_of_weeks=7, images=False, comments=False, only_ta
p = Paragraph(
'<para align="center">%(days)s: %(description)s</para>' % {
- 'days': day['days_of_week']['text'],
- 'description': day['obj'].description
+ 'days': ', '.join([str(_(i.day_of_week)) for i in day.day.all()]),
+ 'description': day.description
}, styleSheet["SubHeader"]
)
@@ -90,33 +90,30 @@ def render_workout_day(day, nr_of_weeks=7, images=False, comments=False, only_ta
# Sets
exercise_start = len(data)
- for set in day['set_list']:
- group_exercise_marker[set['obj'].id] = {'start': len(data), 'end': len(data)}
+ for set_obj in day.set_set.all():
+ group_exercise_marker[set_obj.id] = {'start': len(data), 'end': len(data)}
# Exercises
- for exercise in set['exercise_list']:
- group_exercise_marker[set['obj'].id]['end'] = len(data)
+ for exercise in set_obj.exercises:
+ group_exercise_marker[set_obj.id]['end'] = len(data)
# Process the settings
- if exercise['has_weight']:
- setting_out = []
- for i in exercise['setting_text'].split('–'):
- setting_out.append(Paragraph(i, styleSheet["Small"], bulletText=''))
- else:
- setting_out = Paragraph(exercise['setting_text'], styleSheet["Small"])
+ setting_out = []
+ for i in set_obj.reps_smart_text(exercise).split('–'):
+ setting_out.append(Paragraph(i, styleSheet["Small"], bulletText=''))
# Collect a list of the exercise comments
item_list = [Paragraph('', styleSheet["Small"])]
if comments:
item_list = [
ListItem(Paragraph(i, style=styleSheet["ExerciseComments"]))
- for i in exercise['comment_list']
+ for i in exercise.exercisecomment_set.all()
]
# Add the exercise's main image
image = Paragraph('', styleSheet["Small"])
if images:
- if exercise['obj'].main_image:
+ if exercise.main_image:
# Make the images somewhat larger when printing only the workout and not
# also the columns for weight logs
@@ -125,13 +122,13 @@ def render_workout_day(day, nr_of_weeks=7, images=False, comments=False, only_ta
else:
image_size = 1.5
- image = Image(exercise['obj'].main_image.image)
+ 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 together
exercise_content = [
- Paragraph(exercise['obj'].name, styleSheet["Small"]), image,
+ Paragraph(exercise.name, styleSheet["Small"]), image,
ListFlowable(
item_list,
bulletType='bullet',
diff --git a/wger/manager/views/ical.py b/wger/manager/views/ical.py
index a76289892..0ee538307 100644
--- a/wger/manager/views/ical.py
+++ b/wger/manager/views/ical.py
@@ -97,12 +97,12 @@ def get_events_workout(calendar, workout, duration, start_date=None):
for set_obj in day.set_set.all():
for exercise in set_obj.exercises:
description_list.append(str(exercise))
- description = ', '.join(description_list) if description_list else day['obj'].description
+ description = ', '.join(description_list) if description_list else day.description
# Make an event for each weekday
- for weekday in day['days_of_week']['day_list']:
+ for weekday in day.day.all():
event = Event()
- event.add('summary', day['obj'].description)
+ event.add('summary', day.description)
event.add('description', description)
event.add('dtstart', next_weekday(start_date, weekday.id - 1))
event.add('dtend', next_weekday(start_date, weekday.id - 1))
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index e8ee6c421..2e2052210 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -275,17 +275,17 @@ class WorkoutLogDetailView(DetailView, LoginRequiredMixin):
# Prepare the entries for rendering and the D3 chart
workout_log = {}
- for day_list in self.object.canonical_representation['day_list']:
- day_id = day_list['obj'].id
+ for day_obj in self.object.day_set.all():
+ day_id = day_obj.id
workout_log[day_id] = {}
- for set_list in day_list['set_list']:
+ for set_obj in day_obj.set_set.all():
exercise_log = {}
- for exercise_list in set_list['exercise_list']:
- exercise_id = exercise_list['obj'].id
+ for exercise_obj in set_obj.exercises:
+ exercise_id = exercise_obj.id
exercise_log[exercise_id] = []
# Filter the logs for user and exclude all units that are not weight
- logs = exercise_list['obj'].workoutlog_set.filter(
+ logs = exercise_obj.workoutlog_set.filter(
user=self.owner_user,
weight_unit__in=(1, 2),
repetition_unit=1,
@@ -293,7 +293,7 @@ class WorkoutLogDetailView(DetailView, LoginRequiredMixin):
)
entry_log, chart_data = process_log_entries(logs)
if entry_log:
- exercise_log[exercise_list['obj'].id].append(entry_log)
+ exercise_log[exercise_obj.id].append(entry_log)
if exercise_log:
workout_log[day_id][exercise_id] = {}
diff --git a/wger/manager/views/pdf.py b/wger/manager/views/pdf.py
index 1cc5f5187..3597da9f1 100644
--- a/wger/manager/views/pdf.py
+++ b/wger/manager/views/pdf.py
@@ -106,7 +106,7 @@ def workout_log(request, id, images=False, comments=False, uidb64=None, token=No
elements.append(Spacer(10 * cm, 1.5 * cm))
# Iterate through the Workout and render the training days
- for day in workout.canonical_representation['day_list']:
+ for day in workout.day_set.all():
elements.append(render_workout_day(day, images=images, comments=comments))
elements.append(Spacer(10 * cm, 0.5 * cm))
@@ -179,7 +179,7 @@ def workout_view(request, id, images=False, comments=False, uidb64=None, token=N
elements.append(Spacer(10 * cm, 1.5 * cm))
# Iterate through the Workout and render the training days
- for day in workout.canonical_representation['day_list']:
+ for day in workout.day_set.all():
elements.append(render_workout_day(day, images=images, comments=comments, only_table=True))
elements.append(Spacer(10 * cm, 0.5 * cm))
diff --git a/wger/manager/views/schedule.py b/wger/manager/views/schedule.py
index 61cda96e1..6a39e512c 100644
--- a/wger/manager/views/schedule.py
+++ b/wger/manager/views/schedule.py
@@ -171,7 +171,7 @@ def export_pdf_log(request, pk, images=False, comments=False, uidb64=None, token
elements.append(p)
elements.append(Spacer(10 * cm, 0.5 * cm))
- for day in step.workout.canonical_representation['day_list']:
+ for day in step.workout.day_set.all():
elements.append(
render_workout_day(day, images=images, comments=comments, nr_of_weeks=7)
)
@@ -241,7 +241,7 @@ def export_pdf_table(request, pk, images=False, comments=False, uidb64=None, tok
elements.append(p)
elements.append(Spacer(10 * cm, 0.5 * cm))
- for day in step.workout.canonical_representation['day_list']:
+ for day in step.workout.day_set.all():
elements.append(
render_workout_day(
day,