app/soc/views/helper/templatetags/forms_helpers.py
changeset 273 b97d08ebac0e
parent 99 8c38b546a3cf
child 316 9efdc7bc3565
equal deleted inserted replaced
272:00cea07656c0 273:b97d08ebac0e
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """A Django template tag library containing forms helpers.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Todd Larsen" <tlarsen@google.com>',
       
    22   '"Pawel Solyga" <pawel.solyga@gmail.com>',
       
    23   ]
       
    24 
       
    25 
       
    26 from django import template
       
    27 register = template.Library()
       
    28 
       
    29 
       
    30 @register.inclusion_tag('soc/templatetags/_field_as_table_row.html')
       
    31 def field_as_table_row(field):
       
    32   """Prints a newforms field as a table row.
       
    33 
       
    34   This function actually does very little, simply passing the supplied
       
    35   form field instance in a simple context used by the _field_as_table_row.html
       
    36   template (which is actually doing all of the work).
       
    37 
       
    38   See soc/templates/soc/templatetags/_field_as_table_row.html for the CSS
       
    39   styles used by this template tag.
       
    40 
       
    41   Usage:
       
    42     {% load forms_helpers %}
       
    43     ...
       
    44     <table>
       
    45      {% field_as_table_row form.fieldname %}
       
    46      ...
       
    47     </table>
       
    48 
       
    49   Args:
       
    50     field: a Django newforms field instance
       
    51 
       
    52   Returns:
       
    53     a simple context containing the supplied newforms field instance:
       
    54       { 'field': field }
       
    55   """
       
    56   return {'field': field}
       
    57 
       
    58 
       
    59 @register.inclusion_tag('soc/templatetags/_readonly_field_as_table_row.html')
       
    60 def readonly_field_as_table_row(field_label, field_value):
       
    61   """Prints a field value and it's verbose name as a table row.
       
    62 
       
    63   This function actually does very little, simply passing the 
       
    64   supplied field_label and field_value in a simple context used by the 
       
    65   _readonly_field_as_table_row.html template (which is actually 
       
    66   doing all of the work).
       
    67 
       
    68   See soc/templates/soc/templatetags/_readonly_field_as_table_row.html for the CSS
       
    69   styles used by this template tag.
       
    70 
       
    71   Usage:
       
    72     {% load forms_helpers %}
       
    73     ...
       
    74     <table>
       
    75      {% readonly_field_as_table_row field_label field_value %}
       
    76      ...
       
    77     </table>
       
    78 
       
    79   Args:
       
    80     field_label: label of the field to render
       
    81     field_value: value of the field to render
       
    82 
       
    83   Returns:
       
    84     a simple context containing the supplied newforms field instance:
       
    85       { 'field_label': field_label',
       
    86         'field_value': field_value'}
       
    87   """
       
    88   return {'field_label': field_label,
       
    89           'field_value': field_value}
       
    90