Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Small refactoring of workout representation

Roland Geider3c564c91f31e
diff --git a/wger/manager/helpers.py b/wger/manager/helpers.py
index 9b0bd4fa1..5cbfd600a 100644
--- a/wger/manager/helpers.py
+++ b/wger/manager/helpers.py
@@ -194,13 +194,52 @@ def reps_smart_text(settings, set_obj):
"Smart" textual representation
This is a human representation of the settings, in a way that humans
- would also write: e.g. "8 8 10 10" but "4 x 10" and not "10 10 10 10"
+ would also write: e.g. "8 8 10 10" but "4 x 10" and not "10 10 10 10".
+ This helper also takes care to process, hide or show the different repetition
+ and weight units as appropriate, e.g. "8 x 2 Plates", "10, 20, 30, ∞"
:param settings:
:param set_obj:
:return setting_text, setting_list:
'''
- weight_unit = _('kg') if set_obj.exerciseday.training.user.userprofile.use_metric else _('lb')
+
+ def get_reps_reprentation(setting, rep_unit):
+ '''
+ Returns the representation for the repetitions for a setting
+
+ This is basically just to allow for a special representation for the
+ "Until Failure" unit
+ '''
+ if setting.repetition_unit_id != 2:
+ reps = "{0} {1}".format(setting.reps, rep_unit).strip()
+ else:
+ reps = u'∞'
+ return reps
+
+ def get_weight_unit_reprentation(setting):
+ '''
+ Returns the representation for the weight unit for a setting
+
+ This is basically just to allow for a special representation for the
+ "Repetition" and "Until Failure" unit
+ '''
+ if setting.repetition_unit.id not in (1, 2):
+ rep_unit = _(setting.repetition_unit.name)
+ else:
+ rep_unit = ''
+ return rep_unit
+
+ def normalize_weight(setting):
+ '''
+ The weight can be None, or a decimal. In that case, normalize so
+ that we don't return e.g. '15.00', but always '15', independently of
+ the database used.
+ '''
+ if setting.weight:
+ weight = normalize_decimal(setting.weight)
+ else:
+ weight = setting.weight
+ return weight
if len(settings) == 0:
setting_text = ''
@@ -213,26 +252,18 @@ def reps_smart_text(settings, set_obj):
# Only one setting entry, this is a "compact" representation such as e.g.
# 4x10 or similar
elif len(settings) == 1:
- reps = settings[0].reps if settings[0].reps != 99 else u'∞'
- if settings[0].repetition_unit.id != 1:
- rep_unit = _(settings[0].repetition_unit.name)
- else:
- rep_unit = ''
- setting_text = u'{0} × {1} {2}'.format(set_obj.sets, reps, rep_unit).strip()
- setting_list_text = u'{0} {1}'.format(reps, rep_unit).strip()
- weight_unit = settings[0].weight_unit
- # The weight can be None, or a decimal. In that case, normalize so
- # that we don't return e.g. '15.00', but always '15', independently of
- # the database used.
- if settings[0].weight:
- weight = normalize_decimal(settings[0].weight)
- else:
- weight = settings[0].weight
+ rep_unit = get_weight_unit_reprentation(settings[0])
+ reps = get_reps_reprentation(settings[0], rep_unit)
+ weight_unit = settings[0].weight_unit
+ weight = normalize_weight(settings[0])
+ setting_text = u'{0} × {1} {2}'.format(set_obj.sets, reps, rep_unit).strip()
+ setting_list_text = u'{0} {1}'.format(reps, rep_unit).strip()
if weight:
setting_text += ' ({0} {1})'.format(weight, weight_unit)
setting_list_text += ' ({0} {1})'.format(weight, weight_unit)
+
setting_list = [setting_list_text] * set_obj.sets
reps_list = [settings[0].reps] * set_obj.sets
weight_list = [weight] * set_obj.sets
@@ -248,14 +279,13 @@ def reps_smart_text(settings, set_obj):
tmp_repetition_unit = []
tmp_weight_unit = []
for setting in settings:
- rep_unit = _(setting.repetition_unit.name) if setting.repetition_unit.id != 1 else ''
- reps = "{0} {1}".format(setting.reps, rep_unit).strip() if setting.reps != 99 else u'∞'
- weight = setting.weight
- if setting.weight:
- # Normalize, see comment above
- weight = normalize_decimal(setting.weight)
+ rep_unit = get_weight_unit_reprentation(setting)
+ reps = get_reps_reprentation(setting, rep_unit)
+ weight = normalize_weight(setting)
+ if weight:
reps += ' ({0} {1})'.format(weight, setting.weight_unit)
+
tmp_reps_text.append(reps)
tmp_reps.append(setting.reps)
tmp_weight.append(weight)
diff --git a/wger/manager/templates/mobile/workout/view.html b/wger/manager/templates/mobile/workout/view.html
index 8d7380e9c..786dbf696 100644
--- a/wger/manager/templates/mobile/workout/view.html
+++ b/wger/manager/templates/mobile/workout/view.html
@@ -98,10 +98,7 @@ $(document).ready(function() {
<ol>
<li>{% trans "Add training days" %}</li>
<li>{% trans "Add workout sets to days" %}</li>
- <li>
- {% trans "Set the repetitions for each set" %}
- ({% trans "use '99' for 'all repetitions you can do'" %})
- </li>
+ <li>{% trans "Set the repetitions for each set" %}</li>
</ol>
diff --git a/wger/manager/templates/workout/view.html b/wger/manager/templates/workout/view.html
index dafbaa5d9..a13a1fc5d 100644
--- a/wger/manager/templates/workout/view.html
+++ b/wger/manager/templates/workout/view.html
@@ -93,10 +93,7 @@ $(document).ready(function() {
<ol>
<li>{% trans "Add training days" %}</li>
<li>{% trans "Add workout sets to days" %}</li>
- <li>
- {% trans "Set the repetitions for each set" %}
- ({% trans "use '99' for 'all repetitions you can do'" %})
- </li>
+ <li>{% trans "Set the repetitions for each set" %}</li>
</ol>