Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Manually set the weight und repetition unit

Roland Geider80137c12e1fe
diff --git a/wger/manager/forms.py b/wger/manager/forms.py
index 0cf058b04..cdb134285 100644
--- a/wger/manager/forms.py
+++ b/wger/manager/forms.py
@@ -115,7 +115,10 @@ class WorkoutLogForm(ModelForm):
"""
Helper form for a WorkoutLog.
- These fields are re-defined here only to make them optional
+ These fields are re-defined here only to make them optional. Otherwise
+ all the entries in the formset would be required, which is not really what
+ we want. This form is one prime candidate to rework with some modern JS
+ framework, there is a ton of ugly logic like this just to make it work.
"""
repetition_unit = ModelChoiceField(queryset=RepetitionUnit.objects.all(),
label=_('Unit'),
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index 4ac01a931..948ec4ae1 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -45,6 +45,10 @@ from django.views.generic import (
)
# wger
+from wger.core.models import (
+ RepetitionUnit,
+ WeightUnit
+)
from wger.manager.forms import (
HelperWorkoutSessionForm,
WorkoutLogForm,
@@ -189,8 +193,18 @@ def add(request, pk):
# Log entries (only the ones with actual content)
instances = [i for i in formset.save(commit=False) if i.reps]
for instance in instances:
+
+ # Set the weight unit in kg
+ if not hasattr(instance, 'weight_unit'):
+ instance.weight_unit = WeightUnit.objects.get(pk=1)
+
+ # Set the unit in reps
+ if not hasattr(instance, 'repetition_unit'):
+ instance.repetition_unit = RepetitionUnit.objects.get(pk=1)
+
if not instance.weight:
instance.weight = 0
+
instance.user = request.user
instance.workout = day.training
instance.date = log_date