Self hosted FLOSS fitness/workout, nutrition and weight tracker
Cleanup
Roland Geider3e1e01d681eb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c7b1ee6be..23741e000 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,4 +13,5 @@ Add "warmup" to list of set types.<https://github.com/wger-project/wger/pull/2137>Add more information to the repetition units in the routines. This will allowus to e.g. properly handle time units in the mobile app, e.g. by showing a-timer or similar+timer or similar. The `setting-repetitionunit` endpoint now exposes the new fields+`unit_type` and `multiplier`.diff --git a/wger/core/migrations/0021_add_unit_type_to_repetitionunit.py b/wger/core/migrations/0021_add_unit_type_to_repetitionunit.pyindex 55c3e34cf..b082a5ec8 100644--- a/wger/core/migrations/0021_add_unit_type_to_repetitionunit.py+++ b/wger/core/migrations/0021_add_unit_type_to_repetitionunit.py@@ -1,20 +1,27 @@# Generated by Django 5.2.9 on 2025-12-07 18:34+import loggingfrom django.db import migrations, models+from django.db.migrations.state import StateApps+logger = logging.getLogger(__name__)-def set_unit_types(apps, schema_editor):++def set_unit_types(apps: StateApps, schema_editor):"""Set the unit_type for existing RepetitionUnit records based on their ID.Default units (from fixture):- ID 1: Repetitions -> REPETITIONS- ID 2: Until Failure -> REPETITIONS+ - ID 7: Max Reps -> REPETITIONS+- ID 3: Seconds -> TIME- ID 4: Minutes -> TIME+- ID 5: Miles -> DISTANCE- ID 6: Kilometers -> DISTANCE- - ID 7: Max Reps -> REPETITIONS+ - ID 8: Meters -> DISTANCE (new)"""RepetitionUnit = apps.get_model('core', 'RepetitionUnit')@@ -29,6 +36,12 @@ def set_unit_types(apps, schema_editor):RepetitionUnit.objects.filter(id=6).update(multiplier=1000) # Kilometers -> 1000 metersRepetitionUnit.objects.filter(id=5).update(multiplier=1609) # Miles -> 1609 meters+ if RepetitionUnit.objects.filter(id=8).exists():+ logger.warning('RepetitionUnit with ID=8 already exists, skipping creation of "meters"')+ else:+ # New+ RepetitionUnit.objects.create(id=8, name='Meters', unit_type='DISTANCE', multiplier=1)+# Repetition-based units (already default, but explicit for clarity)RepetitionUnit.objects.filter(id__in=[1, 2, 7]).update(unit_type='REPETITIONS')RepetitionUnit.objects.filter(id=1).update(multiplier=1)diff --git a/wger/core/templates/repetition_unit/list.html b/wger/core/templates/repetition_unit/list.htmlindex a4f32e1c7..a90bc144c 100644--- a/wger/core/templates/repetition_unit/list.html+++ b/wger/core/templates/repetition_unit/list.html@@ -8,7 +8,7 @@<ul class="list-group">{% for unit in object_list %}<li class="list-group-item list-group-item-action">- {% if unit.id != 1 and unit.id != 2 %}+ {% if unit.id > max_id %}<div class="btn-group float-end"><button type="button" class="btn btn-dark dropdown-toggle btn-sm"data-bs-toggle="dropdown">@@ -36,8 +36,6 @@{% endblock %}--{# #}{# Options #}{# #}@@ -47,3 +45,14 @@{% modal_link url='core:repetition-unit:add' text=text %}{% endif %}{% endblock %}+++{# #}+{# Sidebar #}+{# #}+{% block sidebar %}+ <p>+ Note that it is not possible to delete the system repetition units as some+ of the IDs are had coded in a handful of places.+ </p>+{% endblock sidebar %}diff --git a/wger/core/views/repetition_units.py b/wger/core/views/repetition_units.pyindex b2d9fc731..4c45b17c5 100644--- a/wger/core/views/repetition_units.py+++ b/wger/core/views/repetition_units.py@@ -34,6 +34,7 @@ from django.views.generic import (# wgerfrom wger.core.models import RepetitionUnit+from wger.manager.consts import REP_UNIT_METERSfrom wger.utils.generic_views import (WgerDeleteMixin,WgerFormMixin,@@ -52,6 +53,18 @@ class UnitListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):permission_required = 'core.add_repetitionunit'template_name = 'repetition_unit/list.html'+ def get_context_data(self, **kwargs):+ """+ Send some additional data to the template+ """+ context = super().get_context_data(**kwargs)++ # TODO: this is a hack, if the user in the local installation has other units, this+ # will break (however, this is very unlikely). Ideally we would give the units+ # e.g. UUIDs so we can properly identify them.+ context['max_id'] = REP_UNIT_METERS+ return context+class AddView(WgerFormMixin, LoginRequiredMixin, PermissionRequiredMixin, CreateView):"""diff --git a/wger/manager/consts.py b/wger/manager/consts.pyindex 63f9cb2a7..a1788c435 100644--- a/wger/manager/consts.py+++ b/wger/manager/consts.py@@ -18,11 +18,14 @@ RIR_OPTIONS = [None, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5]REP_UNIT_REPETITIONS = 1REP_UNIT_TILL_FAILURE = 2+REP_UNIT_MAX_REPS = 7+REP_UNIT_SECONDS = 3REP_UNIT_MINUTES = 4-REP_UNIT_MILES = 5++REP_UNIT_METERS = 8REP_UNIT_KILOMETERS = 6-REP_UNIT_MAX_REPS = 7+REP_UNIT_MILES = 5WEIGHT_UNIT_KG = 1WEIGHT_UNIT_LB = 2