app/soc/views/helper/templatetags/forms_helpers.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 24 Jan 2009 12:54:59 +0000
changeset 959 b6e8750c9407
parent 935 09f47e08f805
child 1214 7fb705534dd1
permissions -rw-r--r--
Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide. Patch by: Pawel Solyga Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""A Django template tag library containing forms helpers.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
99
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    22
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
    23
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
38
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
  ]
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
    27
from google.appengine.ext import db
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
    28
38
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
from django import template
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
    30
from django.forms import forms as forms_in
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
    31
from django.utils.encoding import force_unicode
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
    32
from django.utils.html import escape
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 273
diff changeset
    33
322
6641e941ef1e Fixed imports sorting based on comments for r751.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    34
38
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
register = template.Library()
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
@register.inclusion_tag('soc/templatetags/_field_as_table_row.html')
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
def field_as_table_row(field):
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
  """Prints a newforms field as a table row.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
  This function actually does very little, simply passing the supplied
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
  form field instance in a simple context used by the _field_as_table_row.html
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  template (which is actually doing all of the work).
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
  See soc/templates/soc/templatetags/_field_as_table_row.html for the CSS
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
  styles used by this template tag.
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
  Usage:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
    {% load forms_helpers %}
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
    ...
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
    <table>
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
     {% field_as_table_row form.fieldname %}
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
     ...
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
    </table>
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
  Args:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
    field: a Django newforms field instance
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
  Returns:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
    a simple context containing the supplied newforms field instance:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
      { 'field': field }
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
  """
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
  return {'field': field}
99
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    65
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    66
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    67
@register.inclusion_tag('soc/templatetags/_readonly_field_as_table_row.html')
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    68
def readonly_field_as_table_row(field_label, field_value):
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    69
  """Prints a field value and it's verbose name as a table row.
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    70
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    71
  This function actually does very little, simply passing the 
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    72
  supplied field_label and field_value in a simple context used by the 
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    73
  _readonly_field_as_table_row.html template (which is actually 
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    74
  doing all of the work).
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    75
744
cd9bf163473c Add missing dots, fix imports sorting and too long lines in different modules. Add TODO in soc.views.models.host module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 741
diff changeset
    76
  See soc/templates/soc/templatetags/_readonly_field_as_table_row.html for
cd9bf163473c Add missing dots, fix imports sorting and too long lines in different modules. Add TODO in soc.views.models.host module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 741
diff changeset
    77
  the CSS styles used by this template tag.
99
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    78
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    79
  Usage:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    80
    {% load forms_helpers %}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    81
    ...
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    82
    <table>
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    83
     {% readonly_field_as_table_row field_label field_value %}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    84
     ...
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    85
    </table>
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    86
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    87
  Args:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    88
    field_label: label of the field to render
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    89
    field_value: value of the field to render
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    90
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    91
  Returns:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    92
    a simple context containing the supplied newforms field instance:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    93
      { 'field_label': field_label',
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    94
        'field_value': field_value'}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    95
  """
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    96
  return {'field_label': field_label,
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    97
          'field_value': field_value}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    98
835
1590625ead55 Add missing blank lines and dots in soc.views.helper.templatetags.forms_helpers module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 794
diff changeset
    99
794
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   100
@register.inclusion_tag('soc/templatetags/_readonly_field_as_twoline_table_row.html')
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   101
def readonly_field_as_twoline_table_row(field_label, field_value):
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   102
  """See readonly_field_as_table_row().
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   103
  """
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   104
  return {'field_label': field_label,
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   105
          'field_value': field_value}
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   106
728
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   107
744
cd9bf163473c Add missing dots, fix imports sorting and too long lines in different modules. Add TODO in soc.views.models.host module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 741
diff changeset
   108
@register.inclusion_tag(
cd9bf163473c Add missing dots, fix imports sorting and too long lines in different modules. Add TODO in soc.views.models.host module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 741
diff changeset
   109
    'soc/templatetags/_readonly_multiline_field_as_table_row.html')
728
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   110
def readonly_multiline_field_as_table_row(field_label, field_value):
744
cd9bf163473c Add missing dots, fix imports sorting and too long lines in different modules. Add TODO in soc.views.models.host module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 741
diff changeset
   111
  """See readonly_field_as_table_row, but with a different template tag.
728
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   112
  """
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   113
  return {'field_label': field_label,
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   114
          'field_value': field_value}
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   115
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   116
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   117
@register.inclusion_tag('soc/templatetags/_as_table.html', takes_context=True)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   118
def as_table(context, form):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   119
  """Outputs a form as a properly formatted html table.
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   120
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   121
  Args:
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   122
    form: the form that should be converted to a table
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   123
  """
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   124
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   125
  return as_table_helper(context, form)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   126
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   127
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   128
@register.inclusion_tag('soc/templatetags/_as_twoline_table.html',
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   129
                        takes_context=True)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   130
