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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 15 14:44:53 CEST 2010


Author: torsten
Date: 2010-04-15 14:44:52 +0200 (Thu, 15 Apr 2010)
New Revision: 2375

Modified:
   wasko/branches/2.0/mpulsweb/model/case.py
Log:
* mpulsweb/model/case.py (MpulsCase.get_value): Fixed Wald #1359. If
getting values from the formedtree fails (e.g like bearbeiter_id which
is not defined in the formed) try to look for it the the presents
which are preloaded.


Modified: wasko/branches/2.0/mpulsweb/model/case.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/case.py	2010-04-15 11:09:01 UTC (rev 2374)
+++ wasko/branches/2.0/mpulsweb/model/case.py	2010-04-15 12:44:52 UTC (rev 2375)
@@ -542,6 +542,7 @@
     def __getattr__(self, name):
         """Provide attribute like access to some fields for compatibility"""
         field = self.alias_dict.get(name)
+        log.debug('field: %s' % field)
         if field:
             try:
                 value = self.get_value(field.name)
@@ -579,7 +580,8 @@
         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.
+        loaded, the value will always be taken from there first. Only if this
+        does not work try to lookup the value in the present dictionary
 
         This behavior is intended as an optimization so that the case
         can be instantiated from e.g. a search result which returns the
@@ -590,11 +592,19 @@
         """
         # always use formed instance tree if available
         if self.formed_instance is not None:
+            print "present: %s" % self.preset
             item = self._get_formed_item(name)
             if item:
                 return item.getValue()
             else:
-                raise KeyError("Cannot find formed item for %r" % name)
+                # Item not found in formed. This my happen for fields which are
+                # not defined in the formed like "bearbeiter_id". Try to look
+                # if this value has been preloaded and is located in the
+                # presendt dict.
+                try:
+                    return self.preset[name]
+                except:
+                    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:
@@ -906,6 +916,7 @@
             query = LOAD_CASE_SQL % dict(fields=", ".join(fields))
             fields = {'id': id}
             c.execute(query, fields)
+            log.debug("Query: %s" % c.query)
             result = c.fetchone()
             if not result:
                 raise LoadCaseNotExistsError("Es konnte keine Fallakte geladen"



More information about the Mpuls-commits mailing list