Skip to content

Commit 0141b75

Browse files
committed
Add a new argument "showdef" to the template function menu(). When set
to a string, the string is appended to the displayed option value. This allows the user to reset the value for the menu (select) to the original value.
1 parent 5f54b1e commit 0141b75

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Features:
156156
field. This allows onchange javascript to trigger to highlight
157157
changes, recalculate other form values etc. See ``upgrading.txt``
158158
for details on applying these changes to your tracker. (John Rouillard)
159+
- menu template function has a new parameter "showdef". When set to a
160+
string, the string is appended to the displayed option value. This
161+
allows the user to reset the value for the menu (select) to the
162+
original value. (John Rouillard)
159163

160164
Fixed:
161165

roundup/cgi/templating.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ def field(self, showid=0, size=None, **kwargs):
20502050
**kwargs)
20512051

20522052
def menu(self, size=None, height=None, showid=0, additional=[], value=None,
2053-
sort_on=None, html_kwargs={}, translate=True, **conditions):
2053+
sort_on=None, html_kwargs={}, translate=True, showdef=None, **conditions):
20542054
""" Render a form select list for this property
20552055
20562056
"size" is used to limit the length of the list labels
@@ -2068,6 +2068,11 @@ def menu(self, size=None, height=None, showid=0, additional=[], value=None,
20682068
"translate" indicates if we should do translation of labels
20692069
using gettext -- this is often desired (e.g. for status
20702070
labels) but sometimes not.
2071+
"showdef" marks the default value with the string passed
2072+
as the showdef argument. It is appended to the selected
2073+
value so the user can reset the menu to the original value.
2074+
Note that the marker may be removed if the length of
2075+
the option label and the marker exceed the size.
20712076
20722077
The remaining keyword arguments are used as conditions for
20732078
filtering the items in the list - they're passed as the
@@ -2136,8 +2141,13 @@ def menu(self, size=None, height=None, showid=0, additional=[], value=None,
21362141

21372142
# figure if this option is selected
21382143
s = ''
2144+
# record the marker for the selected item if requested
2145+
selected_mark=''
2146+
21392147
if value in [optionid, option]:
21402148
s = 'selected="selected" '
2149+
if ( showdef ):
2150+
selected_mark = showdef
21412151

21422152
# figure the label
21432153
if showid:
@@ -2147,6 +2157,7 @@ def menu(self, size=None, height=None, showid=0, additional=[], value=None,
21472157
else:
21482158
lab = option
21492159

2160+
lab = lab + selected_mark
21502161
# truncate if it's too long
21512162
if size is not None and len(lab) > size:
21522163
lab = lab[:size-3] + '...'

0 commit comments

Comments
 (0)