Author: tmckay
Date: 2012-03-29 18:52:47 +0000 (Thu, 29 Mar 2012)
New Revision: 5277
Modified:
trunk/cumin/python/cumin/grid/job.py
trunk/cumin/python/cumin/grid/submission.py
trunk/wooly/python/wooly/forms.py
Log:
Screen 'Reason' dialogs for double quotes and XML
BZ807912
Modified: trunk/cumin/python/cumin/grid/job.py
===================================================================
--- trunk/cumin/python/cumin/grid/job.py 2012-03-29 18:51:14 UTC (rev 5276)
+++ trunk/cumin/python/cumin/grid/job.py 2012-03-29 18:52:47 UTC (rev 5277)
@@ -16,7 +16,7 @@
from wooly import Widget, Parameter, Attribute
from wooly.util import StringCatalog, Writer, escape_amp, escape_entity,\
xml_escape
-from wooly.forms import Form, FormButton, StringField
+from wooly.forms import Form, FormButton, StringField, NoXMLStringField
from wooly.widgets import ModeSet, PropertySet, TemplateRenderer, Notice
from wooly.template import WidgetTemplate
from wooly.parameters import ListParameter, IntegerParameter, DictParameter
@@ -1137,7 +1137,7 @@
self.task.invoke(session, scheduler, job_id, reason, submission)
self.task.exit_with_redirect(session)
-class ReasonField(StringField):
+class ReasonField(NoXMLStringField):
def render_title(self, session):
return "Reason"
Modified: trunk/cumin/python/cumin/grid/submission.py
===================================================================
--- trunk/cumin/python/cumin/grid/submission.py 2012-03-29 18:51:14 UTC (rev 5276)
+++ trunk/cumin/python/cumin/grid/submission.py 2012-03-29 18:52:47 UTC (rev 5277)
@@ -18,7 +18,7 @@
from wooly import Attribute, Parameter
from wooly.forms import StringField, ScalarField, FormError, OptionInputSet,\
- MultilineStringField, FormField, IntegerField, LabelFormField
+ MultilineStringField, FormField, IntegerField, LabelFormField, NoXMLStringField
from wooly.parameters import IntegerParameter
log = logging.getLogger("cumin.grid.submission")
@@ -220,7 +220,7 @@
self.columns.append(scheduler._id.sql_column)
self.columns.append(scheduler.Name.sql_column)
-class JobDescriptionField(StringField):
+class JobDescriptionField(NoXMLStringField):
def __init__(self, app, name):
super(JobDescriptionField, self).__init__(app, name)
@@ -233,18 +233,6 @@
def render_help(self, session):
return "This text will identify the submission"
- def validate(self, session):
- super(JobDescriptionField, self).validate(session)
-
- des = self.get(session)
- if '"' in des:
- error = FormError("Double quotes are not allowed in submission
descriptions")
- self.form.errors.add(session, error)
-
- elif xml_escape(des) != des:
- error = FormError("XML special characters are not allowed in submission
descriptions")
- self.form.errors.add(session, error)
-
class JobSchedulerField(ScalarField):
def __init__(self, app, name):
super(JobSchedulerField, self).__init__(app, name, None)
Modified: trunk/wooly/python/wooly/forms.py
===================================================================
--- trunk/wooly/python/wooly/forms.py 2012-03-29 18:51:14 UTC (rev 5276)
+++ trunk/wooly/python/wooly/forms.py 2012-03-29 18:52:47 UTC (rev 5277)
@@ -133,6 +133,25 @@
title = self.widget.render_title(session)
return "The '%s' field must have a value" % title
+class QuoteValueError(FormError):
+ def __init__(self, widget):
+ super(QuoteValueError, self).__init__(None)
+
+ self.widget = widget
+
+ def get_message(self, session):
+ title = self.widget.render_title(session)
+ return "The '%s' field may not contain double quotes" % title
+
+class XMLValueError(FormError):
+ def __init__(self, widget):
+ super(XMLValueError, self).__init__(None)
+
+ self.widget = widget
+
+ def get_message(self, session):
+ title = self.widget.render_title(session)
+ return "The '%s' field may not contain XML special characters"
% title
class EmptyInputError(FormError):
def __init__(self):
super(EmptyInputError, self).__init__("This value is required")
@@ -461,6 +480,19 @@
self.input = StringInput(app, "input")
self.add_child(self.input)
+class NoXMLStringField(StringField):
+ def validate(self, session):
+ super(NoXMLStringField, self).validate(session)
+
+ des = self.get(session)
+ if '"' in des:
+ error = QuoteValueError(self)
+ self.form.errors.add(session, error)
+
+ elif xml_escape(des) != des:
+ error = XMLValueError(self)
+ self.form.errors.add(session, error)
+
class MultilineStringField(ScalarField):
def __init__(self, app, name):
super(MultilineStringField, self).__init__(app, name, None)