[Mpuls-commits] r4937 - in base/trunk: . mpulsweb/controllers mpulsweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon May 2 11:10:21 CEST 2011
Author: torsten
Date: 2011-05-02 11:10:17 +0200 (Mon, 02 May 2011)
New Revision: 4937
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/controllers/case.py
base/trunk/mpulsweb/model/case.py
Log:
Issue2027: Use SetDataException on case creation to display errors in input data.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2011-05-02 08:03:06 UTC (rev 4936)
+++ base/trunk/ChangeLog 2011-05-02 09:10:17 UTC (rev 4937)
@@ -5,6 +5,10 @@
change should not affekt old behavior. Further added a new method
_get_validator which can be overwritten to add a custom validator in
specific application code.
+ * mpulsweb/controllers/case.py: Issue2027: Use SetDataException on
+ case creation to display errors in input data.
+ * mpulsweb/model/case.py (_updateMasterOnCreate): Reraise exception.
+ Is not handled in controller.
2011-04-29 Roland Geider <roland.geider at intevation.de>
* mpulsweb/public/styles/all.css,
Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py 2011-05-02 08:03:06 UTC (rev 4936)
+++ base/trunk/mpulsweb/controllers/case.py 2011-05-02 09:10:17 UTC (rev 4937)
@@ -371,6 +371,22 @@
a custom validator'''
return NewCaseForm()
+ def _convert_SetDataException2Formencode(self, err):
+ '''Will convert a SetDataException in a formencode compatible dictionary'''
+
+ # Expample SetDataException:
+ # {'geburtsdatum:17': [type: 1, name: 'geburtsdatum:17', msg:
+ # u"'Geburtsdatum' darf zeitlich nicht nach 'Datum Erstgespr\xe4ch'
+ # liegen.", bad: datetime.date(1990, 1, 1)], 'datum_ea_start:17':
+ # [type: 1, name: 'datum_ea_start:17', msg: u"'Geburtsdatum' darf
+ # zeitlich nicht nach 'Datum Erstgespr\xe4ch' liegen.", bad:
+ # datetime.date(1981, 12, 12)]}
+ errors = {}
+ for e in err.errors.keys():
+ key = e.split(':')[0]
+ errors[key] = err.errors.get(e)[0].msg
+ return errors
+
@checkRole('cm_ka')
def newAction(self):
# TODO: Use htmlfill here!
@@ -397,6 +413,14 @@
form_result.update(self._add_custom_fields())
# Create a new case
case = self._createCase(form_result)
+ except SetDataException, err:
+ c.form_result = form_result
+ c.form_errors = self._convert_SetDataException2Formencode(err)
+ form = render('/casemanagement/new.mako')
+ return formencode.htmlfill.render(form,
+ defaults=c.form_result,
+ auto_insert_errors=False,
+ errors=c.form_errors)
except formencode.Invalid, error:
log.debug("Invalid form data: %r", error)
c.form_result = error.value
Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py 2011-05-02 08:03:06 UTC (rev 4936)
+++ base/trunk/mpulsweb/model/case.py 2011-05-02 09:10:17 UTC (rev 4937)
@@ -1213,6 +1213,7 @@
# For now, though, it's better to log it instead of silently
# suppressing it.
log.exception("SetDataException in _updateMasterOnCreate ignored")
+ raise
def _initNewCase(self, id):
"""Additional initialization of the new case.
More information about the Mpuls-commits
mailing list