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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 5 18:21:36 CET 2010


Author: bh
Date: 2010-02-05 18:21:33 +0100 (Fri, 05 Feb 2010)
New Revision: 1289

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/waskaweb/model/case.py
Log:
* waskaweb/model/case.py (SessionCase.__init__): Make it possible
to pass all values that have to be stored in the session case in
the constructor.  The case fields are defined by the
Case.get_session_fields emthod.
(SessionCase.setData, SessionCase.toFormData)
(Case.getSessionCase): Use get_session_fields to decide which
attributes/fields to copy
(Case.get_session_fields): new.  Returns a list of alias
description for all fields that should be stored in the session
case.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-02-05 17:08:16 UTC (rev 1288)
+++ wasko/branches/2.0/ChangeLog	2010-02-05 17:21:33 UTC (rev 1289)
@@ -1,5 +1,18 @@
 2010-02-05  Bernhard Herzog  <bh at intevation.de>
 
+	* waskaweb/model/case.py (SessionCase.__init__): Make it possible
+	to pass all values that have to be stored in the session case in
+	the constructor.  The case fields are defined by the
+	Case.get_session_fields emthod.
+	(SessionCase.setData, SessionCase.toFormData)
+	(Case.getSessionCase): Use get_session_fields to decide which
+	attributes/fields to copy
+	(Case.get_session_fields): new.  Returns a list of alias
+	description for all fields that should be stored in the session
+	case.
+
+2010-02-05  Bernhard Herzog  <bh at intevation.de>
+
 	* waskaweb/model/case.py (AliasDescription.__init__): Add
 	parameter and isntance variable in_session, which indicates
 	whether the attribute should be available in the SessionCase

Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py	2010-02-05 17:08:16 UTC (rev 1288)
+++ wasko/branches/2.0/waskaweb/model/case.py	2010-02-05 17:21:33 UTC (rev 1289)
@@ -553,25 +553,20 @@
     """This class holds all needed information for the currently selected case
     """
 
-    def __init__(self, id=None):
+    def __init__(self, id=None, page_id=None, state=None,
+                 privacy_statement=False, **kw):
         if id is None:
             self.id = None
         else:
             self.id = int(id)
-        self.page_id           = None
-        self.last_name         = None
-        self.first_name        = None
-        self.knr               = None
-        self.state             = None
-        self.first_meeting     = None
-        self.cm_end            = None
-        self.privacy_statement = False
 
-        self.street   = None
-        self.streetnr = None
-        self.plz      = None
-        self.city     = None
+        self.page_id = page_id
+        self.state = state
+        self.privacy_statement = privacy_statement
 
+        for desc in Case.get_session_fields():
+            setattr(self, desc.name, kw.get(desc.name, desc.default))
+
     def getState(self):
         return self.state
 
@@ -585,22 +580,15 @@
         return self.privacy_statement
 
     def setData(self, params):
-        self.last_name  = save_getone(params, "name",    "")
-        self.first_name = save_getone(params, "vorname", "")
-        self.street     = save_getone(params, "addresse_strasse",   "")
-        self.streetnr   = save_getone(params, "addresse_strassenr", "")
-        self.plz        = save_getone(params, "addresse_plz",       "")
-        self.city       = save_getone(params, "addresse_ort",   "")
+        for desc in Case.get_session_fields():
+            setattr(self, desc.name, desc.convert(save_getone(params,
+                                                              desc.formedname,
+                                                              desc.default)))
 
     def toFormData(self):
-        return {
-            'addresse_strasse'  : self.street,
-            'addresse_strassenr': self.streetnr,
-            'addresse_plz'      : self.plz,
-            'addresse_ort'  : self.city,
-            'name'   : self.last_name,
-            'vorname': self.first_name
-        }
+        data = {}
+        for name, formedname, default, converter in Case.get_session_fields():
+            data[formedname] = getattr(self, name)
 
     def isYoungerThan(self, mydate):
         """Return True if case was active relative to mydate.
@@ -709,6 +697,14 @@
         """
         return [item.name for item in cls.aliases]
 
+    @classmethod
+    def get_session_fields(cls):
+        """Return a list describing the fields to store in the session case.
+        The items of the list are those items of cls.alias whose
+        in_session attribute is true.
+        """
+        return [alias for alias in cls.aliases if alias.in_session]
+
     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
@@ -790,16 +786,13 @@
 
     def getSessionCase(self):
         """Return a SessionCase object initialized from the current case"""
-        session                   = SessionCase(self.id)
-        session.last_name         = self.last_name
-        session.first_name        = self.first_name
-        session.knr               = self.knr
-        session.state             = self.state
-        session.first_meeting     = self.first_meeting
-        session.cm_end            = self.cm_end
-        privacy_statement         = self.getPrivacyStatement()
-        session.privacy_statement = privacy_statement.isSigned()
-        return session
+        fields = dict()
+        for desc in self.get_session_fields():
+            fields[desc.name] = self.get_value(desc.formedname)
+        signed = self.getPrivacyStatement().isSigned()
+        return SessionCase(self.id, state=self.state,
+                           privacy_statement=signed,
+                           **fields)
 
     def getStandin(self):
         """Returns the standin of the case"""



More information about the Mpuls-commits mailing list