From 68953a7548f88e71e0ef96dfb38a411edd4f073b Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Sat, 4 Aug 2012 08:41:31 -0700 Subject: [PATCH 1/4] Added equivalent Jinja2 widget templates --- tw2/forms/templates/calendar.jinja | 11 +++++++ tw2/forms/templates/datagrid.jinja | 23 +++++++++++++ tw2/forms/templates/fieldset.jinja | 4 +++ tw2/forms/templates/form.jinja | 14 ++++++++ tw2/forms/templates/grid_layout.jinja | 13 ++++++++ tw2/forms/templates/input_field.jinja | 1 + tw2/forms/templates/label.jinja | 1 + tw2/forms/templates/label_field.jinja | 1 + tw2/forms/templates/link_field.jinja | 1 + tw2/forms/templates/list_layout.jinja | 18 +++++++++++ .../templates/postlabeled_input_field.jinja | 1 + tw2/forms/templates/row_layout.jinja | 18 +++++++++++ tw2/forms/templates/select_field.jinja | 13 ++++++++ tw2/forms/templates/selection_list.jinja | 19 +++++++++++ tw2/forms/templates/selection_table.jinja | 17 ++++++++++ .../templates/separated_selection_table.jinja | 8 +++++ tw2/forms/templates/spacer.jinja | 1 + tw2/forms/templates/table_layout.jinja | 32 +++++++++++++++++++ tw2/forms/templates/textarea.jinja | 1 + .../templates/vertical_selection_table.jinja | 30 +++++++++++++++++ 20 files changed, 227 insertions(+) create mode 100644 tw2/forms/templates/calendar.jinja create mode 100644 tw2/forms/templates/datagrid.jinja create mode 100644 tw2/forms/templates/fieldset.jinja create mode 100644 tw2/forms/templates/form.jinja create mode 100644 tw2/forms/templates/grid_layout.jinja create mode 100644 tw2/forms/templates/input_field.jinja create mode 100644 tw2/forms/templates/label.jinja create mode 100644 tw2/forms/templates/label_field.jinja create mode 100644 tw2/forms/templates/link_field.jinja create mode 100644 tw2/forms/templates/list_layout.jinja create mode 100644 tw2/forms/templates/postlabeled_input_field.jinja create mode 100644 tw2/forms/templates/row_layout.jinja create mode 100644 tw2/forms/templates/select_field.jinja create mode 100644 tw2/forms/templates/selection_list.jinja create mode 100644 tw2/forms/templates/selection_table.jinja create mode 100644 tw2/forms/templates/separated_selection_table.jinja create mode 100644 tw2/forms/templates/spacer.jinja create mode 100644 tw2/forms/templates/table_layout.jinja create mode 100644 tw2/forms/templates/textarea.jinja create mode 100644 tw2/forms/templates/vertical_selection_table.jinja diff --git a/tw2/forms/templates/calendar.jinja b/tw2/forms/templates/calendar.jinja new file mode 100644 index 0000000..65ce742 --- /dev/null +++ b/tw2/forms/templates/calendar.jinja @@ -0,0 +1,11 @@ +
+ + + +
\ No newline at end of file diff --git a/tw2/forms/templates/datagrid.jinja b/tw2/forms/templates/datagrid.jinja new file mode 100644 index 0000000..35b648d --- /dev/null +++ b/tw2/forms/templates/datagrid.jinja @@ -0,0 +1,23 @@ + + {% if w.columns %} + + + {% for i, col in enumerate(w.columns) %} + + {% endfor %} + + + {% endif %} + + + {% for i, row in enumerate(w.value) %} + + {% for col in w.columns %} + + {% endfor %} + + {% endfor %} + +
{{ col.title }}
{{ col.get_field(row) }}
\ diff --git a/tw2/forms/templates/fieldset.jinja b/tw2/forms/templates/fieldset.jinja new file mode 100644 index 0000000..248fffb --- /dev/null +++ b/tw2/forms/templates/fieldset.jinja @@ -0,0 +1,4 @@ +
+ {{ w.legend or '' }} + {{ w.child.display() }} +
diff --git a/tw2/forms/templates/form.jinja b/tw2/forms/templates/form.jinja new file mode 100644 index 0000000..76de4ab --- /dev/null +++ b/tw2/forms/templates/form.jinja @@ -0,0 +1,14 @@ +
+ {{ w.error_msg or '' }} + {% if w.help_msg %} +
+

