[Mpuls-commits] r5479 - jmd/trunk/jmdweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 18 11:43:25 CEST 2011
Author: bh
Date: 2011-10-18 11:43:23 +0200 (Tue, 18 Oct 2011)
New Revision: 5479
Modified:
jmd/trunk/jmdweb/controllers/case.py
Log:
Implement _get_validator instead of reimplementing newAction in
CaseController. The reason newAction was reimplemented in JMD was to add
new fields to the new case form. This is much easier achieved now by
simply overriding the _get_validator method and use the base class
version of newAction.
Fixes the JMD part of mpuls/issue2424.
Modified: jmd/trunk/jmdweb/controllers/case.py
===================================================================
--- jmd/trunk/jmdweb/controllers/case.py 2011-10-17 08:49:49 UTC (rev 5478)
+++ jmd/trunk/jmdweb/controllers/case.py 2011-10-18 09:43:23 UTC (rev 5479)
@@ -31,15 +31,6 @@
import logging
-import formencode
-
-from mpulsweb.lib.base import c, g, render, request, session
-from mpulsweb.lib.security import checkRole
-
-from mpulsweb.model.case import SessionCase, Agency
-from mpulsweb.model.statement import PrivacyStatement
-
-from mpulsweb.controllers.formularpage import convert2dic
from mpulsweb.controllers.case import CaseController as MpulsCaseController
from jmdweb.lib.validators import NewCaseForm
@@ -48,55 +39,8 @@
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):
+ return NewCaseForm()
- session['case'] = session_case
- session.save()
- # 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)
- # 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))
-
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
More information about the Mpuls-commits
mailing list