Skip to content

Commit

Permalink
Merge pull request #10 from clsdaniel/develop
Browse files Browse the repository at this point in the history
Add jinja2 widget templates
  • Loading branch information
ralphbean committed Aug 27, 2012
2 parents b0245f0 + 2755896 commit 975e663
Show file tree
Hide file tree
Showing 22 changed files with 229 additions and 1 deletion.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
recursive-include tw2/forms/static *
recursive-include tw2/forms/templates *.py
recursive-include tw2/forms/templates *.html
recursive-include tw2/forms/templates *.jinja
recursive-include tw2/forms/templates *.tmpl
recursive-include tw2/forms/templates *.kid
recursive-include tw2/forms/templates *.mak
Expand Down
2 changes: 1 addition & 1 deletion tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WidgetTest(_WidgetTest):
the first two since those are the only templates provided by tw2.forms
itself.
"""
engines = ['mako', 'genshi']
engines = ['mako', 'genshi', 'jinja']


class TestInputField(WidgetTest):
Expand Down
11 changes: 11 additions & 0 deletions tw2/forms/templates/calendar.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
<input type="text" id="{{ w.compound_id }}" name="{{ w.name }}" class="{{ w.css_class or '' }}" value="{{ w.strdate or '' }}" />
<input type="button" id="{{ w.compound_id }}_trigger" class="date_field_button" value="{{ w.button_text }}" />
<script type="text/javascript">Calendar.setup({
"inputField": "{{ w.compound_id }}", "showsTime": {{ w.picker_shows_time | lower }},
"ifFormat": "{{ w.date_format }}", "button": "{{ w.compound_id }}_trigger"
{% for k, v in w.setup_options.items %}
, {{ k }}: {{ isinstance(v, twc.JSSymbol) and (v.src) or '"%s"' % v }}
{% endfor %}
})</script>
</div>
23 changes: 23 additions & 0 deletions tw2/forms/templates/datagrid.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<table {{ w.attrs|xmlattr }} cellpadding="0" cellspacing="1" border="0">
{% if w.columns %}
<thead>
<tr>
{% for i, col in enumerate(w.columns) %}
<th class="col_{{ i|string }}">{{ col.title }}</th>
{% endfor %}
</tr>
</thead>
{% endif %}

<tbody>
{% for i, row in enumerate(w.value) %}
<tr class="{{ i%2 and 'odd' or 'even' }}">
{% for col in w.columns %}
<td {{
{'align': col.get_option('align', None),
'class': col.get_option('css_class', None)} | xmlattr }}>{{ col.get_field(row) }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>\
4 changes: 4 additions & 0 deletions tw2/forms/templates/fieldset.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<fieldset {{ w.attrs|xmlattr }}>
<legend>{{ w.legend or '' }}</legend>
{{ w.child.display() }}
</fieldset>
14 changes: 14 additions & 0 deletions tw2/forms/templates/form.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<form {{ w.attrs|xmlattr }}>
<span class="error">{{ w.error_msg or '' }}</span>
{% if w.help_msg %}
<div class="help">
<p>
{{ w.help_msg }}
</p>
</div>
{% endif %}
{{ w.child.display() }}
{% for button in w.buttons %}
{{ button.display() }}
{% endfor %}
</form>
13 changes: 13 additions & 0 deletions tw2/forms/templates/grid_layout.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<table {{ w.attrs|xmlattr }}>
<tr>
{% for col in w.children[0].children_non_hidden %}
<th>{{ col.label | string }}</th>
{% endfor %}
</tr>
{% for row in w.children %}
{{ row.display }}
{% endfor %}
<tr class="error"><td colspan="{{ w.children|length }}" id="{{ w.compound_id or '' }}:error">
{{ w.error_msg or '' }}
</td></tr>
</table>
1 change: 1 addition & 0 deletions tw2/forms/templates/input_field.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input {{ w.attrs|htmlbools|xmlattr }}/>
1 change: 1 addition & 0 deletions tw2/forms/templates/label.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span {{ w.attrs|xmlattr }}>{{ w.text }}</span>
1 change: 1 addition & 0 deletions tw2/forms/templates/label_field.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span>{{ w.value|string }}<input {{ w.attrs|xmlattr }}/></span>
1 change: 1 addition & 0 deletions tw2/forms/templates/link_field.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a {{ w.attrs|xmlattr }}>{{ w.text }}</a>
18 changes: 18 additions & 0 deletions tw2/forms/templates/list_layout.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<ul {{ w.attrs|xmlattr }}>
{% for c in w.children_hidden %}
{{ c.display() }}
{% endfor %}
{% for c in w.children_non_hidden %}
<li class="{{ loop.index0 % 2 and 'even' or 'odd' }}{{ c|attr(' required') and ' required' or '' }}{{ c.error_msg and ' error' or '' }}" {% if w.hover_help and c.help_text %}title="{{ c.help_text }}"{% endif %} {{ c.container_attrs|xmlattr }}>
<label>{{ c.label or '' }}</label>
{{ c.display() }}
{% if not w.hover_help %}{{ c.help_text or '' }}{% endif %}
<span id="{{ c.compound_id or '' }}:error" class="error">{{ c.error_msg or '' }}</span>
</li>
{% endfor %}
<li class="error"><span id="{{ w.compound_id or '' }}:error" class="error">
{% for error in w.rollup_errors %}
<p>{{ error }}</p>
{% endfor %}
</span></li>
</ul>
1 change: 1 addition & 0 deletions tw2/forms/templates/postlabeled_input_field.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input {{ w.attrs|xmlattr }}/> <label for='{{ w.compound_id }}' {{ w.text_attrs|xmlattr }}>{{ w.text }}</label>
18 changes: 18 additions & 0 deletions tw2/forms/templates/row_layout.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<tr {{ w.attrs|xmlattr }}>
{% for c in w.children_non_hidden %}
<td>
{{ c.display() }}
{% if c.error_msg %}
<img src="{{ w.resources.error.link }}" title="{{ c.error_msg }}"/>
{% endif %}
</td>
{% endfor %}
<td>
{% for c in w.children_hidden %}
{{ c.display() }}
{% endfor %}
{% if w.error_msg %}
<img src="{{ w.resources.error.link }}" title="{{ w.error_msg }}"/>
{% endif %}
</td>
</tr>
13 changes: 13 additions & 0 deletions tw2/forms/templates/select_field.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<select {{ w.attrs|xmlattr }}>
{% for group, options in w.grouped_options %}
{% if group %}
<optgroup {{ {'label': group}|xmlattr }}>
{% endif %}
{% for attrs, desc in options %}
<option {% if attrs %}{{ attrs|xmlattr }}{% endif %}>{{ desc }}</option>
{% endfor %}
{% if group %}
</optgroup>
{% endif %}
{% endfor %}
</select>
19 changes: 19 additions & 0 deletions tw2/forms/templates/selection_list.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<ul {{ w.attrs|xmlattr }}>
{% for group, opts in w.grouped_options %}
{% if group %}
<li>
<div class="group_header">{{ group }}</div>
<ul>
{% endif %}
{% for attrs, desc in opts %}
<li>
<input {{ attrs|xmlattr }}/>
<label for="{{ attrs['id'] }}">{{ desc }}</label>
</li>
{% endfor %}
{% if group %}
</li>
</ul>
{% endif %}
{% endfor %}
</ul>
17 changes: 17 additions & 0 deletions tw2/forms/templates/selection_table.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<table {{ w.attrs|xmlattr }}>
<tbody>
{% for row in w.options_rows %}
<tr>
{% for attrs, desc in row %}
<td>
<input {{ attrs|xmlattr }} />
<label for="{{ attrs['id'] }}">{{ desc }}</label>
</td>
{% endfor %}
{% for j in range(w.cols - row|length) %}
<td/>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
8 changes: 8 additions & 0 deletions tw2/forms/templates/separated_selection_table.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<table {{ w.attrs|xmlattr }}>
{% for attrs, desc in w.options %}
<tr>
<td><input {{ attrs|xmlattr }}/></td>
<td><label for="{{ attrs['id'] }}">{{ desc }}</label></td>
</tr>
{% endfor %}
</table>
1 change: 1 addition & 0 deletions tw2/forms/templates/spacer.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>&nbsp;</div>
32 changes: 32 additions & 0 deletions tw2/forms/templates/table_layout.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<table {{ w.attrs|xmlattr }}>
{% for c in w.children_non_hidden %}
<tr class="{{ loop.index0 % 2 and 'even' or 'odd' }}{{ c|attr('required') and ' required' or '' }}{{ c.error_msg and ' error' or '' }}"
{% if w.hover_help and c.help_text %}title="{{ c.help_text }}"{% endif %}
{{ c.container_attrs|xmlattr }}
id="{{ c.compound_id }}:container">

{% if c.label %}
<th>{{ c.label }}</th>
{% endif %}

<td
{% if not c.label %}
colspan="2"
{% endif %}>
{{ c.display() }}

{% if not w.hover_help %}
{{ c.help_text or '' }}
{% endif %}
<span id="{{ c.compound_id or '' }}:error">{{ c.error_msg or ''}}</span>
</td>
</tr>
{% endfor %}

<tr class="error"><td colspan="2">
{% for c in w.children_hidden %}
{{ c.display() }}
{% endfor %}
<span id="{{ w.compound_id or '' }}:error">{{ w.error_msg or '' }}</span>
</td></tr>
</table>
1 change: 1 addition & 0 deletions tw2/forms/templates/textarea.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<textarea {{ w.attrs|xmlattr }}>{{ w.value or '' }}</textarea>
30 changes: 30 additions & 0 deletions tw2/forms/templates/vertical_selection_table.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<table {{ w.attrs|xmlattr }}>
{% if w.grouped_options[0][0] %}
<thead>
<tr>
{% for group_name, options in w.grouped_options %}
<th>{{ group_name }}</th>
{% endfor %}
</tr>
</thead>
{% endif %}
<tbody>
{% for row in w.options_rows %}
<tr>
{% for attrs, desc in row %}
{% if attrs and desc %}
<td>
<input {{ attrs|xmlattr }} />
<label for="{{ attrs['id'] }}">{{ desc }}</label>
</td>
{% else %}
<td/>
{% endif %}
{% endfor %}
{% for j in range(w.cols - len(row)) %}
<td/>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

0 comments on commit 975e663

Please sign in to comment.