[Mpuls-commits] r958 - in wasko/branches/2.0: . waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Jan 27 17:05:54 CET 2010
Author: bh
Date: 2010-01-27 17:05:54 +0100 (Wed, 27 Jan 2010)
New Revision: 958
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/waskaweb/model/case.py
Log:
Fetch instance variables of CaseDigest on demand from the instance
tree.
* waskaweb/model/case.py (CaseDigest.fields, CaseDigest._fields):
Renamed fields to _fields because it's only used internally.
(CaseDigest.__init__): Store id in instance variable id.
(CaseDigest._loadFromDB): Only create the intance tree and save it
in self._it. Any actual values needed are fetched on demand.
(CaseDigest.__getattr__): Fetch instance variables from the
instance tree, using self._names to map the currently used
instance variable names to the field descriptions.
(CaseDigest._names): New. Map instance variable names to field
descriptions.
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-01-27 16:00:26 UTC (rev 957)
+++ wasko/branches/2.0/ChangeLog 2010-01-27 16:05:54 UTC (rev 958)
@@ -1,5 +1,21 @@
2010-01-27 Bernhard Herzog <bh at intevation.de>
+ Fetch instance variables of CaseDigest on demand from the instance
+ tree.
+
+ * waskaweb/model/case.py (CaseDigest.fields, CaseDigest._fields):
+ Renamed fields to _fields because it's only used internally.
+ (CaseDigest.__init__): Store id in instance variable id.
+ (CaseDigest._loadFromDB): Only create the intance tree and save it
+ in self._it. Any actual values needed are fetched on demand.
+ (CaseDigest.__getattr__): Fetch instance variables from the
+ instance tree, using self._names to map the currently used
+ instance variable names to the field descriptions.
+ (CaseDigest._names): New. Map instance variable names to field
+ descriptions.
+
+2010-01-27 Bernhard Herzog <bh at intevation.de>
+
* waskaweb/model/case.py (log): Add logger.
2010-01-27 Bernhard Herzog <bh at intevation.de>
Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py 2010-01-27 16:00:26 UTC (rev 957)
+++ wasko/branches/2.0/waskaweb/model/case.py 2010-01-27 16:05:54 UTC (rev 958)
@@ -636,7 +636,7 @@
class CaseDigest:
- fields = [
+ _fields = [
CaseStringField("last_name", "name"),
CaseStringField("first_name", "vorname"),
CaseStringField("knr", "fn"),
@@ -661,33 +661,37 @@
CaseStringField("father_email", "vater_email"),
]
+ _names = {}
+ for _field in _fields:
+ _names[_field.name] = _field
def __init__(self, id):
+ self.id = id
self._loadFromDB(id)
def _loadFromDB(self, id):
result = {}
try:
factory = InstanceFactory(g.formedTree, PostgresDBInterface())
- it = factory.loadInstanceTreeByIdentifier(id)
-
- for field in self.fields:
- fid = get_field_identifier(id, field.dbname, it)
- print fid
- if not fid:
- continue
- item = it.getItem(fid)
- if not item:
- continue
- value = item.getValue()
- if not value:
- continue
- result[field.dbname] = value
+ self._it = factory.loadInstanceTreeByIdentifier(id)
except:
traceback.print_exc(file=sys.stderr)
- for field in self.fields:
- setattr(self, field.name, field.from_db(result.get(field.dbname)))
+ def __getattr__(self, name):
+ log.debug("CaseDigest.__getattr__: name = %r", name)
+ field = self._names.get(name)
+ if field is not None:
+ value = None
+ fid = get_field_identifier(self.id, field.dbname, self._it)
+ log.debug("CaseDigest.__getattr__: fid = %r", fid)
+ if fid:
+ item = self._it.getItem(fid)
+ if item:
+ value = item.getValue()
+ self.__dict__[name] = field.from_db(value)
+ return self.__dict__[name]
+ else:
+ raise AttributeError(name)
class SessionCase:
More information about the Mpuls-commits
mailing list