Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove unused field rendering tags

Roland Geiderdc297636510a
diff --git a/wger/core/templates/tags/render_form_element.html b/wger/core/templates/tags/render_form_element.html
deleted file mode 100644
index 6a1d949ce..000000000
--- a/wger/core/templates/tags/render_form_element.html
+++ /dev/null
@@ -1,40 +0,0 @@
-{% load i18n wger_extras %}
-{% if not field.is_hidden %}
-<div class="form-group {% if field.errors %}has-error{% endif %}" id="form-{{field.name}}">
- <div {% if field.errors %}class="has-error has-feedback"{% endif %}>
-
- <label for="{{field.auto_id}}" class="col-md-3 control-label">
- {% trans field.label %}
- {% if not field.field.required %}
- <br>
- <span style="font-size:90%;">— <em>{% trans "Optional" %}</em></span>
- {% endif %}
- </label>
-
- <div class="col-md-9">
- {% if not field|is_checkbox and not field|is_fileupload and not field|is_multiple %}
- {{ field|form_field_add_css:'form-control' }}
- {% elif field|is_checkbox and not field|is_multiple %}
- {{ field|form_field_add_css:'checkbox' }}
- {% else %}
- {{ field }}
- {% endif %}
-
- {% if field.errors %}
- <span class="glyphicon glyphicon-remove form-control-feedback"></span>
- {% endif %}
-
- <span class="help-block">
- {% for error in field.errors %}
- <p>{% trans error %}</p>
- {% endfor %}
-
- {% if field.help_text %}{% trans field.help_text|safe %}{% endif %}
- </span>
- </div>
-
- </div>
-</div>
-{% else %}
- {{field}}
-{% endif %}
diff --git a/wger/core/templates/tags/render_form_errors.html b/wger/core/templates/tags/render_form_errors.html
deleted file mode 100644
index edab32c0d..000000000
--- a/wger/core/templates/tags/render_form_errors.html
+++ /dev/null
@@ -1,15 +0,0 @@
-{% load i18n %}
-
-{% if form.is_bound and not form.is_valid or form.non_field_errors or form.non_form_errors %}
-<div class="alert alert-danger has-error">
- {% blocktrans %}The form contains errors. Please verify and correct the
-data in the fields in red and submit the form again.{% endblocktrans %}
-
- {% if form.non_field_errors %}
- {{ form.non_field_errors }}
- {% endif %}
- {% if form.non_form_errors %}
- {{ form.non_form_errors }}
- {% endif %}
-</div>
-{% endif %}
diff --git a/wger/core/templates/tags/render_form_fields.html b/wger/core/templates/tags/render_form_fields.html
deleted file mode 100644
index 0e7f61974..000000000
--- a/wger/core/templates/tags/render_form_fields.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{% load wger_extras %}
-
-{% csrf_token %}
-
-{% render_form_errors form %}
-
-{% for field in form %}
- {% render_form_field field %}
-{% endfor %}
-
-{% if show_save and submit_text %}
- {% render_form_submit submit_text %}
-{% endif %}
diff --git a/wger/core/templates/tags/render_form_submit.html b/wger/core/templates/tags/render_form_submit.html
deleted file mode 100644
index 2d22f9d60..000000000
--- a/wger/core/templates/tags/render_form_submit.html
+++ /dev/null
@@ -1,7 +0,0 @@
-{% load i18n %}
-
-<div class="form-group">
- <div class="offset-md-3 col-md-9">
- <input type="submit" value="{% trans save_text %}" id="form-save" class="btn btn-{{button_class}} btn-block">
- </div>
-</div>
diff --git a/wger/core/templatetags/wger_extras.py b/wger/core/templatetags/wger_extras.py
index 40ee3c3dd..cd9c5d910 100644
--- a/wger/core/templatetags/wger_extras.py
+++ b/wger/core/templatetags/wger_extras.py
@@ -17,10 +17,6 @@
# Django
from django import template
from django.conf import settings
-from django.forms.widgets import (
- CheckboxInput,
- ClearableFileInput
-)
from django.utils.html import strip_spaces_between_tags
from django.utils.safestring import mark_safe
from django.utils.translation import (
@@ -33,10 +29,6 @@ from wger.utils.constants import (
PAGINATION_MAX_TOTAL_PAGES,
PAGINATION_PAGES_AROUND_CURRENT
)
-from wger.utils.widgets import (
- BootstrapSelectMultiple,
- BootstrapSelectMultipleTranslatedOriginal
-)
register = template.Library()
@@ -136,19 +128,6 @@ def get_item(dictionary, key):
return dictionary.get(key)
-def auto_link_css(mobile=False, css=''):
- """
- Adds the appropriate classes to a sidebar link depending on the site version
-
- :param mobile: true if mobile version of site
- :param css: the CSS class, if any, of the link
- :return: the complete CSS classes, wrapped in class="foo"
- """
- css = css + ' btn btn-default btn-block' if mobile else css
- return mark_safe('class="{0}"'.format(css))
-
-
@register.simple_tag
def fa_class(class_name='', icon_type='fas', fixed_width=True):
"""
@@ -224,121 +203,3 @@ def spaceless_config(parser, token):
nodelist = parser.parse(('endspaceless_config',))
parser.delete_first_token()
return SpacelessNode(nodelist)
-
-
-#
-# Form utils
-#
[email protected](name='form_field_add_css')
-def form_field_add_css(field, css):
- """
- Adds a CSS class to a form field. This is needed among other places for
- bootstrap 3, which needs a 'form-control' class in the field itself
- """
- return field.as_widget(attrs={"class": css})
-
-
[email protected](name='is_checkbox')
-def is_checkbox(field):
- """
- Tests if a field element is a checkbox, as it needs to be handled slightly different
-
- :param field: a form field
- :return: boolen
- """
- return isinstance(field.field.widget, CheckboxInput)
-
-
[email protected](name='is_multiple')
-def is_multiple(field):
- """
- Tests if a field element is a multiple select rendered as a checkbox, as it
- needs to be handled slightly different
-
- :param field: a form field
- :return: boolen
- """
- return isinstance(field.field.widget, BootstrapSelectMultiple) \
- or isinstance(field.field.widget, BootstrapSelectMultipleTranslatedOriginal)
-
-
[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 isinstance(field.field.widget, ClearableFileInput)
-
-
[email protected]_tag('tags/render_form_element.html')
-def render_form_field(field):
- """
- Renders a form field with all necessary labels, help texts and labels
- within 'form-group'.
-
- See bootstrap documentation for details: http://getbootstrap.com/css/#forms
- """
-
- return {'field': field}
-
-
[email protected]_tag('tags/render_form_submit.html')
-def render_form_submit(save_text='Save', button_class='default'):
- """
- Comfort function that renders a submit button with all necessary HTML
- and CSS
-
- :param save_text: the text to use on the submit button
- :param button_class: CSS class to apply to the button, default 'default'
- """
- if button_class in ('default',
- 'primary',
- 'success',
- 'info',
- 'warning',
- 'danger',
- 'link'):
- button_class = button_class
- else:
- button_class = 'default'
-
- return {'save_text': save_text,
- 'button_class': button_class}
-
-
[email protected]_tag('tags/render_form_errors.html')
-def render_form_errors(form):
- """
- Renders the non-field errors of a form with all necessary HTML and CSS
- (non-field errors refer to errors that can't be associated to any single
- field)
-
- :param form: the form object
- """
- return {'form': form}
-
-
[email protected]_tag('tags/render_form_fields.html')
-def render_form_fields(form, submit_text='Save', show_save=True):
- """
- Comfort function that renders all fields in a form, as well as the submit
- button
-
- Internally it simply calls the other table_form_* functions and will render
- the fields in the order they were defined. If you want to change this, you
- need to call table_form_field for each field yourself. This function will
- also render a hidden field with a CSRF token, so be sure to pass it to the
- template.
-
- It is still necessary to enclose its output in <form> tags!
-
- :param form: the form to be rendered
- :param save_text: the text to use on the submit button
- """
-
- return {'form': form,
- 'show_save': show_save,
- 'submit_text': submit_text}
diff --git a/wger/exercises/templates/exercise/view.html b/wger/exercises/templates/exercise/view.html
index fd68e3e3f..3c07cc569 100644
--- a/wger/exercises/templates/exercise/view.html
+++ b/wger/exercises/templates/exercise/view.html
@@ -318,7 +318,7 @@ $(document).ready(function() {
{% if user.is_authenticated and not user.userprofile.is_temporary and not perms.exercises %}
<h4>{% trans "Options" %}</h4>
<p>
- <a href="{% url 'exercise:exercise:correct' exercise.id %}" {% auto_link_css request.user_agent.is_mobile %}>
+ <a href="{% url 'exercise:exercise:correct' exercise.id %}">
<span class="{% fa_class 'edit' %}"></span>
{% trans "Submit a correction" %}
</a>
diff --git a/wger/gym/templates/gym/new_user.html b/wger/gym/templates/gym/new_user.html
index 13aaa4f31..472d3e198 100644
--- a/wger/gym/templates/gym/new_user.html
+++ b/wger/gym/templates/gym/new_user.html
@@ -53,7 +53,7 @@ cannot be recovered later.{% endblocktrans %}
</p>
<p>
- <a href="{% url 'gym:gym:new-user-data-export' %}" {% auto_link_css request.user_agent.is_mobile %}>
+ <a href="{% url 'gym:gym:new-user-data-export' %}">
{% trans "Export user data" %}
</a>
</p>