Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix exercise edit/create form

Roland Geider695daf0ab722
diff --git a/docs/changelog.rst b/docs/changelog.rst
index e93c97493..0ba6b8f34 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -23,7 +23,7 @@ Upgrade steps from 1.9:
🐛 Bug Fixes:
-* `#499`_
+* `#499`_, `#505`_
🧰 Maintenance:
@@ -38,6 +38,7 @@ Upgrade steps from 1.9:
.. _#340: https://github.com/wger-project/wger/issues/340
.. _#494: https://github.com/wger-project/wger/issues/494
.. _#499: https://github.com/wger-project/wger/issues/499
+.. _#505: https://github.com/wger-project/wger/issues/505
diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.py
index 5874ccab5..a97f37948 100644
--- a/wger/exercises/tests/test_exercise.py
+++ b/wger/exercises/tests/test_exercise.py
@@ -333,7 +333,7 @@ class ExercisesTestCase(WgerTestCase):
'name_original': 'my test exercise',
'license': 1,
'muscles': []})
- self.assertFalse(response.context['form'].errors.get('muscles'))
+ self.assertEqual(response.status_code, 302)
# No muscles - editing
response = self.client.post(reverse('exercise:exercise:edit', kwargs={'pk': '1'}),
@@ -342,7 +342,7 @@ class ExercisesTestCase(WgerTestCase):
'license': 1,
'muscles': []})
if admin:
- self.assertFalse(response.context['form'].errors.get('muscles'))
+ self.assertEqual(response.status_code, 302)
else:
self.assertIn(response.status_code, STATUS_CODES_FAIL)
@@ -359,7 +359,7 @@ class ExercisesTestCase(WgerTestCase):
"""
self.user_login('test')
self.add_exercise_success(admin=False)
- self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(len(mail.outbox), 2)
def search_exercise(self, fail=True):
"""
diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.py
index 52b7f1f11..0a8c97a35 100644
--- a/wger/exercises/views/exercises.py
+++ b/wger/exercises/views/exercises.py
@@ -27,11 +27,13 @@ from django.contrib.auth.mixins import (
)
from django.core import mail
from django.forms import (
+ CharField,
CheckboxSelectMultiple,
ModelChoiceField,
ModelForm,
ModelMultipleChoiceField,
- Select
+ Select,
+ Textarea
)
from django.http import (
HttpResponseForbidden,
@@ -169,9 +171,11 @@ class ExercisesEditAddView(WgerFormMixin):
def get_form_class(self):
class ExerciseForm(ModelForm):
+ # Redefine some fields here to set some properties
+ # (some of this could be done with a crispy form helper and would be
+ # a cleaner solution)
category = ModelChoiceField(queryset=ExerciseCategory.objects.all(),
- widget=Select()
- )
+ widget=Select())
muscles = ModelMultipleChoiceField(queryset=Muscle.objects.all(),
widget=CheckboxSelectMultiple(),
required=False)
@@ -180,6 +184,10 @@ class ExercisesEditAddView(WgerFormMixin):
widget=CheckboxSelectMultiple(),
required=False)
+ description = CharField(label=_('Description'),
+ widget=Textarea,
+ required=False)
+
class Meta:
model = Exercise
widgets = {'equipment': TranslatedSelectMultiple()}