app/soc/views/helper/templatetags/forms_helpers.py
changeset 835 1590625ead55
parent 794 19c24508c398
child 935 09f47e08f805
equal deleted inserted replaced
834:b60c9ccbeaa5 835:1590625ead55
    92         'field_value': field_value'}
    92         'field_value': field_value'}
    93   """
    93   """
    94   return {'field_label': field_label,
    94   return {'field_label': field_label,
    95           'field_value': field_value}
    95           'field_value': field_value}
    96 
    96 
       
    97 
    97 @register.inclusion_tag('soc/templatetags/_readonly_field_as_twoline_table_row.html')
    98 @register.inclusion_tag('soc/templatetags/_readonly_field_as_twoline_table_row.html')
    98 def readonly_field_as_twoline_table_row(field_label, field_value):
    99 def readonly_field_as_twoline_table_row(field_label, field_value):
    99   """See readonly_field_as_table_row().
   100   """See readonly_field_as_table_row().
   100   """
   101   """
   101   return {'field_label': field_label,
   102   return {'field_label': field_label,
   111           'field_value': field_value}
   112           'field_value': field_value}
   112 
   113 
   113 
   114 
   114 @register.inclusion_tag('soc/templatetags/_as_table.html')
   115 @register.inclusion_tag('soc/templatetags/_as_table.html')
   115 def as_table(form):
   116 def as_table(form):
   116   """Outputs a form as a properly formatted html table
   117   """Outputs a form as a properly formatted html table.
   117 
   118 
   118   Args:
   119   Args:
   119     form: the form that should be converted to a table
   120     form: the form that should be converted to a table
   120   """
   121   """
   121 
   122 
   122   return as_table_helper(form)
   123   return as_table_helper(form)
       
   124 
   123 
   125 
   124 @register.inclusion_tag('soc/templatetags/_as_twoline_table.html')
   126 @register.inclusion_tag('soc/templatetags/_as_twoline_table.html')
   125 def as_twoline_table(form):
   127 def as_twoline_table(form):
   126   """Outputs a form as a properly formatted html table
   128   """Outputs a form as a properly formatted html table.
   127 
   129 
   128   Args:
   130   Args:
   129     form: the form that should be converted to a table
   131     form: the form that should be converted to a table
   130   """
   132   """
   131 
   133 
   132   return as_table_helper(form)
   134   return as_table_helper(form)
       
   135 
   133 
   136 
   134 def as_table_helper(form):
   137 def as_table_helper(form):
   135   fields = []
   138   fields = []
   136   hidden_fields = []
   139   hidden_fields = []
   137   hidden_fields_errors = []
   140   hidden_fields_errors = []
   164       }
   167       }
   165 
   168 
   166 
   169 
   167 @register.inclusion_tag('soc/templatetags/_as_table_row.html')
   170 @register.inclusion_tag('soc/templatetags/_as_table_row.html')
   168 def as_table_row(form, field, required, example_text):
   171 def as_table_row(form, field, required, example_text):
   169   """Outputs a field as a properly formatted html row
   172   """Outputs a field as a properly formatted html row.
   170 
   173 
   171   Args:
   174   Args:
   172     form: the form that the row belongs to
   175     form: the form that the row belongs to
   173     field: the field that should be converted to a row
   176     field: the field that should be converted to a row
   174     required: whether the field is required
   177     required: whether the field is required
   175     example_text: the example_text for this row
   178     example_text: the example_text for this row
   176   """
   179   """
   177 
   180 
   178   return as_table_row_helper(form, field, required, example_text)
   181   return as_table_row_helper(form, field, required, example_text)
   179 
   182 
       
   183 
   180 @register.inclusion_tag('soc/templatetags/_as_twoline_table_row.html')
   184 @register.inclusion_tag('soc/templatetags/_as_twoline_table_row.html')
   181 def as_twoline_table_row(form, field, required, example_text):
   185 def as_twoline_table_row(form, field, required, example_text):
   182   """Outputs a field as a properly formatted html row
   186   """Outputs a field as a properly formatted html row.
   183 
   187 
   184   Args:
   188   Args:
   185     form: the form that the row belongs to
   189     form: the form that the row belongs to
   186     field: the field that should be converted to a row
   190     field: the field that should be converted to a row
   187     required: whether the field is required
   191     required: whether the field is required
   188     example_text: the example_text for this row
   192     example_text: the example_text for this row
   189   """
   193   """
   190 
   194 
   191   return as_table_row_helper(form, field, required, example_text)
   195   return as_table_row_helper(form, field, required, example_text)
       
   196 
   192 
   197 
   193 def as_table_row_helper(form, field, required, example_text):
   198 def as_table_row_helper(form, field, required, example_text):
   194   # Escape and cache in local variable.
   199   # Escape and cache in local variable.
   195   errors = [force_unicode(escape(error)) for error in field.errors]
   200   errors = [force_unicode(escape(error)) for error in field.errors]
   196 
   201