Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add short set text and fix routine set texts
Roland Geider298f5d0ba360
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3b99d890e..3ebcf6225 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,9 @@ Progression requirements can now reference the top of the prescribed range via t* Exercise contributions always have an author: if none is given, the usernameis used. Everyone who edits an exercise or translation is credited as anauthor, images and videos keep the author of the file.+* The routine date sequences (`date-sequence-gym`, `date-sequence-display`) have+ a new `text_repr_short` per set: repetitions and weight only, without sets,+ RiR and rest, e.g. for notifications.### Bug fixes@@ -25,6 +28,8 @@ Progression requirements can now reference the top of the prescribed range via tdeletion continue to remove the corresponding history. Apply the usual databasemigrations when upgrading; previously deleted history cannot be restored bythis change.+* Sets with "Until Failure" or "Max Reps" but no repetitions value keep their+ unit in the routine API and show it in the set text.## New settings*(for self-hoster)*diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.pyindex f448e6544..b8a55c03d 100644--- a/wger/manager/api/serializers.py+++ b/wger/manager/api/serializers.py@@ -389,6 +389,7 @@ class SetConfigDataSerializer(serializers.Serializer):max_rest = DecimalOrIntegerField(max_digits=6, decimal_places=2, allow_null=True)type = serializers.CharField()text_repr = serializers.CharField()+ text_repr_short = serializers.CharField()comment = serializers.CharField()diff --git a/wger/manager/dataclasses.py b/wger/manager/dataclasses.pyindex f2edd5d91..6cdc78c58 100644--- a/wger/manager/dataclasses.py+++ b/wger/manager/dataclasses.py@@ -37,6 +37,7 @@ from django.utils.translation import gettext as _# wgerfrom wger.manager.consts import (+ REP_UNIT_MAX_REPS,REP_UNIT_REPETITIONS,REP_UNIT_TILL_FAILURE,)@@ -93,10 +94,19 @@ class SetConfigData:This converts the values to something readable like "10 × 100 kg @ 2.00RiR""""+ return self._text_repr(short=False)+ @property+ def text_repr_short(self) -> str:+ """+ Text representation without sets, RiR and rest, e.g. "10 × 100 kg"+ """+ return self._text_repr(short=True)++ def _text_repr(self, short: bool) -> str:out = []- if self.sets and self.sets > 1:+ if not short and self.sets and self.sets > 1:sets = self.setsif self.max_sets:sets = f'{sets}-{self.max_sets}'@@ -134,6 +144,16 @@ class SetConfigData:if self.weight:out.append('×')+ # These units are meaningful without a repetitions value+ elif self.repetitions_unit in (REP_UNIT_TILL_FAILURE, REP_UNIT_MAX_REPS):+ if self.repetitions_unit == REP_UNIT_TILL_FAILURE and self.weight:+ out.append('∞')+ else:+ out.append(_(self.repetitions_unit_name))++ if self.weight:+ out.append('×')+if self.weight:weight = round_value(self.weight, self.weight_rounding)max_weight = (@@ -151,6 +171,9 @@ class SetConfigData:out.append(f'{weight} {unit}'.strip())+ if short:+ return ' '.join(out)+if self.rir:rir = round_value(self.rir, 0.5)out.append(f'@ {rir} {_("RiR")}')diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.pyindex b9dbdfcf3..9f57b5ce2 100644--- a/wger/manager/models/slot_entry.py+++ b/wger/manager/models/slot_entry.py@@ -34,7 +34,9 @@ from wger.core.models import ()from wger.exercises.models import Exercisefrom wger.manager.consts import (+ REP_UNIT_MAX_REPS,REP_UNIT_REPETITIONS,+ REP_UNIT_TILL_FAILURE,REQUIREMENT_RULES,WEIGHT_UNIT_KG,)@@ -536,6 +538,12 @@ class SlotEntry(models.Model):rest = states['rest'].valuemax_rest = states['maxrest'].value+ # "Until Failure" and "Max Reps" don't need a repetitions value+ has_repetitions_unit = repetitions is not None or self.repetition_unit_id in (+ REP_UNIT_TILL_FAILURE,+ REP_UNIT_MAX_REPS,+ )+result = SetConfigData(slot_entry_id=self.id,exercise=self.exercise_id,@@ -557,9 +565,9 @@ class SlotEntry(models.Model):if max_repetitions and repetitions and max_repetitions > repetitionselse None,repetitions_rounding=self.repetition_rounding if repetitions is not None else None,- repetitions_unit=self.repetition_unit_id if repetitions is not None else None,+ repetitions_unit=self.repetition_unit_id if has_repetitions_unit else None,repetitions_unit_name=self.repetition_unit.name- if repetitions is not None and self.repetition_unit is not None+ if has_repetitions_unit and self.repetition_unit is not Noneelse None,rir=round_value(rir, self._display_rounding('rir')),max_rir=round_value(max_rir, self._display_rounding('rir'))diff --git a/wger/manager/tests/test_set_config_data.py b/wger/manager/tests/test_set_config_data.pyindex 65f1ac02a..f87d9bc81 100644--- a/wger/manager/tests/test_set_config_data.py+++ b/wger/manager/tests/test_set_config_data.py@@ -190,6 +190,172 @@ class SetConfigDataTestCase(WgerTestCase):self.assertEqual(Decimal(data['rir']), capped_rir)+class SetConfigDataUnitsTestCase(WgerTestCase):+ """+ Test the long and short text representation for the different units+ """++ def assert_texts(self, config: SetConfigData, text_repr: str, text_repr_short: str):+ self.assertEqual(config.text_repr, text_repr)+ self.assertEqual(config.text_repr_short, text_repr_short)++ def test_seconds(self):+ config = SetConfigData(+ exercise=1,+ repetitions=45,+ repetitions_unit=3,+ repetitions_unit_name='Seconds',+ rest=15,+ )+ self.assert_texts(config, '45 Seconds 15s rest', '45 Seconds')++ def test_until_failure_with_weight_without_repetitions(self):+ config = SetConfigData(+ exercise=1,+ repetitions_unit=2,+ repetitions_unit_name='Until Failure',+ weight=20,+ weight_unit=1,+ weight_unit_name='kg',+ rir=2,+ rest=15,+ )+ self.assert_texts(config, '∞ × 20 kg @ 2 RiR 15s rest', '∞ × 20 kg')++ def test_until_failure_without_repetitions(self):+ config = SetConfigData(+ exercise=1,+ repetitions_unit=2,+ repetitions_unit_name='Until Failure',+ rest=15,+ )+ self.assert_texts(config, 'Until Failure 15s rest', 'Until Failure')++ def test_max_reps_without_repetitions(self):+ config = SetConfigData(+ exercise=1,+ repetitions_unit=7,+ repetitions_unit_name='Max Reps',+ rest=15,+ )+ self.assert_texts(config, 'Max Reps 15s rest', 'Max Reps')++ def test_max_reps_with_weight_without_repetitions(self):+ config = SetConfigData(+ exercise=1,+ repetitions_unit=7,+ repetitions_unit_name='Max Reps',+ weight=20,+ weight_unit=1,+ weight_unit_name='kg',+ )+ self.assert_texts(config, 'Max Reps × 20 kg', 'Max Reps × 20 kg')++ def test_kilometers_and_speed(self):+ config = SetConfigData(+ exercise=1,+ repetitions=5,+ repetitions_unit=6,+ repetitions_unit_name='Kilometers',+ weight=12,+ weight_unit=6,+ weight_unit_name='Kilometers Per Hour',+ rest=15,+ )+ self.assert_texts(+ config,+ '5 Kilometers × 12 Kilometers Per Hour 15s rest',+ '5 Kilometers × 12 Kilometers Per Hour',+ )++ def test_pounds(self):+ config = SetConfigData(+ exercise=1,+ repetitions=8,+ repetitions_unit=1,+ repetitions_unit_name='Repetitions',+ weight=65,+ weight_unit=2,+ weight_unit_name='lb',+ rest=15,+ )+ self.assert_texts(config, '8 × 65 lb 15s rest', '8 × 65 lb')++ def test_body_weight_zero(self):+ config = SetConfigData(+ exercise=1,+ repetitions=10,+ repetitions_unit=1,+ repetitions_unit_name='Repetitions',+ weight=0,+ weight_unit=5,+ weight_unit_name='Body Weight',+ rest=15,+ )+ self.assert_texts(config, '10 Reps 15s rest', '10 Reps')++ def test_plates(self):+ config = SetConfigData(+ exercise=1,+ repetitions=8,+ repetitions_unit=1,+ repetitions_unit_name='Repetitions',+ weight=2,+ weight_unit=3,+ weight_unit_name='Plates',+ rest=15,+ )+ self.assert_texts(config, '8 × 2 Plates 15s rest', '8 × 2 Plates')++ def test_ranges(self):+ config = SetConfigData(+ exercise=1,+ sets=3,+ repetitions=8,+ max_repetitions=12,+ repetitions_unit=1,+ repetitions_unit_name='Repetitions',+ weight=60,+ max_weight=70,+ weight_unit=1,+ weight_unit_name='kg',+ rir=2,+ rest=15,+ max_rest=30,+ )+ self.assert_texts(+ config,+ '3 Sets, 8-12 × 60-70 kg @ 2 RiR 15-30s rest',+ '8-12 × 60-70 kg',+ )++ def test_weight_only(self):+ config = SetConfigData(+ exercise=1,+ weight=40,+ weight_unit=1,+ weight_unit_name='kg',+ rest=15,+ )+ self.assert_texts(config, '40 kg 15s rest', '40 kg')++ def test_short_text_serialized(self):+ config = SetConfigData(+ exercise=1,+ sets=3,+ repetitions=8,+ repetitions_unit=1,+ weight=40,+ weight_unit=1,+ weight_unit_name='kg',+ rest=15,+ )+ data = SetConfigDataSerializer(config).data++ self.assertEqual(data['text_repr'], '3 Sets, 8 × 40 kg 15s rest')+ self.assertEqual(data['text_repr_short'], '8 × 40 kg')++class SlotDataExercisesTestCase(WgerTestCase):"""Test that the list of exercises of a slot keeps the order of its setsdiff --git a/wger/manager/tests/test_slot_entry.py b/wger/manager/tests/test_slot_entry.pyindex e86e870c5..a8bad8e3c 100644--- a/wger/manager/tests/test_slot_entry.py+++ b/wger/manager/tests/test_slot_entry.py@@ -1177,6 +1177,29 @@ class SlotEntryTestCase(WgerTestCase):),)+ def test_repetitions_unit_without_repetitions(self):+ """+ Test that "Until Failure" and "Max Reps" are kept without a repetitions config,+ other units are not+ """+ WeightConfig(slot_entry=self.slot_entry, iteration=1, value=20).save()++ for unit_id, expected_unit, expected_name in (+ (2, 2, 'Until Failure'),+ (7, 7, 'Max Reps'),+ (1, None, None),+ (3, None, None),+ ):+ with self.subTest(unit_id=unit_id):+ self.slot_entry.repetition_unit_id = unit_id+ self.slot_entry.save()+ cache.clear()++ data = self.slot_entry.get_config_data(1)+ self.assertEqual(data.repetitions_unit, expected_unit)+ self.assertEqual(data.repetitions_unit_name, expected_name)+ self.assertIsNone(data.repetitions)+def test_has_progression_flag(self):"""Tests that the has_progression flag is automatically set"""diff --git a/wger/version.py b/wger/version.pyindex fae52e9dd..1e058be18 100644--- a/wger/version.py+++ b/wger/version.py@@ -35,7 +35,7 @@ Always use versions in the x.y.z format, without any suffixes like "beta1" or suMIN_SERVER_VERSION = Version('2.5.0')"""Minimum version of the server required to run sync commands on this server"""-VERSION_STRING = '2.8.0-dev.3'+VERSION_STRING = '2.8.0-dev.4'"""Current version of the app.