[Mpuls-commits] r5618 - base/trunk/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 18 20:50:50 CET 2011


Author: bh
Date: 2011-11-18 20:50:41 +0100 (Fri, 18 Nov 2011)
New Revision: 5618

Modified:
   base/trunk/mpulsweb/model/case.py
Log:
Allow the MpulsCase to be instantiated with an uncommitted fields dictionary.
This involves adding a corresponding parameter to the case factory and
the case constructor and passing it on to the instance tree factory when
the instance tree is finally created by the case class.

This change prepares for the extended access checks for the formularpage
controller which will be extended to load cases via the _loadCase method
and we want to avoid having to instantiate the instance tree too many
times.

This is part of the changes for mpuls/issue2367.


Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2011-11-18 19:38:34 UTC (rev 5617)
+++ base/trunk/mpulsweb/model/case.py	2011-11-18 19:50:41 UTC (rev 5618)
@@ -546,7 +546,8 @@
 class MpulsCase(object):
 
     def __init__(self, id=None, preset=None, state_id=None, state_status=None,
-                 state_access=None, state_phase=None, tags=None, editor_id=None):
+                 state_access=None, state_phase=None, tags=None,
+                 uncommitted=None, editor_id=None):
         self.id = id
         if preset is None:
             preset = dict()
@@ -557,6 +558,7 @@
         self.documents = []
         self.appointments = []
         self.tags = tags
+        self.uncommitted = uncommitted
         self.privacy_statement = None
         self.editor_id = editor_id
         self.init_state(state_id, state_status, state_access, state_phase)
@@ -632,7 +634,8 @@
     def _load_formed_instance_tree(self):
         if self.formed_instance is None:
             factory = InstanceFactory(g.formedTree, PostgresDBInterface())
-            self.formed_instance = factory.loadInstanceTreeByIdentifier(self.id)
+            self.formed_instance = factory.loadInstanceTreeByIdentifier(
+                self.id, uncommited=self.uncommitted)
 
     def get_formed_instance_tree(self):
         """Return the formed instance tree associated with the case object.
@@ -1215,8 +1218,12 @@
                     for name in self.case_cls.get_preset_fields()
                     if result.has_key(name))
 
-    def loadById(self, id):
-        """Load a case with the given id. Return a case object"""
+    def loadById(self, id, uncommitted=None):
+        """Load a case with the given id. Return a case object.
+        The parameter uncommitted should be a dictionary with
+        uncommitted fields. It will be passed through to the case class
+        constructor.
+        """
         # ideally, id should always be an int.  However, sometimes it's
         # given as a unicode object, so we explicitly convert to int.
         # FIXME: the callers should be changed so that id is always an int.
@@ -1240,7 +1247,7 @@
             db.recycleConnection(conn, c)
 
         return self.case_cls(id, preset=self._build_preset(result),
-                             tags=result['tags'])
+                             tags=result['tags'], uncommitted=uncommitted)
 
     def loadFromQueryResult(self, result):
         """Create a Case object from a DB query result row.



More information about the Mpuls-commits mailing list