app/soc/views/helper/templatetags/forms_helpers.py
author Sverre Rabbelier <srabbelier@gmail.com>
Fri, 13 Feb 2009 22:36:45 +0000
changeset 1307 091a21cf3627
parent 1301 58f18ea60093
child 1308 35b75ffcbb37
permissions -rw-r--r--
Update the copyright notice for 2009. Patch by: Sverre Rabbelier
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
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1301
diff changeset
     3
# Copyright 2009 the Melange authors.
38
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
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
    34
from soc.views.helper import widgets
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
    35
322
6641e941ef1e Fixed imports sorting based on comments for r751.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    36
38
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
register = template.Library()
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
@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
    41
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
    42
  """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
    43
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  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
    45
  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
    46
  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
    47
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
  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
    49
  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
    50
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
  Usage:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
    {% load forms_helpers %}
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
    ...
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
    <table>
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
     {% 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
    56
     ...
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
    </table>
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
  Args:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
    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
    61
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
  Returns:
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
    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
    64
      { 'field': field }
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
  """
9a6ee3ab1446 A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
  return {'field': field}
99
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    67
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    68
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    69
@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
    70
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
    71
  """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
    72
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    73
  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
    74
  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
    75
  _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
    76
  doing all of the work).
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    77
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
    78
  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
    79
  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
    80
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    81
  Usage:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    82
    {% load forms_helpers %}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    83
    ...
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    84
    <table>
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    85
     {% 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
    86
     ...
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    87
    </table>
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    88
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    89
  Args:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    90
    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
    91
    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
    92
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    93
  Returns:
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    94
    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
    95
      { 'field_label': field_label',
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    96
        'field_value': field_value'}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    97
  """
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    98
  return {'field_label': field_label,
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    99
          'field_value': field_value}
8c38b546a3cf Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
   100
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
   101
794
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   102
@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
   103
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
   104
  """See readonly_field_as_table_row().
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   105
  """
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   106
  return {'field_label': field_label,
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   107
          'field_value': field_value}
19c24508c398 Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents: 785
diff changeset
   108
728
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   109
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
   110
@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
   111
    '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
   112
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
   113
  """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
   114
  """
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   115
  return {'field_label': field_label,
602c2b2f4d8b Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 322
diff changeset
   116
          'field_value': field_value}
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   117
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   118
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   119
@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
   120
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
   121
  """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
   122
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   123
  Args:
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   124
    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
   125
  """
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
  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
   128
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   129
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   130
@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
   131
                        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
   132
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
   133
  """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
   134
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   135
  Args:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   136
    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
   137
  """
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   138
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   139
  return as_table_helper(context, form)
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   140
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
   141
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   142
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
   143
  """Retrieves the reference url from a field.
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   144
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   145
  Args:
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   146
    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
   147
    name: the name of the field
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   148
  """
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   149
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   150
  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
   151
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   152
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   153
  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
   154
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   155
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   156
  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
   157
    return None
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
  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
   160
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   161
  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
   162
    return None
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   163
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   164
  return getattr(field, 'redirect_url', None)
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   165
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
   166
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   167
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
   168
  fields = []
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   169
  hidden_fields = []
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   170
  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
   171
  entity = context['entity']
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   172
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   173
  # 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
   174
  for name, field in form.fields.items():
1282
005be2cf889d Do not attempt to render a field if it is disabled
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1271
diff changeset
   175
    if not field:
005be2cf889d Do not attempt to render a field if it is disabled
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1271
diff changeset
   176
      continue
005be2cf889d Do not attempt to render a field if it is disabled
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1271
diff changeset
   177
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   178
    bf = forms_in.BoundField(form, field, name)
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   179
    attrs = {}
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   180
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   181
    if isinstance(field, widgets.ReferenceField):
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   182
      attrs = field.rf
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   183
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   184
    # 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
   185
    if not bf.is_hidden:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   186
      example_text = ''
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   187
      if hasattr(field, 'example_text'):
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   188
        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
   189
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   190
      item = (bf, field.required, example_text, attrs)
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   191
      fields.append(item)
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   192
    else:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   193
      hidden_fields.append(unicode(bf))
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   194
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   195
      for e in bf.errors:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   196
        item = (name, force_unicode(e))
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   197
        hidden_fields_errors.append(item)
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   198
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   199
  context.update({
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   200
      '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
   201
      '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
   202
      'fields': fields or '',
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   203
      '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
   204
      })
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   205
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   206
  return context
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   207
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   208
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   209
@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
   210
                        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
   211
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
   212
  """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
   213
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   214
  Args:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   215
    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
   216
    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
   217
    required: whether the field is required
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   218
    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
   219
    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
   220
  """
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   221
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   222
  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
   223
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
@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
   226
                        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
   227
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
   228
  """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
   229
  """
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   230
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   231
  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
   232
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
   233
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   234
def as_table_row_helper(context, field, required, example_text, attrs):
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   235
  """See as_table_row().
785
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   236
  """
c740d0129cce Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 754
diff changeset
   237
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   238
  # Escape and cache in local variable.
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   239
  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
   240
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   241
  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
   242
  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
   243
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   244
  reference = attrs.get('reference_url')
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   245
  filter = attrs.get('filter')
1301
58f18ea60093 Added a filter_fields parameter to the ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1282
diff changeset
   246
  filter_fields = attrs.get('filter_fields')
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   247
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   248
  if reference:
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   249
    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
   250
    params = {
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   251
        '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
   252
        }
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   253
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   254
    if entity:
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   255
      args = {}
1301
58f18ea60093 Added a filter_fields parameter to the ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1282
diff changeset
   256
      for filter_field, filter_value in filter_fields.iteritems():
58f18ea60093 Added a filter_fields parameter to the ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1282
diff changeset
   257
        args[filter_field] = filter_value
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   258
      for filter_field in (i for i in filter if hasattr(entity, i)):
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   259
        args[filter_field] = getattr(entity, filter_field)
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   260
1271
3bd4a3b527d7 Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1229
diff changeset
   261
      if '__scoped__' in filter:
3bd4a3b527d7 Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1229
diff changeset
   262
        args['scope_path'] = entity.key().name()
3bd4a3b527d7 Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1229
diff changeset
   263
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   264
      params['args'] = '&'.join(['%s=%s' % item for item in args.iteritems()])
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   265
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1214
diff changeset
   266
    select_url = redirects.getSelectRedirect(params)
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   267
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   268
  if field.label:
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   269
    label = escape(force_unicode(field.label))
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   270
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   271
    # 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
   272
    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
   273
      label += form.label_suffix
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   274
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   275
    label = field.label_tag(label) or ''
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   276
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   277
  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
   278
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   279
  help_text = field.help_text
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   280
935
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   281
  context.update({
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   282
      '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
   283
      'field_class_type': field_class_type,
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   284
      'label': force_unicode(label) if field.label else '',
1271
3bd4a3b527d7 Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1229
diff changeset
   285
      'field': field,
1214
7fb705534dd1 Include the field_id in the context of _as_table_helper
Sverre Rabbelier <srabbelier@gmail.com>
parents: 959
diff changeset
   286
      'field_id': field.auto_id,
741
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   287
      'required': required,
2dc2c65c5f76 Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents: 728
diff changeset
   288
      '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
   289
      '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
   290
      '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
   291
      })
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   292
09f47e08f805 Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 835
diff changeset
   293
  return context