[Mpuls-commits] r1164 - in wasko/branches/2.0: . waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Feb 2 17:26:15 CET 2010
Author: bh
Date: 2010-02-02 17:26:13 +0100 (Tue, 02 Feb 2010)
New Revision: 1164
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/waskaweb/model/case.py
Log:
* waskaweb/model/case.py (Case.get_preset_fields): New. Class
method to return a list of the field names that can be preset.
(CaseFactory._build_preset): New method to build a preset mapping
for the case object from a database query result
(CaseFactory.loadById): Pass id, state and the query result as the
preset mapping to the Case constructor instead of assigning
instance variables explicitly
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-02-02 16:13:51 UTC (rev 1163)
+++ wasko/branches/2.0/ChangeLog 2010-02-02 16:26:13 UTC (rev 1164)
@@ -1,5 +1,15 @@
2010-02-02 Bernhard Herzog <bh at intevation.de>
+ * waskaweb/model/case.py (Case.get_preset_fields): New. Class
+ method to return a list of the field names that can be preset.
+ (CaseFactory._build_preset): New method to build a preset mapping
+ for the case object from a database query result
+ (CaseFactory.loadById): Pass id, state and the query result as the
+ preset mapping to the Case constructor instead of assigning
+ instance variables explicitly
+
+2010-02-02 Bernhard Herzog <bh at intevation.de>
+
* waskaweb/model/case.py (Case.__init__): Add some parameters so
that the case can be instantiated without having to assign to
instance variables. This includes a parameter "preset" that can
Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py 2010-02-02 16:13:51 UTC (rev 1163)
+++ wasko/branches/2.0/waskaweb/model/case.py 2010-02-02 16:26:13 UTC (rev 1164)
@@ -375,9 +375,17 @@
"""Factory for case object. This factory provides methods to either load
existing cases from db or create new cases"""
+ def _build_preset(self, result):
+ return dict((name, result.get(name))
+ for name in Case.get_preset_fields())
+
def loadById(self, id):
"""Load a case with the given id. Return a case object"""
- case = Case()
+ # 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.
+ id = int(id)
+
result = None
conn, c = None, None
try:
@@ -392,15 +400,7 @@
finally:
db.recycleConnection(conn, c)
- case.id = int(id)
- case.last_name = ensure_unicode(result.get('name', ''))
- case.first_name = ensure_unicode(result.get('vorname', ''))
- case.knr = ensure_unicode(result.get('fn', ''))
- case.first_meeting = result.get('erstgespraech')
- case.cm_end = result.get('datum_cm_ende')
- case.editor = result.get('bearbeiter_id', None)
- case.state = State(id)
- return case
+ return Case(id, state=State(id), preset=self._build_preset(result))
def loadByName(self, id, first_name, last_name, knr, bearbeiter_id,
s_id, s_state, s_access):
@@ -815,6 +815,14 @@
return value
raise AttributeError(name)
+ @classmethod
+ def get_preset_fields(cls):
+ """Return a list with the names of formed fields that can be preset.
+ The list is intended to be used when populating the preset
+ mapping passed to the constructor.
+ """
+ return [value[0] for value in cls.aliases.itervalues()]
+
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
More information about the Mpuls-commits
mailing list