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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jan 25 16:43:54 CET 2010


Author: bh
Date: 2010-01-25 16:43:53 +0100 (Mon, 25 Jan 2010)
New Revision: 837

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/waskaweb/model/case.py
Log:
* waskaweb/model/case.py (CaseDigest.fields): New class variable
with a list of field descriptions
(CaseDigest._loadFromDB): Iterate over self.fields to read the
values from the instance tree and to set the instance variables.
(CaseField, CaseStringField, CaseAgeField, CaseStatementField):
New classes to describe the fields of the case digest.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-01-25 15:38:39 UTC (rev 836)
+++ wasko/branches/2.0/ChangeLog	2010-01-25 15:43:53 UTC (rev 837)
@@ -1,5 +1,14 @@
 2010-01-25  Bernhard Herzog  <bh at intevation.de>
 
+	* waskaweb/model/case.py (CaseDigest.fields): New class variable
+	with a list of field descriptions
+	(CaseDigest._loadFromDB): Iterate over self.fields to read the
+	values from the instance tree and to set the instance variables.
+	(CaseField, CaseStringField, CaseAgeField, CaseStatementField):
+	New classes to describe the fields of the case digest.
+
+2010-01-25  Bernhard Herzog  <bh at intevation.de>
+
 	* waskaweb/model/case.py (Case.getDigest): remove the parameter
 	empty and the Ürkan mode with it.  No caller uses it anymore.
 

Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py	2010-01-25 15:38:39 UTC (rev 836)
+++ wasko/branches/2.0/waskaweb/model/case.py	2010-01-25 15:43:53 UTC (rev 837)
@@ -742,83 +742,84 @@
             db.recycleConnection(con, cur)
 
 
-class CaseDigest:
+class CaseField(object):
 
-    def __init__(self, id):
-        self.resetValues(id)
-        self._loadFromDB(id)
+    def __init__(self, name, dbname=None):
+        self.name = name
+        if dbname is None:
+            dbname = name
+        self.dbname = dbname
 
-    def resetValues(self, id):
-        self.id              = id
-        self.first_name      = ''
-        self.last_name       = ''
-        self.knr             = ''
-        self.age             = '0'
-        self.plz             = ''
-        self.city            = ''
-        self.street          = ''
-        self.streetnr        = ''
-        self.email           = ''
-        self.telephone_1     = ''
-        self.telephone_2     = ''
-        self.telephone_more  = ''
-        self.mobiletel       = ''
-        self.statement       = False
+    @classmethod
+    def from_db(cls, obj):
+        return obj
 
-        # Parents of the children
-        self.mother_first_name  = ''
-        self.mother_last_name   = ''
-        self.mother_telephone_1 = ''
-        self.mother_telephone_2 = ''
-        self.mother_telephone_3 = ''
-        self.mother_telephone_4 = ''
-        self.mother_email       = ''
 
-        self.father_first_name  = ''
-        self.father_last_name   = ''
-        self.father_telephone_1 = ''
-        self.father_telephone_2 = ''
-        self.father_telephone_3 = ''
-        self.father_telephone_4 = ''
-        self.father_email       = ''
+class CaseStringField(CaseField):
 
+    @classmethod
+    def from_db(cls, obj):
+        if obj is None:
+            return u""
+        return unicode(str(obj), 'utf-8')
 
-    def hasSignedPrivacyStatement(self):
-        return self.statement
 
+class CaseAgeField(CaseField):
+
+    @classmethod
+    def from_db(cls, obj):
+        if obj is None:
+            obj = date.today()
+        return (date.today() - obj).days / 365 or ""
+
+
+class CaseStatementField(CaseField):
+
+    @classmethod
+    def from_db(cls, obj):
+        return obj >= 0
+
+
+class CaseDigest:
+
+    fields = [
+        CaseStringField("last_name", "name"),
+        CaseStringField("first_name", "vorname"),
+        CaseStringField("knr", "fn"),
+        CaseAgeField("age", "geburtsdatum"),
+        CaseStringField("street", "addresse_strasse"),
+        CaseStringField("streetnr", "addresse_strassenr"),
+        CaseStringField("plz", "addresse_plz"),
+        CaseStringField("city", "addresse_ort"),
+        CaseStringField("telephone_1", "addresse_vorwahl"),
+        CaseStringField("telephone_2", "addresse_telefonnummer"),
+        CaseStringField("telephone_more", "addresse_weiteretelefonnummern"),
+        CaseStringField("email", "addresse_email"),
+        CaseStatementField("statement", "einverstaendniserklaerung"),
+        CaseStringField("mother_first_name", "mutter_vn"),
+        CaseStringField("mother_last_name", "mutter_n"),
+        CaseStringField("mother_telephone_1", "mutter_vorwahl"),
+        CaseStringField("mother_telephone_2", "mutter_telefonnummer"),
+        CaseStringField("mother_email", "mutter_email"),
+        CaseStringField("father_first_name", "vater_vn"),
+        CaseStringField("father_last_name", "vater_n"),
+        CaseStringField("father_telephone_1", "vater_vorwahl"),
+        CaseStringField("father_telephone_2", "vater_telefonnummer"),
+        CaseStringField("father_email", "vater_email"),
+        ]
+
+
+    def __init__(self, id):
+        self._loadFromDB(id)
+
     def _loadFromDB(self, id):
         result = {}
         try:
             factory = InstanceFactory(g.formedTree, PostgresDBInterface())
             it = factory.loadInstanceTreeByIdentifier(id)
