Add an as_readonly_table filter
authorSverre Rabbelier <srabbelier@gmail.com>
Sun, 15 Feb 2009 14:56:30 +0000
changeset 1341 1b4b4a9ac17b
parent 1340 06ffdc68ab1b
child 1342 f8056a197fb8
Add an as_readonly_table filter Results in a very plain table, with no error messages etc. Intended use is in combination with PTW's. Patch by: Sverre Rabbelier
app/soc/templates/soc/templatetags/_as_readonly_table.html
app/soc/views/helper/templatetags/forms_helpers.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/templatetags/_as_readonly_table.html	Sun Feb 15 14:56:30 2009 +0000
@@ -0,0 +1,20 @@
+{% comment %}
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+{% load forms_helpers %}
+
+{% for field in fields %}
+  {% if field.as_widget %}
+    {% readonly_field_as_table_row field.label field %}
+  {% endif %}
+{% endfor %}
--- a/app/soc/views/helper/templatetags/forms_helpers.py	Sun Feb 15 14:55:53 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py	Sun Feb 15 14:56:30 2009 +0000
@@ -116,6 +116,21 @@
           'field_value': field_value}
 
 
+@register.inclusion_tag('soc/templatetags/_as_readonly_table.html',
+                        takes_context=True)
+def as_readonly_table(context, form):
+  """Outputs a form as a properly formatted html table.
+
+  Args:
+    form: the form that should be converted to a table
+  """
+
+  # create the bound fields
+  fields = [forms_in.BoundField(form, field, name) for name, field in
+            form.fields.items() if field]
+
+  return {'fields': fields}
+
 @register.inclusion_tag('soc/templatetags/_as_table.html', takes_context=True)
 def as_table(context, form):
   """Outputs a form as a properly formatted html table.