Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Also check if input field is a file upload

Roland Geider2f82f94e823b
diff --git a/wger/manager/templates/tags/render_form_element.html b/wger/manager/templates/tags/render_form_element.html
index 34085dcfa..b990886b8 100644
--- a/wger/manager/templates/tags/render_form_element.html
+++ b/wger/manager/templates/tags/render_form_element.html
@@ -13,7 +13,7 @@
</label>
<div class="col-md-9">
- {% if not field|is_checkbox %}
+ {% if not field|is_checkbox and not field|is_fileupload %}
{{ field|form_field_add_css:'form-control' }}
{% else %}
{{ field }}
diff --git a/wger/manager/templatetags/wger_extras.py b/wger/manager/templatetags/wger_extras.py
index 968ab8411..4a0292f08 100644
--- a/wger/manager/templatetags/wger_extras.py
+++ b/wger/manager/templatetags/wger_extras.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
from django import template
-from django.forms.widgets import CheckboxInput
+from django.forms.widgets import CheckboxInput, ClearableFileInput
from wger.utils.constants import PAGINATION_MAX_TOTAL_PAGES
from wger.utils.constants import PAGINATION_PAGES_AROUND_CURRENT
@@ -138,6 +138,17 @@ def is_checkbox(field):
return field.field.widget.__class__.__name__ == CheckboxInput().__class__.__name__
[email protected](name='is_fileupload')
+def is_fileupload(field):
+ '''
+ Tests if a field element is a file upload, as it needs to be handled slightly different
+
+ :param field: a form field
+ :return: boolen
+ '''
+ return field.field.widget.__class__.__name__ == ClearableFileInput().__class__.__name__
+
+
@register.inclusion_tag('tags/render_form_element.html')
def render_form_field(field):
'''