Skip to content

Commit 4001cda

Browse files
committed
issue2550683 Allow indexargs_form filter variable exclusion.
Patch generated by Bruce Tulloch (bruce). Applied and docstring for indexargs_form updated by John Rouillard. Full patch description is in CHANGES.txt file. I added the use case description. Code should be backwards compatible. There are not existing tests of indexargs_form that I can adopt to test, but it didn't cause tests/test_cgi tests/test_template to fail and the demo tracker ran properly.
1 parent d0e3658 commit 4001cda

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

CHANGES.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,33 @@ Features:
4040
- issue2109308 - Allow subject of nosy messages be changed from reactor
4141
Adds a subject parameter to nosymessage function. Patch initally
4242
generated by Frank Niessink. Tests, adaptation by John Rouillard.
43+
- issue2550683 Allow indexargs_form filter variable exclusion.
44+
Patch generated by Bruce Tulloch (bruce). Applied and docstring for
45+
indexargs_form updated by John Rouillard. Patch description is:
46+
This is required to allow indexargs_form to be used in conjunction with
47+
other form variables which *replace* some filterspec parameters.
48+
49+
One must exclude all variables from the indexargs_form call which are to
50+
be replaced with values that are derived from other form input elements,
51+
otherwise they will clash with the "hidden" input elements generated by
52+
indexargs_form itself.
53+
54+
For example:
55+
<tal:block replace="structure python:request.indexargs_form(
56+
sort=0,group=0,filter=0,columns=0,
57+
exclude=['type','status','assignedto'])"/>
58+
where the variables type, status and assignedto are supplied via other
59+
form input elements. Without the new exclude argument to indexargs_form,
60+
all hidden input elements otherwise generated by this call would need to
61+
be manually added to the template code. Further, given that the template
62+
may not know what other variables may be defined, it may not even be
63+
possible to code this without some python helpers.
64+
[ rouilj I think this is an example usecase. Possible assignedto
65+
users need to have a specific role. Create TAL that
66+
filters the users to the select few. Defines a select list for
67+
assignedto. Use exclude=['assignedto'] to prevent the
68+
indexargs_form from generating a confliciting assignedto field
69+
which lists all users regardless of the role.]
4370

4471
Fixed:
4572

roundup/cgi/templating.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,8 +2681,15 @@ def __str__(self):
26812681
"""%d
26822682

26832683
def indexargs_form(self, columns=1, sort=1, group=1, filter=1,
2684-
filterspec=1, search_text=1):
2685-
""" return the current index args as form elements """
2684+
filterspec=1, search_text=1, exclude=[]):
2685+
""" return the current index args as form elements
2686+
2687+
This routine generates an html form with hidden elements.
2688+
If you want to have visible form elements in your tal/jinja
2689+
generated templates use the exclude aray to list the names for
2690+
these elements. This wll prevent the function from creating
2691+
these elements in its output.
2692+
"""
26862693
l = []
26872694
sc = self.special_char
26882695
def add(k, v):
@@ -2710,6 +2717,8 @@ def add(k, v):
27102717
if self.classname and filterspec:
27112718
cls = self.client.db.getclass(self.classname)
27122719
for k,v in self.filterspec.items():
2720+
if k in exclude:
2721+
continue
27132722
if type(v) == type([]):
27142723
if isinstance(cls.get_transitive_prop(k), hyperdb.String):
27152724
add(k, ' '.join(v))

0 commit comments

Comments
 (0)