Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Make fields in workout form optional

Roland Geider3b3dd0a08ea0
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 4907495d7..d1a99d11f 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -40,6 +40,7 @@ Improvements:
* BMI calculator now works with pounds as well (thanks `@petervanderdoes`_) `#318`_
* Give feedback when autocompleter didn't find any results `#293`_
* Better GUI consistency in modal dialogs (thanks `@jstoebel`_ ) `#274`_
+* Fields in workout log form are no longer required, making it possible to only log weight for certain exercises `#334`_
* The dashboard page was improved and made more user friendly `#201`_ (partly)
* Replace jquery UI's autocompleter and sortable this reduces size of JS and CSS `#78`_ and `#79`_
* Update to D3js v4 `#314`_, `#302`_
@@ -83,6 +84,7 @@ Other improvements and bugfixes: `#25`_, `#243`_, `#279`_, `#275`_, `#270`_,
.. _#325: https://github.com/wger-project/wger/issues/325
.. _#330: https://github.com/wger-project/wger/issues/330
.. _#331: https://github.com/wger-project/wger/issues/331
+.. _#334: https://github.com/wger-project/wger/issues/334
.. _@petervanderdoes: https://github.com/petervanderdoes
.. _@DeveloperMal: https://github.com/DeveloperMal
.. _@alelevinas: https://github.com/alelevinas
diff --git a/wger/manager/forms.py b/wger/manager/forms.py
index 551771970..c8cc6c61f 100644
--- a/wger/manager/forms.py
+++ b/wger/manager/forms.py
@@ -26,6 +26,8 @@ from django.forms import (
MultipleHiddenInput,
ModelForm,
DateField,
+ IntegerField,
+ DecimalField,
CharField,
widgets,
ModelChoiceField
@@ -138,7 +140,7 @@ class WorkoutLogForm(ModelForm):
'''
Helper form for a WorkoutLog.
- The repetition and weight units are defined here only to make them optional
+ These fields are re-defined here only to make them optional
'''
repetition_unit = ModelChoiceField(queryset=RepetitionUnit.objects.all(),
label=_('Unit'),
@@ -146,6 +148,14 @@ class WorkoutLogForm(ModelForm):
weight_unit = ModelChoiceField(queryset=WeightUnit.objects.all(),
label=_('Unit'),
required=False)
+ exercise = ModelChoiceField(queryset=Exercise.objects.all(),
+ label=_('Exercise'),
+ required=False)
+ reps = IntegerField(label=_('Repetitions'),
+ required=False)
+ weight = DecimalField(label=_('Weight'),
+ initial=0,
+ required=False)
class Meta:
model = WorkoutLog
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index a762e49e4..a58e4ca57 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -173,10 +173,11 @@ def add(request, pk):
instance.instance = session
instance.save()
- # Log entries
- instances = formset.save(commit=False)
+ # Log entries (only the ones with actual content)
+ instances = [i for i in formset.save(commit=False) if i.reps]
for instance in instances:
-
+ if not instance.weight:
+ instance.weight = 0
instance.user = request.user
instance.workout = day.training
instance.date = log_date