[Mpuls-commits] r5489 - waska/trunk/waskaweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Oct 21 12:59:04 CEST 2011
Author: bh
Date: 2011-10-21 12:59:04 +0200 (Fri, 21 Oct 2011)
New Revision: 5489
Modified:
waska/trunk/waskaweb/controllers/case.py
Log:
Don't reimplement CaseController.newAction for WASKA functionality.
Instead, implement the _get_validator and _add_custom_fields as
appropriate. They cover all the reason why newAction was reimplemented
in WASKA in the first place.
This fixes the WASKA part of mpuls/issue2424
Modified: waska/trunk/waskaweb/controllers/case.py
===================================================================
--- waska/trunk/waskaweb/controllers/case.py 2011-10-21 10:56:42 UTC (rev 5488)
+++ waska/trunk/waskaweb/controllers/case.py 2011-10-21 10:59:04 UTC (rev 5489)
@@ -31,16 +31,11 @@
import logging
-import formencode
+from mpulsweb.lib.base import c, render
-from mpulsweb.lib.base import c, g, render, request, session
-from mpulsweb.lib.security import checkRole
+from mpulsweb.model.case import Agency
-from mpulsweb.model.case import SessionCase, Agency
-from mpulsweb.model.statement import PrivacyStatement
-
-from mpulsweb.controllers.formularpage import convert2dic
-from mpulsweb.controllers.navigation import NavigationController
+from mpulsweb.controllers.navigation import NavigationController
from mpulsweb.controllers.case import CaseController as MpulsCaseController
from waskaweb.lib.validators import NewCaseForm
@@ -49,60 +44,14 @@
class CaseController(MpulsCaseController):
- @checkRole('cm_ka')
- def newAction(self):
- # TODO: Use htmlfill here!
- session_case = SessionCase()
- session_case.setData(request.params)
+ def _get_validator(self):
+ """Override base method to return WASKA specific validator."""
+ return NewCaseForm()
- session['case'] = session_case
- session.save()
- agency = Agency()
+ def _add_custom_fields(self):
+ """Override base method to add agencynumber to new cases."""
+ return dict(fkz=Agency().getFKZ())
- # Do we want to print the statement?
- if request.params.has_key('print'):
- c.print_version = 1
- statement = PrivacyStatement(session_case, agency)
- c.content = statement.fillout()
- return render('privacy/default_statement.mako')
-
- # Or do we want to store the new case?
- elif request.params.has_key('save'):
- validator = NewCaseForm()
- try:
- form_result = validator.to_python(request.params)
- # Add fkz of the agency to the form_result
- form_result['fkz'] = agency.getFKZ()
- # 1. Create a new case
- case = g.case_factory.createNew(data=convert2dic({}))
- case._load_formed_instance_tree()
- # Set data
- data = {}
- for k in convert2dic(form_result).keys():
- try:
- item = case.formed_instance.getAllItemsForName(k)[0]
- id = ":".join(item.getIdentifier().split(':')[1:])
- data["%s:%s" % (k,id)] = form_result.get(k)
- except:
- # some values within the formresult can not be found in
- # instance tree. e.g "statement_signed"
- pass
- case.formed_instance.setData(data)
- case.formed_instance.commit()
-
- statement = case.getPrivacyStatement()
- # 3. Do we want to sign the statement?
- if form_result.get('statement_signed'):
- statement.sign()
-
- except formencode.Invalid, error:
- log.debug("Invalid form data: %r", error)
- c.form_result = error.value
- c.form_errors = error.error_dict or {}
- return render('/casemanagement/new.mako')
-
- return self.select(str(case.id))
-
def print_AidplanStatement(self, id):
# Call navigation controller which will trigger rendering the right
# formularpage. Content of the formularpage (c.formular) will be user
More information about the Mpuls-commits
mailing list