diff roundup/cgi/templating.py @ 5181:496f30da72f8

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.
author John Rouillard <rouilj@ieee.org>
date Mon, 30 Jan 2017 22:09:32 -0500
parents f95650727b1c
children 5c8808f55d93
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Sat Jan 28 21:15:49 2017 -0500
+++ b/roundup/cgi/templating.py	Mon Jan 30 22:09:32 2017 -0500
@@ -2050,7 +2050,7 @@
                           **kwargs)
 
     def menu(self, size=None, height=None, showid=0, additional=[], value=None,
-             sort_on=None, html_kwargs={}, translate=True, **conditions):
+             sort_on=None, html_kwargs={}, translate=True, showdef=None, **conditions):
         """ Render a form select list for this property
 
             "size" is used to limit the length of the list labels
@@ -2068,6 +2068,11 @@
             "translate" indicates if we should do translation of labels
             using gettext -- this is often desired (e.g. for status
             labels) but sometimes not.
+            "showdef" marks the default value with the string passed
+                as the showdef argument. It is appended to the selected
+                value so the user can reset the menu to the original value.
+                Note that the marker may be removed if the length of
+                the option label and the marker exceed the size.
 
             The remaining keyword arguments are used as conditions for
             filtering the items in the list - they're passed as the
@@ -2136,8 +2141,13 @@
 
             # figure if this option is selected
             s = ''
+            # record the marker for the selected item if requested
+            selected_mark=''
+
             if value in [optionid, option]:
                 s = 'selected="selected" '
+                if ( showdef ):
+                    selected_mark = showdef
 
             # figure the label
             if showid:
@@ -2147,6 +2157,7 @@
             else:
                 lab = option
 
+            lab = lab + selected_mark
             # truncate if it's too long
             if size is not None and len(lab) > size:
                 lab = lab[:size-3] + '...'

Roundup Issue Tracker: http://roundup-tracker.org/