def as_twoline_table(context, form):
835
1590625ead55 Add missing blank lines and dots in soc.views.helper.templatetags.forms_helpers module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 794
diff changeset
   131
  """Outputs a form as a properly formatted html table.
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   132
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   133
  Args:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   134
    form: the form that should be converted to a table
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   135
  """
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   136
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   137
  return as_table_helper(context, form)
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   138
835
1590625ead55 Add missing blank lines and dots in soc.views.helper.templatetags.forms_helpers module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 794
diff changeset
   139
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   140
def get_reference_url(form, name):
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 935
diff changeset
   141
  """Retrieves the reference url from a field.
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   142
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   143
  Args:
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   144
    form: the form the field is defined in
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   145
    name: the name of the field
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   146
  """
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   147
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   148
  if not hasattr(form, 'Meta'):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   149
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   150
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   151
  if not hasattr(form.Meta, 'model'):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   152
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   153
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   154
  if not hasattr(form.Meta.model, name):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   155
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   156
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   157
  field = getattr(form.Meta.model, name)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   158
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   159
  if not isinstance(field, db.ReferenceProperty):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   160
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   161
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   162
  return getattr(field, 'redirect_url', None)
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   163
835
1590625ead55 Add missing blank lines and dots in soc.views.helper.templatetags.forms_helpers module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 794
diff changeset
   164
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   165
def as_table_helper(context, form):
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   166
  fields = []
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   167
  hidden_fields = []
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   168
  hidden_fields_errors = []
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   169
  entity = context['entity']
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   170
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   171
  # Iterate over all fields and prepare it for adding 
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   172
  for name, field in form.fields.items():
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   173
    bf = forms_in.BoundField(form, field, name)
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   174
    reference = None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   175
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   176
    if name.endswith('_link_id'):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   177
      reference = get_reference_url(form, name[:-8])
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   178
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   179
    # If the field is hidden we display it elsewhere
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   180
    if not bf.is_hidden:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   181
      example_text = ''
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   182
      if hasattr(field, 'example_text'):
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   183
        example_text = force_unicode(field.example_text)
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   184
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   185
      item = (bf, field.required, example_text, reference)
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   186
      fields.append(item)
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   187
    else:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   188
      hidden_fields.append(unicode(bf))
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   189
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   190
      for e in bf.errors:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   191
        item = (name, force_unicode(e))
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   192
        hidden_fields_errors.append(item)
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   193
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   194
  context.update({
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   195
      'top_errors': form.non_field_errors() or '',
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   196
      'hidden_field_errors': hidden_fields_errors or '',
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   197
      'fields': fields or '',
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   198
      'hidden_fields': hidden_fields or '',
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   199
      })
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   200
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   201
  return context
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   202
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   203
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   204
@register.inclusion_tag('soc/templatetags/_as_table_row.html',
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   205
                        takes_context=True)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   206
def as_table_row(context, field, required, example_text, reference):
835
1590625ead55 Add missing blank lines and dots in soc.views.helper.templatetags.forms_helpers module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 794
diff changeset
   207
  """Outputs a field as a properly formatted html row.
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   208
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   209
  Args:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   210
    form: the form that the row belongs to
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   211
    field: the field that should be converted to a row
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   212
    required: whether the field is required
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   213
    example_text: the example_text for this row
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   214
    reference: the entity_suffix if the field is a reference
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   215
  """
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   216
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   217
  return as_table_row_helper(context, field, required, example_text, reference)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   218
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   219
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   220
@register.inclusion_tag('soc/templatetags/_as_twoline_table_row.html',
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   221
                        takes_context=True)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   222
def as_twoline_table_row(context, field, required, example_text, reference):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   223
  """See as_table_row().
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   224
  """
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   225
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   226
  return as_table_row_helper(context, field, required, example_text, reference)
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   227
835
1590625ead55 Add missing blank lines and dots in soc.views.helper.templatetags.forms_helpers module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 794
diff changeset
   228
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   229
def as_table_row_helper(context, field, required, example_text, reference):
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   230
  """See as_table_row().
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   231
  """
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   232
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   233
  # Escape and cache in local variable.
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   234
  errors = [force_unicode(escape(error)) for error in field.errors]
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   235
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   236
  form = context['form']
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   237
  entity = context['entity']
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   238
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   239
  if reference:
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   240
    from soc.views.helper import redirects
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   241
    params = {
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   242
        'url_name': reference,
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   243
        'field_name': field.name,
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   244
        'return_url': context['return_url']
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   245
        }
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   246
    select_url = redirects.getSelectRedirect(entity, params)
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   247
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   248
  if field.label:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   249
    label = escape(force_unicode(field.label))
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   250
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   251
    # Only add the suffix if the label does not end in punctuation.
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   252
    if form.label_suffix and (label[-1] not in ':?.!'):
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   253
      label += form.label_suffix
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   254
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   255
    label = field.label_tag(label) or ''
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   256
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   257
  field_class_type = 'formfield%slabel' % ('error' if errors else '')
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   258
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   259
  help_text = field.help_text
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   260
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   261
  context.update({
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   262
      'help_text': force_unicode(help_text) if help_text else '',
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   263
      'field_class_type': field_class_type,
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   264
      'label': force_unicode(label) if field.label else '',
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   265
      'field': unicode(field),
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   266
      'required': required,
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   267
      'example_text': example_text,
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   268
      'select_url': select_url if reference else None,
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   269
      'errors': errors,
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   270
      })
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   271
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   272
  return context