Create wtforms_util.render_label(_p) and use it around.

- This makes many places more readable.
- Gives us translation in two places.
- Allows easier changing of labels in a central place.
This commit is contained in:
Elrond 2013-02-22 14:19:19 +01:00
parent d647b62699
commit cde7a07d5e
6 changed files with 23 additions and 11 deletions

View File

@ -45,11 +45,11 @@
{{ wtforms_util.render_field_div(form.new_password) }} {{ wtforms_util.render_field_div(form.new_password) }}
<div class="form_field_input"> <div class="form_field_input">
<p>{{ form.wants_comment_notification }} <p>{{ form.wants_comment_notification }}
{{ form.wants_comment_notification.label }}</p> {{ wtforms_util.render_label(form.wants_comment_notification) }}</p>
</div> </div>
<div class="form_field_input"> <div class="form_field_input">
<p>{{ form.license_preference }} <p>{{ form.license_preference }}
{{ form.license_preference.label }}</p> {{ wtforms_util.render_label(form.license_preference) }}</p>
</div> </div>
<div class="form_submit_buttons"> <div class="form_submit_buttons">
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" /> <input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />

View File

@ -36,7 +36,7 @@
<p class="delete_checkbox_box"> <p class="delete_checkbox_box">
{{ form.confirm }} {{ form.confirm }}
<label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label> {{ wtforms_util.render_label(form.confirm) }}
</p> </p>
<div class="form_submit_buttons"> <div class="form_submit_buttons">

View File

@ -42,7 +42,7 @@
<p class="delete_checkbox_box"> <p class="delete_checkbox_box">
{{ form.confirm }} {{ form.confirm }}
<label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label> {{ wtforms_util.render_label(form.confirm) }}
</p> </p>
<div class="form_submit_buttons"> <div class="form_submit_buttons">

View File

@ -48,9 +48,7 @@
<br /> <br />
<p class="form_field_label"> {{- wtforms_util.render_label_p(form.collection) }}
<label for="{{ (form.collection.name) }}">{{ _(form.collection.label.text) }}</label>
</p>
<div class="form_field_input"> <div class="form_field_input">
{{ form.collection }} {{ form.collection }}
<a class="button_action" id="button_addcollection">{% trans %}+{% endtrans %}</a> <a class="button_action" id="button_addcollection">{% trans %}+{% endtrans %}</a>

View File

@ -40,7 +40,7 @@
<p class="delete_checkbox_box"> <p class="delete_checkbox_box">
{{ form.confirm }} {{ form.confirm }}
<label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label> {{ wtforms_util.render_label(form.confirm) }}
</p> </p>
<div class="form_submit_buttons"> <div class="form_submit_buttons">

View File

@ -16,11 +16,25 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
{# Render the label for a field #}
{% macro render_label(field) %}
{%- if field.label.text -%}
<label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label>
{%- endif -%}
{%- endmacro %}
{# Render the label in a <p> for a field #}
{% macro render_label_p(field) %}
{%- if field.label.text %}
<p class="form_field_label">
{{- render_label(field) -}}
</p>
{%- endif %}
{%- endmacro %}
{# Generically render a field #} {# Generically render a field #}
{% macro render_field_div(field) %} {% macro render_field_div(field) %}
{% if field.label.text -%} {{- render_label_p(field) }}
<p class="form_field_label"><label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label></p>
{%- endif %}
<div class="form_field_input"> <div class="form_field_input">
{{ field }} {{ field }}
{%- if field.errors -%} {%- if field.errors -%}