-            fields = [
-                'name',
-                'vorname',
-                'fn',
-                'geburtsdatum',
-                'addresse_strasse',
-                'addresse_strassenr',
-                'addresse_plz',
-                'addresse_ort',
-                'addresse_vorwahl',
-                'addresse_telefonnummer',
-                'addresse_weiteretelefonnummern',
-                'addresse_email',
-                'einverstaendniserklaerung',
-                'mutter_vn',
-                'mutter_n',
-                'mutter_vorwahl',
-                'mutter_telefonnummer',
-                'mutter_email',
-                'vater_vn',
-                'vater_n',
-                'vater_vorwahl',
-                'vater_telefonnummer',
-                'vater_email'
-            ]
 
-            for name in fields:
-                fid = get_field_identifier(id, name, it)
+            for field in self.fields:
+                fid = get_field_identifier(id, field.dbname, it)
                 print fid
                 if not fid:
                     continue
@@ -828,48 +829,14 @@
                 value = item.getValue()
                 if not value:
                     continue
-                result[name] = value
+                result[field.dbname] = value
         except:
             traceback.print_exc(file=sys.stderr)
 
-        self.last_name         = unicode(str(result.get('name', '')), 'utf-8')
-        self.first_name        = unicode(str(result.get('vorname', '')), 'utf-8')
-        self.knr               = unicode(str(result.get('fn')), 'utf-8')
-        self.plz               = unicode(str(result.get('addresse_plz', '')), 'utf-8')
-        self.street            = unicode(str(result.get('addresse_strasse', '')), 'utf-8')
-        self.streetnr          = unicode(str(result.get('addresse_strassenr', '')), 'utf-8')
-        self.city              = unicode(str(result.get('addresse_ort', '')), 'utf-8')
-        self.telephone_1       = unicode(str(result.get('addresse_vorwahl', '')), 'utf-8')
-        self.telephone_2       = unicode(str(result.get('addresse_telefonnummer', '')), 'utf-8')
+        for field in self.fields:
+            setattr(self, field.name, field.from_db(result.get(field.dbname)))
 
-        self.telephone_3       = ""
-        self.telephone_4       = ""
 
-        self.telephone_more    = unicode(str(result.get('addresse_weiteretelefonnummern', '')), 'utf-8')
-
-        self.email             = unicode(str(result.get('addresse_email', '')), 'utf-8')
-        td                     = date.today() - result .get('geburtsdatum', date.today())
-        self.age               = td.days/365 or ""
-        self.statement         = (result.get('einverstaendniserklaerung') >= 0)
-
-        # Parents of the kids
-        self.mother_first_name  = unicode(str(result.get('mutter_vn', '')), 'utf-8')
-        self.mother_last_name   = unicode(str(result.get('mutter_n', '')), 'utf-8')
-        self.mother_telephone_1 = unicode(str(result.get('mutter_vorwahl', '')), 'utf-8')
-        self.mother_telephone_2 = unicode(str(result.get('mutter_telefonnummer', '')), 'utf-8')
-        self.mother_telephone_3 = unicode(str(result.get('mutter_vorwahl', '')), 'utf-8')
-        self.mother_telephone_4 = unicode(str(result.get('mutter_telefonnummer', '')), 'utf-8')
-        self.mother_email       = unicode(str(result.get('mutter_email', '')), 'utf-8')
-
-        self.father_first_name  = unicode(str(result.get('vater_vn', '')), 'utf-8')
-        self.father_last_name   = unicode(str(result.get('vater_n', '')), 'utf-8')
-        self.father_telephone_1 = unicode(str(result.get('vater_vorwahl', '')), 'utf-8')
-        self.father_telephone_2 = unicode(str(result.get('vater_telefonnummer', '')), 'utf-8')
-        self.father_telephone_3 = unicode(str(result.get('vater_vorwahl', '')), 'utf-8')
-        self.father_telephone_4 = unicode(str(result.get('vater_telefonnummer', '')), 'utf-8')
-        self.father_email       = unicode(str(result.get('vater_email', '')), 'utf-8')
-
-
 class SessionCase:
 
     """This class holds all needed information for the currently selected case



More information about the Mpuls-commits mailing list