[Mpuls-commits] r3322 - base/trunk/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 3 17:09:24 CEST 2010


Author: torsten
Date: 2010-08-03 17:09:24 +0200 (Tue, 03 Aug 2010)
New Revision: 3322

Modified:
   base/trunk/mpulsweb/controllers/case.py
Log:
* mpulsweb/controllers/case.py (_createCase): Moved logic to create a
new case into a new function which can be used from other controllers
too.


Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py	2010-08-03 15:07:39 UTC (rev 3321)
+++ base/trunk/mpulsweb/controllers/case.py	2010-08-03 15:09:24 UTC (rev 3322)
@@ -3,6 +3,8 @@
 import logging
 import formencode
 
+from formed.instance.tree import SetDataException
+
 from pylons import request, session, tmpl_context as c, app_globals as g
 from pylons.controllers.util import redirect_to
 
@@ -291,6 +293,29 @@
     # Create new case
     #
 
+    def _createCase(self, form_result):
+        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()
+        return case
+
     @checkRole('cm')
     def new(self):
         session_case = SessionCase()
@@ -324,28 +349,8 @@
             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()
-
+                # Create a new case
+                case = self._createCase(form_result)
             except formencode.Invalid, error:
                 log.debug("Invalid form data: %r", error)
                 c.form_result = error.value



More information about the Mpuls-commits mailing list