Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Simplify a bit the generic view by checking the fields' class

Roland Geider10a180a5a7ec
diff --git a/wger/exercises/views.py b/wger/exercises/views.py
index cfeaaad48..e78e54a0d 100644
--- a/wger/exercises/views.py
+++ b/wger/exercises/views.py
@@ -223,7 +223,6 @@ class ExercisesEditAddView(YamlFormMixin):
'muscles_secondary',
'description']
- select_lists = ['category']
title = ugettext_lazy('Add exercise')
custom_js = 'init_tinymce();'
diff --git a/wger/workout_manager/generic_views.py b/wger/workout_manager/generic_views.py
index 966476edd..cf24c8839 100644
--- a/wger/workout_manager/generic_views.py
+++ b/wger/workout_manager/generic_views.py
@@ -16,6 +16,7 @@
import logging
+from django.forms import models
from django.http import HttpResponseForbidden
from django.utils.translation import ugettext_lazy
@@ -30,7 +31,6 @@ class YamlFormMixin(ModelFormMixin):
template_name = 'form.html'
form_fields = []
- select_lists = []
custom_js = ''
form_action = ''
form_action_urlname = ''
@@ -58,9 +58,12 @@ class YamlFormMixin(ModelFormMixin):
else:
context['form_fields'] = kwargs['form']
- # Drop down lists get a special CSS class, there doesn't seem to be
- # another way of detecting them
- context['select_lists'] = self.select_lists
+ # Drop down lists get a special CSS class
+ select_list = []
+ for i in self.form_fields:
+ if isinstance(kwargs['form'][i].field, models.ModelChoiceField):
+ select_list.append(i)
+ context['select_lists'] = select_list
# Custom JS code on form (autocompleter, editor, etc.)
context['custom_js'] = self.custom_js