[Mpuls-commits] r2023 - wasko/branches/2.0/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 19 08:37:46 CET 2010


Author: torsten
Date: 2010-03-19 08:37:46 +0100 (Fri, 19 Mar 2010)
New Revision: 2023

Modified:
   wasko/branches/2.0/mpulsweb/model/case.py
Log:
Reordered functions


Modified: wasko/branches/2.0/mpulsweb/model/case.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/case.py	2010-03-19 07:33:05 UTC (rev 2022)
+++ wasko/branches/2.0/mpulsweb/model/case.py	2010-03-19 07:37:46 UTC (rev 2023)
@@ -453,6 +453,73 @@
         """Return a list with all names of fields to match in the search"""
         return [field.name for field in cls.fields if field.search_match]
 
+    def __getattr__(self, name):
+        """Provide attribute like access to some fields for compatibility"""
+        field = self.alias_dict.get(name)
+        if field:
+            try:
+                value = self.get_value(field.name)
+            except KeyError:
+                value = field.default
+            return field.convert(value)
+        raise AttributeError(name)
+
+    def _load_formed_instance_tree(self):
+        if self.formed_instance is None:
+            factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+            self.formed_instance = factory.loadInstanceTreeByIdentifier(self.id)
+
+    def _get_formed_item(self, name):
+        self._load_formed_instance_tree()
+        fid = get_field_identifier(self.id, name, self.formed_instance)
+        if fid:
+            return self.formed_instance.getItem(fid)
+        log.error('(_get_formed_item): Can not find %s' % name)
+        return None
+
+    def get_description(self, name):
+        """Return the description of the formed field given by name"""
+        if self.formed_instance is None:
+            self._load_formed_instance_tree()
+        item = self._get_formed_item(name)
+        if item:
+            return item.getMeta().getDescription()
+        else:
+            raise KeyError("Cannot find formed item for %r" % name)
+
+    def get_value(self, name, **kw):
+        """Return the value of the formed field given by name.
+        If the formed instance of the case has not yet been loaded, the
+        value is taken from the preset dictionary the case was
+        instantiated with.  If it's not in the preset dictionary, the
+        formed tree is loaded.  Once the formed instance has been
+        loaded, the value will always be taken from there.
+
+        This behavior is intended as an optimization so that the case
+        can be instantiated from e.g. a search result which returns the
+        commonly used fields without any further database queries.  The
+        other fields will be loaded on demand when they're actually
+        needed.  Once the formed instance has been created it takes
+        precedence over the preset fields.
+        """
+        # always use formed instance tree if available
+        if self.formed_instance is not None:
+            item = self._get_formed_item(name)
+            if item:
+                return item.getValue()
+            else:
+                raise KeyError("Cannot find formed item for %r" % name)
+
+        # if the instance tree has not yet been loaded, look in preset
+        if name in self.preset:
+            return self.preset[name]
+
+        # otherwise actually load the formed instance tree and repeat
+        # We should only get here if self.formed_instance is not set yet.
+        assert self.formed_instance is None
+        self._load_formed_instance_tree()
+        return self.get_value(name, **kw)
+
     def check_consistence(self, fields=None):
         """Raises ConsistenceCheckException if the case is not completly
         consistent up to the current phase. A case is consistent if no required
@@ -542,74 +609,6 @@
             raise
         return None
 
-    def __getattr__(self, name):
-        """Provide attribute like access to some fields for compatibility"""
-        field = self.alias_dict.get(name)
-        if field:
-            try:
-                value = self.get_value(field.name)
-            except KeyError:
-                value = field.default
-            return field.convert(value)
-        raise AttributeError(name)
-
-    def get_value(self, name, **kw):
-        """Return the value of the formed field given by name.
-        If the formed instance of the case has not yet been loaded, the
-        value is taken from the preset dictionary the case was
-        instantiated with.  If it's not in the preset dictionary, the
-        formed tree is loaded.  Once the formed instance has been
-        loaded, the value will always be taken from there.
-
-        This behavior is intended as an optimization so that the case
-        can be instantiated from e.g. a search result which returns the
-        commonly used fields without any further database queries.  The
-        other fields will be loaded on demand when they're actually
-        needed.  Once the formed instance has been created it takes
-        precedence over the preset fields.
-        """
-        # always use formed instance tree if available
-        if self.formed_instance is not None:
-            item = self._get_formed_item(name)
-            if item:
-                return item.getValue()
-            else:
-                raise KeyError("Cannot find formed item for %r" % name)
-
-        # if the instance tree has not yet been loaded, look in preset
-        if name in self.preset:
-            return self.preset[name]
-
-        # otherwise actually load the formed instance tree and repeat
-        # We should only get here if self.formed_instance is not set yet.
-        assert self.formed_instance is None
-        self._load_formed_instance_tree()
-        return self.get_value(name, **kw)
-
-    def get_description(self, name):
-        """Return the description of the formed field given by name"""
-        if self.formed_instance is None:
-            self._load_formed_instance_tree()
-        item = self._get_formed_item(name)
-        if item:
-            return item.getMeta().getDescription()
-        else:
-            raise KeyError("Cannot find formed item for %r" % name)
-
-    def _load_formed_instance_tree(self):
-        if self.formed_instance is None:
-            factory = InstanceFactory(g.formedTree, PostgresDBInterface())
-            self.formed_instance = factory.loadInstanceTreeByIdentifier(self.id)
-
-    def _get_formed_item(self, name):
-        self._load_formed_instance_tree()
-        fid = get_field_identifier(self.id, name, self.formed_instance)
-        if fid:
-            return self.formed_instance.getItem(fid)
-        log.error('(_get_formed_item): Can not find %s' % name)
-        return None
-
-
 class MpulsCaseFactory:
 
     """Factory for case object. This factory provides methods to either load



More information about the Mpuls-commits mailing list