Create wtforms_util.render_label(_p) and use it around.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 22 Feb 2013 13:19:19 +0000 (14:19 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 22 Feb 2013 13:24:37 +0000 (14:24 +0100)
- This makes many places more readable.
- Gives us translation in two places.
- Allows easier changing of labels in a central place.

mediagoblin/templates/mediagoblin/edit/edit_account.html
mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html
mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html
mediagoblin/templates/mediagoblin/user_pages/media_collect.html
mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
mediagoblin/templates/mediagoblin/utils/wtforms.html

index 4b980301e2da360df06b214cfd56392523f96366..3f508af4937aac0a2263e87083acccdeae3a6905 100644 (file)
       {{ wtforms_util.render_field_div(form.new_password) }}
       <div class="form_field_input">
         <p>{{ form.wants_comment_notification }}
-           {{ form.wants_comment_notification.label }}</p>
+           {{ wtforms_util.render_label(form.wants_comment_notification) }}</p>
       </div>
       <div class="form_field_input">
         <p>{{ form.license_preference }}
-           {{ form.license_preference.label }}</p>
+           {{ wtforms_util.render_label(form.license_preference) }}</p>
       </div>
       <div class="form_submit_buttons">
         <input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
index 7499c0cf586f44a5c20785233f976b7417bfe658..2b790584aedeeb8904cae72468435f0fd8d679c5 100644 (file)
@@ -36,7 +36,7 @@
          
       <p class="delete_checkbox_box">
        {{ form.confirm }}
-       <label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label>
+       {{ wtforms_util.render_label(form.confirm) }}
       </p>
 
       <div class="form_submit_buttons">
index 447201cd6d113ef0c222f487f12cf92e7f8b624e..449cc3cea3a936647b4eb29e47fc27a79b864aa5 100644 (file)
@@ -42,7 +42,7 @@
 
       <p class="delete_checkbox_box">
        {{ form.confirm }}
-       <label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label>
+       {{ wtforms_util.render_label(form.confirm) }}
       </p>
 
       <div class="form_submit_buttons">
index 159eeeb4bfe4f44515c2717c1378a68f11da79b6..0fa0a9f4c613aa72fc5c8c60c78f7092362fb362 100644 (file)
@@ -48,9 +48,7 @@
 
       <br />
 
-      <p class="form_field_label">
-       <label for="{{ (form.collection.name) }}">{{ _(form.collection.label.text) }}</label>
-      </p>
+      {{- wtforms_util.render_label_p(form.collection) }}
       <div class="form_field_input">
        {{ form.collection }}
        <a class="button_action" id="button_addcollection">{% trans %}+{% endtrans %}</a>
index d2a5655e9b094a113e6e0685b51c763a9e2da1de..1d7dcc1701b921836db23944757747eaa1ef22a1 100644 (file)
@@ -40,7 +40,7 @@
 
       <p class="delete_checkbox_box">
        {{ form.confirm }}
-       <label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label>
+       {{ wtforms_util.render_label(form.confirm) }}
       </p>
 
       <div class="form_submit_buttons">
index df2354eda0e9c67e00dafc19166ab5327f22ea28..35b4aa0499bcac10ed87f1d30727fb797fd1b7ef 100644 (file)
 # 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 #}
 {% macro render_field_div(field) %}
-  {% if field.label.text -%}
-    <p class="form_field_label"><label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label></p>
-  {%- endif %}
+  {{- render_label_p(field) }}
   <div class="form_field_input">
     {{ field }}
     {%- if field.errors -%}