[Mpuls-commits] r1641 - in wasko/branches/2.0: . waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 16 17:55:17 CET 2010


Author: bh
Date: 2010-02-16 17:55:13 +0100 (Tue, 16 Feb 2010)
New Revision: 1641

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/waskaweb/model/case.py
Log:
* waskaweb/model/case.py (CaseFactory.__init__): New.  Make it
possible to instantiate the CaseFactory with the case class to
instantiate.  Default is to use Case from the same module.
(CaseFactory._build_preset, CaseFactory.loadById)
(CaseFactory.loadById, CaseFactory.loadFromQueryResult)
(CaseFactory.createNew): Use the case class passed to the factory
to instantiate the case object and to access metadata about the
fields.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-02-16 16:51:05 UTC (rev 1640)
+++ wasko/branches/2.0/ChangeLog	2010-02-16 16:55:13 UTC (rev 1641)
@@ -1,5 +1,16 @@
 2010-02-16  Bernhard Herzog  <bh at intevation.de>
 
+	* waskaweb/model/case.py (CaseFactory.__init__): New.  Make it
+	possible to instantiate the CaseFactory with the case class to
+	instantiate.  Default is to use Case from the same module.
+	(CaseFactory._build_preset, CaseFactory.loadById)
+	(CaseFactory.loadById, CaseFactory.loadFromQueryResult)
+	(CaseFactory.createNew): Use the case class passed to the factory
+	to instantiate the case object and to access metadata about the
+	fields.
+
+2010-02-16  Bernhard Herzog  <bh at intevation.de>
+
 	* waskaweb/model/case.py (CaseList.getCases)
 	(CaseBundle.setEditor, CaseBundle.setStandin, CaseBundle.delete)
 	(CaseBundle.anonymize, CaseBundle.restore)

Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py	2010-02-16 16:51:05 UTC (rev 1640)
+++ wasko/branches/2.0/waskaweb/model/case.py	2010-02-16 16:55:13 UTC (rev 1641)
@@ -356,9 +356,15 @@
     """Factory for case object. This factory provides methods to either load
     existing cases from db or create new cases"""
 
+    def __init__(self, case_cls=None):
+        if case_cls is None:
+            case_cls = Case
+        self.case_cls = case_cls
+
     def _build_preset(self, result):
         return dict((name, result[name])
-                    for name in Case.get_preset_fields() if name in result)
+                    for name in self.case_cls.get_preset_fields()
+                    if name in result)
 
     def loadById(self, id):
         """Load a case with the given id. Return a case object"""
@@ -372,7 +378,7 @@
         try:
             conn = db.getConnection()
             c = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-            fields = Case.get_preload_fields()
+            fields = self.case_cls.get_preload_fields()
             query = LOAD_CASE_SQL % dict(fields=", ".join(fields))
             fields = {'id': id}
             c.execute(query, fields)
@@ -383,7 +389,8 @@
         finally:
             db.recycleConnection(conn, c)
 
-        return Case(id, state=State(id), preset=self._build_preset(result))
+        return self.case_cls(id, state=State(id),
+                             preset=self._build_preset(result))
 
     def loadFromQueryResult(self, result):
         """Create a Case object from a DB query result row.
@@ -398,7 +405,7 @@
         id = result["id"]
         state = State()
         state.setData(result["s_id"], id, result["status"], result["zugriff"])
-        return Case(id, state=state, preset=self._build_preset(result))
+        return self.case_cls(id, state=state, preset=self._build_preset(result))
 
     def createNew(self, init=True, uuid=None, data=None):
         """Create a new case in the database and return the case object.
@@ -417,7 +424,7 @@
         if init == True:
             self._initNewCase(id)
 
-        return Case(id)
+        return self.case_cls(id)
 
     def _updateMasterOnCreate(self, instance_tree, data):
         id = instance_tree.getRootNode().getIdentifier()



More information about the Mpuls-commits mailing list