[Mpuls-commits] r5246 - in base/trunk: . mpulsweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Aug 18 22:12:52 CEST 2011
Author: bh
Date: 2011-08-18 22:12:51 +0200 (Thu, 18 Aug 2011)
New Revision: 5246
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/controllers/case.py
Log:
* mpulsweb/controllers/case.py (CaseController._markForAnonymize):
Prepare for the possibility that marking a case for anonymization
may raise arbitrary exception which will be the case when the
meta-server is involved, for instance. The actual anonymization is
handled in the new method _do_mark_anonymize_case which is the
place where the more specific exceptions can be
handled. _markForAnonymize itself is mostly scaffolding to ask for
confirmation and handle exceptions not caught by
_do_mark_anonymize_case in a generic way.
(CaseController._do_mark_anonymize_case): Extracted from
_markForAnonymize so that derived classes can easily extend the
exception handling, if necessary.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2011-08-18 17:32:23 UTC (rev 5245)
+++ base/trunk/ChangeLog 2011-08-18 20:12:51 UTC (rev 5246)
@@ -1,5 +1,20 @@
2011-08-18 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/controllers/case.py (CaseController._markForAnonymize):
+ Prepare for the possibility that marking a case for anonymization
+ may raise arbitrary exception which will be the case when the
+ meta-server is involved, for instance. The actual anonymization is
+ handled in the new method _do_mark_anonymize_case which is the
+ place where the more specific exceptions can be
+ handled. _markForAnonymize itself is mostly scaffolding to ask for
+ confirmation and handle exceptions not caught by
+ _do_mark_anonymize_case in a generic way.
+ (CaseController._do_mark_anonymize_case): Extracted from
+ _markForAnonymize so that derived classes can easily extend the
+ exception handling, if necessary.
+
+2011-08-18 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/controllers/case_bundle.py
(CaseBundleController.delete): Improve error reporting. This is
basically the same as the improved error reporting implemented for
Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py 2011-08-18 17:32:23 UTC (rev 5245)
+++ base/trunk/mpulsweb/controllers/case.py 2011-08-18 20:12:51 UTC (rev 5246)
@@ -127,6 +127,7 @@
id = self._checkInt(id)
confirmed = self._checkBool(confirmed)
case = self._loadCase(id)
+
# First check if the case is in a state which allows anonymization
try:
case.check_anonymizeability()
@@ -135,59 +136,89 @@
c.dialog_text = h.literal(e.value)
c.url_ok = url
return render('/casemanagement/dialogs/failed_markanonymize.mako')
- # Ok, show confirmation dialog if the user really wants to anonymize the
- # case.
- if confirmed == 1:
- try:
- c.dialog_title = _(u"""Freed case document to anonymise.""")
- c.dialog_text = _(u"""\
-The case document has been freed to be anonymised and has been given to
-the admininstration. Please click on OK, to get back to the overview.""")
- c.url_ok = h.url_for(controller="/case_overview")
- case.make_anonymizable()
- case.markAnonymize()
- session['render_mode'] = 'ro'
- session.save()
- return render('/casemanagement/dialogs/success_markanonymize.mako')
- except SetDataException, e:
- errors = []
- for k, values in e.errors.iteritems():
- for v in values:
- errors.append(v.msg)
- c.dialog_title = _(u"""Anonymising not possible.""")
- c.dialog_text = _(u"""\
-To anonymise this case document was not possible, because of following
-reason:</p><p><i>%s</i></p><p>Please click on OK to geht back to the overview.
-</p>""") % "<br>".join(errors)
- c.url_ok = h.url_for(controller='/case', action='select',
- id=case.id, confirmed=1)
- return render('/casemanagement/dialogs/failed_markanonymize.mako')
- else:
+
+ # Show confirmation dialog if necessary.
+ if not confirmed:
# Get description of the phase which will be set after anonymisation
phase_name = []
pdescriptions = g.mpuls_config.get('phases', 'description')[0]
phase = pdescriptions.get(determineAnonymizedCaseEndPhaseName(case))
end_phase = determineAnonymizedCaseEndPhase(case)
- for ph, pairs in g.mpuls_config.get('phases', 'pairs')[0].iteritems():
+ for ph, pairs in g.mpuls_config.get('phases',
+ 'pairs')[0].iteritems():
if str(end_phase) in pairs:
phase_name.append(phase)
if str(end_phase) == pairs[0]:
phase_name.append("(%s)" % _('Running'))
else:
phase_name.append("(%s)" % _('Finished'))
-
- c.dialog_title = _(u"""Do make anonymous?""")
- c.dialog_text =_(u"""\
-<p>Do you really want to free the case document to be made anonymous? The
-case document can then no longer be edited and is given to the administrator
-to make anonymous.</p>
-<p><b>The case document is going to make anonymous in phase </b>%s<b>!</b>""") \
- % " ".join(phase_name)
+
+ c.dialog_title = _(u"Do make anonymous?")
+ c.dialog_text = (_(u"<p>Do you really want to mark the case for"
+ u" anonymization? The case can then no longer be"
+ u" edited and will given to the administrators"
+ u" for final anonymisation.</p>"
+ u"<p><b>The case document is going to be"
+ u" anonymised in phase </b>%s<b>!</b>""") \
+ % " ".join(phase_name))
c.url_yes = h.url_for(controller='/case', action='markForAnonymize',
id=id, confirmed=1)
c.url_no = url
return render('/casemanagement/dialogs/confirm_markanonymize.mako')
+ # the action is confirmed, so call attempt to mark the case for
+ # deletion.
+ try:
+ return self._do_mark_anonymize_case(case)
+ except Exception:
+ log.exception("Exception while trying to mark case %d for"
+ " anonymisation", case.id)
+ c.dialog_title = _("Case document not marked for anonymisation!")
+ c.dialog_text = _("The case can not be marked for anonymisation"
+ " because of an unexpected problem.")
+ c.url_ok = h.url_for(controller="/case_overview")
+ return render('/casemanagement/dialogs/failed_markanonymize.mako')
+
+ def _do_mark_anonymize_case(self, case):
+ """Mark the case for anonymization and handle SetDataException.
+ Derived classes may override or extend this method if they need
+ to handle more exceptions.
+
+ The method returns a rendered HTML page with the success or
+ error message.
+ """
+ try:
+ case.make_anonymizable()
+ case.markAnonymize()
+
+ c.dialog_title = _(u"Case marked for anonymisation.")
+ c.dialog_text = _(u"The case document has been marked for"
+ u" anonymisation and has been given to the"
+ u" administration for final anonymisation."
+ u" Please click on OK, to get back to the"
+ u" overview.")
+ c.url_ok = h.url_for(controller="/case_overview")
+ session['render_mode'] = 'ro'
+ session.save()
+ return render('/casemanagement/dialogs/success_markanonymize.mako')
+ except SetDataException, e:
+ log.exception("SetDataException while trying to mark case %d for"
+ " anonymization", case.id)
+ errors = []
+ for k, values in e.errors.iteritems():
+ for v in values:
+ errors.append(v.msg)
+ c.dialog_title = _(u"Anonymisation not possible.")
+ c.dialog_text = _(u"The case could not be anonymised for the"
+ u" following reason:</p>"
+ u"<p><i>%s</i></p>"
+ u"<p>Please click on OK to geht back to the"
+ u" overview.</p>""") % "<br>".join(errors)
+ c.url_ok = h.url_for(controller='/case', action='select',
+ id=case.id, confirmed=1)
+ return render('/casemanagement/dialogs/failed_markanonymize.mako')
+
+
@checkRole('admin')
def anonymize(self, id, confirmed):
id = self._checkInt(id)
More information about the Mpuls-commits
mailing list