app/soc/views/helper/templatetags/forms_helpers.py
changeset 785 c740d0129cce
parent 754 ed78bb93a287
child 794 19c24508c398
equal deleted inserted replaced
784:23eaf3aa19b1 785:c740d0129cce
   110 
   110 
   111   Args:
   111   Args:
   112     form: the form that should be converted to a table
   112     form: the form that should be converted to a table
   113   """
   113   """
   114 
   114 
       
   115   return as_table_helper(form)
       
   116 
       
   117 @register.inclusion_tag('soc/templatetags/_as_twoline_table.html')
       
   118 def as_twoline_table(form):
       
   119   """Outputs a form as a properly formatted html table
       
   120 
       
   121   Args:
       
   122     form: the form that should be converted to a table
       
   123   """
       
   124 
       
   125   return as_table_helper(form)
       
   126 
       
   127 def as_table_helper(form):
   115   fields = []
   128   fields = []
   116   hidden_fields = []
   129   hidden_fields = []
   117   hidden_fields_errors = []
   130   hidden_fields_errors = []
   118 
   131 
   119   # Iterate over all fields and prepare it for adding 
   132   # Iterate over all fields and prepare it for adding 
   153     field: the field that should be converted to a row
   166     field: the field that should be converted to a row
   154     required: whether the field is required
   167     required: whether the field is required
   155     example_text: the example_text for this row
   168     example_text: the example_text for this row
   156   """
   169   """
   157 
   170 
       
   171   return as_table_row_helper(form, field, required, example_text)
       
   172 
       
   173 @register.inclusion_tag('soc/templatetags/_as_twoline_table_row.html')
       
   174 def as_twoline_table_row(form, field, required, example_text):
       
   175   """Outputs a field as a properly formatted html row
       
   176 
       
   177   Args:
       
   178     form: the form that the row belongs to
       
   179     field: the field that should be converted to a row
       
   180     required: whether the field is required
       
   181     example_text: the example_text for this row
       
   182   """
       
   183 
       
   184   return as_table_row_helper(form, field, required, example_text)
       
   185 
       
   186 def as_table_row_helper(form, field, required, example_text):
   158   # Escape and cache in local variable.
   187   # Escape and cache in local variable.
   159   errors = [force_unicode(escape(error)) for error in field.errors]
   188   errors = [force_unicode(escape(error)) for error in field.errors]
   160 
   189 
   161   if field.label:
   190   if field.label:
   162     label = escape(force_unicode(field.label))
   191     label = escape(force_unicode(field.label))