+ {{ w.help_msg }} +

+
+ {% endif %} + {{ w.child.display() }} + {% for button in w.buttons %} + {{ button.display() }} + {% endfor %} +
diff --git a/tw2/forms/templates/grid_layout.jinja b/tw2/forms/templates/grid_layout.jinja new file mode 100644 index 0000000..6f3c88d --- /dev/null +++ b/tw2/forms/templates/grid_layout.jinja @@ -0,0 +1,13 @@ + + +{% for col in w.children[0].children_non_hidden %} + +{% endfor %} + +{% for row in w.children %} + {{ row.display }} +{% endfor %} + +
{{ col.label | string }}
+ {{ w.error_msg or '' }} +
diff --git a/tw2/forms/templates/input_field.jinja b/tw2/forms/templates/input_field.jinja new file mode 100644 index 0000000..e36a817 --- /dev/null +++ b/tw2/forms/templates/input_field.jinja @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tw2/forms/templates/label.jinja b/tw2/forms/templates/label.jinja new file mode 100644 index 0000000..4a1658f --- /dev/null +++ b/tw2/forms/templates/label.jinja @@ -0,0 +1 @@ +{{ w.text }} \ No newline at end of file diff --git a/tw2/forms/templates/label_field.jinja b/tw2/forms/templates/label_field.jinja new file mode 100644 index 0000000..4f18ad9 --- /dev/null +++ b/tw2/forms/templates/label_field.jinja @@ -0,0 +1 @@ +{{ w.value|string }} \ No newline at end of file diff --git a/tw2/forms/templates/link_field.jinja b/tw2/forms/templates/link_field.jinja new file mode 100644 index 0000000..c8165d5 --- /dev/null +++ b/tw2/forms/templates/link_field.jinja @@ -0,0 +1 @@ +{{ w.text }} \ No newline at end of file diff --git a/tw2/forms/templates/list_layout.jinja b/tw2/forms/templates/list_layout.jinja new file mode 100644 index 0000000..215ded7 --- /dev/null +++ b/tw2/forms/templates/list_layout.jinja @@ -0,0 +1,18 @@ + diff --git a/tw2/forms/templates/postlabeled_input_field.jinja b/tw2/forms/templates/postlabeled_input_field.jinja new file mode 100644 index 0000000..a313ec8 --- /dev/null +++ b/tw2/forms/templates/postlabeled_input_field.jinja @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tw2/forms/templates/row_layout.jinja b/tw2/forms/templates/row_layout.jinja new file mode 100644 index 0000000..16e926a --- /dev/null +++ b/tw2/forms/templates/row_layout.jinja @@ -0,0 +1,18 @@ + + {% for c in w.children_non_hidden %} + + {{ c.display() }} + {% if c.error_msg %} + + {% endif %} + + {% endfor %} + + {% for c in w.children_hidden %} + {{ c.display() }} + {% endfor %} + {% if w.error_msg %} + + {% endif %} + + diff --git a/tw2/forms/templates/select_field.jinja b/tw2/forms/templates/select_field.jinja new file mode 100644 index 0000000..6b5dbe3 --- /dev/null +++ b/tw2/forms/templates/select_field.jinja @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/tw2/forms/templates/selection_list.jinja b/tw2/forms/templates/selection_list.jinja new file mode 100644 index 0000000..828198c --- /dev/null +++ b/tw2/forms/templates/selection_list.jinja @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/tw2/forms/templates/selection_table.jinja b/tw2/forms/templates/selection_table.jinja new file mode 100644 index 0000000..f1ba8f1 --- /dev/null +++ b/tw2/forms/templates/selection_table.jinja @@ -0,0 +1,17 @@ + + + {% for row in w.options_rows %} + + {% for attrs, desc in row %} + + {% endfor %} + {% for j in range(w.cols - row|length) %} + + {% endfor %} + +
+ + + + {% endfor %} +
diff --git a/tw2/forms/templates/separated_selection_table.jinja b/tw2/forms/templates/separated_selection_table.jinja new file mode 100644 index 0000000..94172bc --- /dev/null +++ b/tw2/forms/templates/separated_selection_table.jinja @@ -0,0 +1,8 @@ + + {% for attrs, desc in w.options %} + + + + + {% endfor %} +
\ No newline at end of file diff --git a/tw2/forms/templates/spacer.jinja b/tw2/forms/templates/spacer.jinja new file mode 100644 index 0000000..171e792 --- /dev/null +++ b/tw2/forms/templates/spacer.jinja @@ -0,0 +1 @@ +
 
