Author: croberts
Date: 2011-05-12 14:18:15 +0000 (Thu, 12 May 2011)
New Revision: 4761
Modified:
trunk/cumin/python/cumin/grid/limit.py
trunk/cumin/python/cumin/grid/limit.strings
trunk/cumin/resources/app.css
Log:
In order to address BZ
https://bugzilla.redhat.com/show_bug.cgi?id=697016 I have modified
the Limit form to include an "Unlimited" button that will change the value in
the box to "Unlimited". In addition, the back end will now support
"Unlimited" as a valid input which gets translated to a large number to be sent
to condor...the user will still see "unlimited" anytime they set a value over
1M.
Modified: trunk/cumin/python/cumin/grid/limit.py
===================================================================
--- trunk/cumin/python/cumin/grid/limit.py 2011-05-09 12:59:44 UTC (rev 4760)
+++ trunk/cumin/python/cumin/grid/limit.py 2011-05-12 14:18:15 UTC (rev 4761)
@@ -1,20 +1,23 @@
-import logging
-
from cumin.formats import fmt_link
from cumin.model import QmfCall
-from cumin.objectselector import ObjectTableColumn, ObjectQmfSelector,\
+from cumin.objectframe import ObjectFrame, ObjectFrameTask, \
+ ObjectFrameTaskFeedbackForm
+from cumin.objectselector import ObjectTableColumn, ObjectQmfSelector, \
ObjectQmfTable
-from cumin.objectframe import ObjectFrame, ObjectFrameTask,\
- ObjectFrameTaskFeedbackForm
from cumin.qmfadapter import ObjectQmfAdapter
from cumin.widgets import CuminView
-
-from wooly.forms import StringField, StringInput, IntegerField, RealField
+from wooly.forms import StringField, StringInput, IntegerField, RealField, \
+ FormButton, FormField, FormError
from wooly.util import StringCatalog
from wooly.widgets import TabbedModeSet
+from wooly.parameters import *
+import logging
+
+
strings = StringCatalog(__file__)
log = logging.getLogger("cumin.limit")
+LIMIT_FLOAT_VALUE_FOR_UNLIMITED = 1000000.0
class LimitAdapter(ObjectQmfAdapter):
def __init__(self, app, cls, collector):
@@ -104,7 +107,7 @@
limit_max = super(LimitTable.MaxColumn, self).render_cell_content(session,
data)
try:
limit_max = float(limit_max)
- if limit_max > 1000000.0:
+ if limit_max >= LIMIT_FLOAT_VALUE_FOR_UNLIMITED:
limit_max = "Unlimited"
except:
limit_max = 0
@@ -177,13 +180,25 @@
self.limit_max = self.LimitMax(app, "max")
self.limit_max.required = True
self.add_field(self.limit_max)
+
+ self.reset_button = self.ResetLimitFormButton(app, "resetbutton")
+ self.add_field(self.reset_button)
+
+
def process_submit(self, session):
- self.validate(session)
+ new_max_value = self.limit_max.input.get(session)
+
+ self.limit_max.validate(session)
+ if not self.errors.get(session):
+ if new_max_value.lower() in ("unlimited", "na",
"n/a") or float(new_max_value) >= LIMIT_FLOAT_VALUE_FOR_UNLIMITED:
+ self.limit_max.set(session, LIMIT_FLOAT_VALUE_FOR_UNLIMITED)
+ else:
+ self.limit_max.set(session,new_max_value)
if not self.errors.get(session):
limit_name = self.limit_name.get(session)
- limit_max = self.limit_max.get(session)
+ limit_max = self.limit_max.get_float_value(session)
negotiator = self.object.get(session)
self.task.invoke(session, negotiator, limit_name, limit_max)
@@ -192,6 +207,19 @@
def render_form_class(self, session):
return " ".join((super(NegotiatorLimitForm,
self).render_form_class(session), "mform"))
+ class ResetLimitFormButton(FormField):
+ def __init__(self, app, name):
+ super(NegotiatorLimitForm.ResetLimitFormButton, self).__init__(app, name)
+ self.button_tmpl = WidgetTemplate(self, "reset_button_html")
+
+ def do_render(self, session):
+ writer = Writer()
+ self.button_tmpl.render(writer, session)
+ return writer.to_string()
+
+ def render_class(self, session):
+ return "midformbutton"
+
class LimitName(StringField):
def __init__(self, app, name):
super(NegotiatorLimitForm.LimitName, self).__init__(app, name)
@@ -206,10 +234,35 @@
# used to override html and css
pass
- class LimitMax(RealField):
+ class LimitMax(StringField):
def render_title(self, session):
return "Max Allowance"
-
+
+ def get(self,session):
+ # this gets the value for display
+ value = self.input.get(session)
+ if value >= LIMIT_FLOAT_VALUE_FOR_UNLIMITED:
+ value = "Unlimited"
+ return value
+
+ def get_float_value(self,session):
+ # this gets the value sent via QMF to reset the limit
+ value = self.input.get(session)
+ if float(value) >= LIMIT_FLOAT_VALUE_FOR_UNLIMITED:
+ value = LIMIT_FLOAT_VALUE_FOR_UNLIMITED
+ return value
+
+ def validate(self, session):
+ value = self.input.get(session)
+ if value:
+ try:
+ if value not in ("unlimited", "na",
"n/a"):
+ value = float(value)
+ except:
+ title = self.render_title(session)
+ message = "The '%s' field must be either
\"unlimited\", an integer or a float" % title
+ self.form.errors.add(session, FormError(message))
+
class LimitView(CuminView):
def __init__(self, app, name, limit):
super(LimitView, self).__init__(app, name, None)
Modified: trunk/cumin/python/cumin/grid/limit.strings
===================================================================
--- trunk/cumin/python/cumin/grid/limit.strings 2011-05-09 12:59:44 UTC (rev 4760)
+++ trunk/cumin/python/cumin/grid/limit.strings 2011-05-12 14:18:15 UTC (rev 4761)
@@ -30,3 +30,17 @@
);
//]]>
</script>
+
+[ResetLimitFormButton.reset_button_html]
+<tr id="{id}">
+ <th></th>
+ <td><button class="{class}" type="button"
name="{id}" onclick="return
resetLimitMax();">Unlimited</button></td>
+</tr>
+<script type="text/javascript">
+//<![CDATA[
+function resetLimitMax() {
+ document.forms[0].elements[1].value="Unlimited";
+ return false;
+}
+//]]>
+</script>
Modified: trunk/cumin/resources/app.css
===================================================================
--- trunk/cumin/resources/app.css 2011-05-09 12:59:44 UTC (rev 4760)
+++ trunk/cumin/resources/app.css 2011-05-12 14:18:15 UTC (rev 4761)
@@ -237,6 +237,10 @@
padding: 0.25em 0.25em 0 0.25em;
}
+form.mform button.midformbutton {
+ margin: 0em;
+}
+
form.mform a.help {
float: left;
margin: 0.5em;