Merge remote branch 'remotes/elrond/dev/init'
[mediagoblin.git] / mediagoblin / templates / mediagoblin / utils / wtforms.html
1 {#
2 # GNU MediaGoblin -- federated, autonomous media hosting
3 # Copyright (C) 2011 Free Software Foundation, Inc
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #}
18
19 {# Generically render a field #}
20 {% macro render_field_div(field) %}
21 <div class="form_field_box">
22 <div class="form_field_label">{{ field.label }}</div>
23 {% if field.description -%}
24 <div class="form_field_description">{{ field.description }}</div>
25 {%- endif %}
26 <div class="form_field_input">{{ field }}</div>
27 {%- if field.errors -%}
28 {% for error in field.errors %}
29 <div class="form_field_error">
30 {{ error }}
31 </div>
32 {% endfor %}
33 {%- endif %}
34 </div>
35 {%- endmacro %}
36
37 {# Generically render a textarea
38 # ... mostly the same thing except it includes rows and cols #}
39 {% macro render_textarea_div(field, rows=8, cols=20) %}
40 <div class="form_field_box">
41 <div class="form_field_label">{{ field.label }}</div>
42 {% if field.description -%}
43 <div class="form_field_description">{{ field.description }}</div>
44 {%- endif %}
45 <div class="form_field_input">{{ field(rows=rows, cols=cols) }}</div>
46 {%- if field.errors -%}
47 {% for error in field.errors %}
48 <div class="form_field_error">
49 {{ error }}
50 </div>
51 {% endfor %}
52 {%- endif %}
53 </div>
54 {%- endmacro %}
55
56 {# Auto-render a form as a series of divs #}
57 {% macro render_divs(form) -%}
58 {% for field in form %}
59 {{ render_field_div(field) }}
60 {% endfor %}
61 {%- endmacro %}
62
63 {# Auto-render a form as a table #}
64 {% macro render_table(form) -%}
65 {% for field in form %}
66 <tr>
67 <th>{{field.label}}</th>
68 <td>
69 {{field}}
70 {% if field.errors %}
71 <br />
72 <ul class="errors">
73 {% for error in field.errors %}
74 <li>{{error}}</li>
75 {% endfor %}
76 </ul>
77 {% endif %}
78 </td>
79 </tr>
80 {% endfor %}
81 {%- endmacro %}