\ No newline at end of file diff --git a/tw2/forms/templates/table_layout.jinja b/tw2/forms/templates/table_layout.jinja new file mode 100644 index 0000000..b1e7f2c --- /dev/null +++ b/tw2/forms/templates/table_layout.jinja @@ -0,0 +1,32 @@ + + {% for c in w.children_non_hidden %} + + + {% if c.label %} + + {% endif %} + + + + {% endfor %} + + +
{{ c.label }} + {{ c.display() }} + + {% if not w.hover_help %} + {{ c.help_text or '' }} + {% endif %} + {{ c.error_msg or ''}} +
+ {% for c in w.children_hidden %} + {{ c.display() }} + {% endfor %} + {{ w.error_msg or '' }} +
diff --git a/tw2/forms/templates/textarea.jinja b/tw2/forms/templates/textarea.jinja new file mode 100644 index 0000000..f162526 --- /dev/null +++ b/tw2/forms/templates/textarea.jinja @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tw2/forms/templates/vertical_selection_table.jinja b/tw2/forms/templates/vertical_selection_table.jinja new file mode 100644 index 0000000..35a07ef --- /dev/null +++ b/tw2/forms/templates/vertical_selection_table.jinja @@ -0,0 +1,30 @@ + + {% if w.grouped_options[0][0] %} + + + {% for group_name, options in w.grouped_options %} + + {% endfor %} + + + {% endif %} + + {% for row in w.options_rows %} + + {% for attrs, desc in row %} + {% if attrs and desc %} + + {% else %} + + {% endfor %} + +
{{ group_name }}
+ + + + {% endif %} + {% endfor %} + {% for j in range(w.cols - len(row)) %} + + {% endfor %} +
From 0621be35f863a37f6afe79019e7ed27be5feb02f Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Sat, 4 Aug 2012 08:42:25 -0700 Subject: [PATCH 2/4] Turned on jinja2 templates on widgets unittests --- tests/test_widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index b3b3930..7e8ec28 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -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): From 42e1f8867f626e84b343c4fe8ce8c22270910485 Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Sat, 4 Aug 2012 10:23:25 -0700 Subject: [PATCH 3/4] Updated manifest to include jinja templates --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index edca56f..48cbe91 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 From 2755896bb38c743d8c52578f6ed9bbdda51ae5f2 Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Sat, 4 Aug 2012 11:26:53 -0700 Subject: [PATCH 4/4] Used htmlbools filter from tw2.core.jinja_utils to take care of special case html boolean attributes such as radio 'checked', jinja templates now passes all tests. --- tw2/forms/templates/input_field.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tw2/forms/templates/input_field.jinja b/tw2/forms/templates/input_field.jinja index e36a817..69ceb64 100644 --- a/tw2/forms/templates/input_field.jinja +++ b/tw2/forms/templates/input_field.jinja @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file