author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 21 Feb 2009 10:36:04 +0000 | |
changeset 1420 | c49d6f79663d |
parent 1371 | 2d97dbbb4d99 |
child 1531 | db5d40d9dc43 |
permissions | -rw-r--r-- |
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 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 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 |
|
1371
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
27 |
import operator |
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
28 |
import re |
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
29 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
30 |
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
|
31 |
|
38
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
from django import template |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
|
1371
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
37 |
from soc.logic import dicts |
1229
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
38 |
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
|
39 |
|
322
6641e941ef1e
Fixed imports sorting based on comments for r751.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
40 |
|
38
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
register = template.Library() |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
|
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 |
@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
|
45 |
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
|
46 |
"""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
|
47 |
|
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
|
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
|
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
Usage: |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
{% load forms_helpers %} |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
... |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
<table> |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
{% 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
|
60 |
... |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
</table> |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
|
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
Args: |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
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
|
65 |
|
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
Returns: |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
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
|
68 |
{ 'field': field } |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
""" |
9a6ee3ab1446
A {% field_as_table_row %} template tag to simplify custom forms.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
return {'field': field} |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
71 |
|
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 |
@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
|
74 |
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
|
75 |
"""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
|
76 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
_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
|
80 |
doing all of the work). |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
81 |
|
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
|
82 |
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
|
83 |
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
|
84 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
85 |
Usage: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
86 |
{% load forms_helpers %} |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
87 |
... |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
88 |
<table> |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
89 |
{% 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
|
90 |
... |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
91 |
</table> |
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 |
Args: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
97 |
Returns: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
98 |
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
|
99 |
{ 'field_label': field_label', |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
100 |
'field_value': field_value'} |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
101 |
""" |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
102 |
return {'field_label': field_label, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
103 |
'field_value': field_value} |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
104 |
|
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
|
105 |
|
794
19c24508c398
Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents:
785
diff
changeset
|
106 |
@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
|
107 |
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
|
108 |
"""See readonly_field_as_table_row(). |
19c24508c398
Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents:
785
diff
changeset
|
109 |
""" |
19c24508c398
Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents:
785
diff
changeset
|
110 |
return {'field_label': field_label, |
19c24508c398
Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents:
785
diff
changeset
|
111 |
'field_value': field_value} |
19c24508c398
Added _readonly_field_as_twoline_table_row .
Lennard de Rijk <ljvderijk@gmail.com>
parents:
785
diff
changeset
|
112 |
|
728
602c2b2f4d8b
Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
322
diff
changeset
|
113 |
|
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
|
114 |
@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
|
115 |
'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
|
116 |
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
|
117 |
"""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
|
118 |
""" |
602c2b2f4d8b
Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
322
diff
changeset
|
119 |
return {'field_label': field_label, |
602c2b2f4d8b
Added a readonly_multiline_field_as_table_row tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
322
diff
changeset
|
120 |
'field_value': field_value} |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
121 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
122 |
|
1341
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
123 |
@register.inclusion_tag('soc/templatetags/_as_readonly_table.html', |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
124 |
takes_context=True) |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
125 |
def as_readonly_table(context, form): |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
126 |
"""Outputs a form as a properly formatted html table. |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
127 |
|
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
128 |
Args: |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
129 |
form: the form that should be converted to a table |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
130 |
""" |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
131 |
|
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
132 |
# create the bound fields |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
133 |
fields = [forms_in.BoundField(form, field, name) for name, field in |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
134 |
form.fields.items() if field] |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
135 |
|
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
136 |
return {'fields': fields} |
1b4b4a9ac17b
Add an as_readonly_table filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
137 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
138 |
@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
|
139 |
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
|
140 |
"""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
|
141 |
|
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
142 |
Args: |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
143 |
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
|
144 |
""" |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
145 |
|
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
146 |
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
|
147 |
|
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
148 |
|
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
149 |
@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
|
150 |
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
|
151 |
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
|
152 |
"""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
|
153 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
154 |
Args: |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
155 |
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
|
156 |
""" |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
157 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
158 |
return as_table_helper(context, form) |
785
c740d0129cce
Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
754
diff
changeset
|
159 |
|
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
|
160 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
161 |
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
|
162 |
fields = [] |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
163 |
hidden_fields = [] |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
164 |
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
|
165 |
entity = context['entity'] |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
166 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
167 |
# 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
|
168 |
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
|
169 |
if not field: |
005be2cf889d
Do not attempt to render a field if it is disabled
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1271
diff
changeset
|
170 |
continue |
005be2cf889d
Do not attempt to render a field if it is disabled
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1271
diff
changeset
|
171 |
|
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
172 |
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
|
173 |
attrs = {} |
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
174 |
|
1229
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
175 |
if isinstance(field, widgets.ReferenceField): |
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
176 |
attrs = field.rf |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
177 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
178 |
# 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
|
179 |
if not bf.is_hidden: |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
180 |
example_text = '' |
1371
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
181 |
group = '0. ' |
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
182 |
|
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
183 |
if hasattr(field, 'group'): |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
184 |
group = field.group |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
185 |
|
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
186 |
if hasattr(field, 'example_text'): |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
187 |
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
|
188 |
|
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
189 |
item = { |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
190 |
'field': bf, |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
191 |
'required': field.required, |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
192 |
'example_text': example_text, |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
193 |
'group': group, |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
194 |
} |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
195 |
|
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
196 |
item.update(attrs) |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
197 |
fields.append(item) |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
198 |
else: |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
199 |
hidden_fields.append(unicode(bf)) |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
200 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
201 |
for e in bf.errors: |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
202 |
item = (name, force_unicode(e)) |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
203 |
hidden_fields_errors.append(item) |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
204 |
|
1371
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
205 |
grouped = dicts.groupby(fields, 'group') |
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
206 |
rexp = re.compile(r"\d+. ") |
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
207 |
fields = [(rexp.sub('',key), grouped[key]) for key in sorted(grouped)] |
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
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 |
context.update({ |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
210 |
'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
|
211 |
'hidden_field_errors': hidden_fields_errors or '', |
1371
2d97dbbb4d99
Implemented simple group sorted using numerical ordering
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1360
diff
changeset
|
212 |
'groups': fields if fields else '', |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
213 |
'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
|
214 |
}) |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
215 |
|
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
216 |
return context |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
217 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
218 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
219 |
@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
|
220 |
takes_context=True) |
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
221 |
def as_table_row(context, item): |
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
|
222 |
"""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
|
223 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
224 |
Args: |
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
225 |
item: the item that is being rendered |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
226 |
""" |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
227 |
|
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
228 |
return as_table_row_helper(context, item) |
935
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 |
@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
|
232 |
takes_context=True) |
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
233 |
def as_twoline_table_row(context, item): |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
234 |
"""See as_table_row(). |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
235 |
""" |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
236 |
|
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
237 |
return as_table_row_helper(context, item) |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
238 |
|
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
239 |
|
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
240 |
def as_table_row_helper(context, item): |
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
241 |
"""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
|
242 |
""" |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
243 |
|
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
244 |
field = item['field'] |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
245 |
required = item['required'] |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
246 |
example_text = item['example_text'] |
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
|
247 |
|
1360
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
248 |
form = context['form'] |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
249 |
entity = context['entity'] |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
250 |
|
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
251 |
reference = item.get('reference_url') |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
252 |
filter = item.get('filter') |
f62c462037b6
Added grouping support to all forms, converted role as example
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1341
diff
changeset
|
253 |
filter_fields = item.get('filter_fields') |
785
c740d0129cce
Added a twoline_edit.html page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
754
diff
changeset
|
254 |
|
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
255 |
# Escape and cache in local variable. |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
256 |
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
|
257 |
|
1229
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
258 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
259 |
if reference: |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
260 |
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
|
261 |
params = { |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
262 |
'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
|
263 |
} |
1229
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
264 |
|
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
265 |
if entity: |
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
266 |
args = {} |
1301
58f18ea60093
Added a filter_fields parameter to the ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1282
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
|
1271
3bd4a3b527d7
Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1229
diff
changeset
|
272 |
if '__scoped__' in filter: |
3bd4a3b527d7
Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1229
diff
changeset
|
273 |
args['scope_path'] = entity.key().name() |
3bd4a3b527d7
Add '__scoped__' as a special filter
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1229
diff
changeset
|
274 |
|
1229
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
275 |
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
|
276 |
|
ec3768cbf369
Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1214
diff
changeset
|
277 |
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
|
278 |
|
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
279 |
if field.label: |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
280 |
label = escape(force_unicode(field.label)) |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
281 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
282 |
# 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
|
283 |
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
|
284 |
label += form.label_suffix |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
285 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
286 |
label = field.label_tag(label) or '' |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
287 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
288 |
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
|
289 |
|
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
290 |
help_text = field.help_text |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
291 |
|
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
292 |
context.update({ |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
293 |
'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
|
294 |
'field_class_type': field_class_type, |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
295 |
'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
|
296 |
'field': field, |
1214
7fb705534dd1
Include the field_id in the context of _as_table_helper
Sverre Rabbelier <srabbelier@gmail.com>
parents:
959
diff
changeset
|
297 |
'field_id': field.auto_id, |
741
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
298 |
'required': required, |
2dc2c65c5f76
Converted as_table to be a template tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
728
diff
changeset
|
299 |
'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
|
300 |
'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
|
301 |
'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
|
302 |
}) |
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
303 |
|
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
835
diff
changeset
|
304 |
return context |