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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 17 22:41:25 CET 2011


Author: bh
Date: 2011-11-17 22:41:23 +0100 (Thu, 17 Nov 2011)
New Revision: 5598

Modified:
   base/trunk/mpulsweb/model/case.py
Log:
Add the method MpulsCase.get_formed_instance_tree.
This method returns the instance tree used by the case object, loading
it first, if necessary. It bypasses the abstraction provided by
MpulsCase but makes working with existing code easier. It will be useful
in particular in implementing mpuls/issue2367 because to perform the
additional access control checks we need to load case objects in places
where now we only load an instance tree and we want to avoid loading the
same instance tree multiple times.


Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2011-11-17 21:11:37 UTC (rev 5597)
+++ base/trunk/mpulsweb/model/case.py	2011-11-17 21:41:23 UTC (rev 5598)
@@ -634,6 +634,21 @@
             factory = InstanceFactory(g.formedTree, PostgresDBInterface())
             self.formed_instance = factory.loadInstanceTreeByIdentifier(self.id)
 
+    def get_formed_instance_tree(self):
+        """Return the formed instance tree associated with the case object.
+        The instance tree will be loaded if hasn't been loaded yet.
+
+        This method is meant as a way to improve older code that
+        directly deals with the formed instance tree. By using the case
+        object's instance tree, it's possible in some cases to avoid
+        explicitly loading the instance tree separately and redundantly.
+
+        Also, it's possible to perform additional access permission
+        checks using the user_may_read and user_may_edit methods.
+        """
+        self._load_formed_instance_tree()
+        return self.formed_instance
+
     def get_formed_item(self, name):
         self._load_formed_instance_tree()
         # Some fields are not part of the formed tree because they are preset



More information about the Mpuls-commits mailing list