[Mpuls-commits] r2009 - in waska/trunk: . waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Mar 18 15:16:12 CET 2010


Author: roland
Date: 2010-03-18 15:15:55 +0100 (Thu, 18 Mar 2010)
New Revision: 2009

Modified:
   waska/trunk/ChangeLog
   waska/trunk/waskaweb/lib/xmlimport.py
Log:
Add rules for CM start and end date to XML import/export

Modified: waska/trunk/ChangeLog
===================================================================
--- waska/trunk/ChangeLog	2010-03-18 14:01:55 UTC (rev 2008)
+++ waska/trunk/ChangeLog	2010-03-18 14:15:55 UTC (rev 2009)
@@ -1,3 +1,9 @@
+2010-03-18 Roland Geider <roland.geider at intevation.de>
+
+	Add the rules for CM start and end date to the XML import/export functions
+
+	* waskaweb/model/casexml.py: waskaweb/lib/xmlimport.py
+
 2010-03-16 Roland Geider <roland.geider at intevation.de>
 
 	Fix missing ">" in hidden fields

Modified: waska/trunk/waskaweb/lib/xmlimport.py
===================================================================
--- waska/trunk/waskaweb/lib/xmlimport.py	2010-03-18 14:01:55 UTC (rev 2008)
+++ waska/trunk/waskaweb/lib/xmlimport.py	2010-03-18 14:15:55 UTC (rev 2009)
@@ -28,12 +28,13 @@
 # Sascha L. Teichmann <teichmann at intevation.de>
 #
 import sys
+import re
+import datetime
+
 from datetime import date
-
 from xml.sax.saxutils import DefaultHandler
 from xml.sax          import parse
 
-import re
 
 def _int_converter(s):
     return int(s)
@@ -298,7 +299,9 @@
         "freie_dokumentation_abschlussbewertung": _text_converter,
         "beendigung_nachbetreuung": _date_converter,
         "zeitraum_nachbetreuung": _choice_converter,
-        "verbleib_nachbetreuung": _choice_converter
+        "verbleib_nachbetreuung": _choice_converter,
+        "teilnahme_evaluation": _choice_converter,
+        "evaluation_nummer": _text_converter
     },
     'kompetenzfestellung': {
         "verfahren_kompetenzfeststellung": _choice_converter,
@@ -506,6 +509,9 @@
 SQL_SELECT_UUID_FROM_RELATION = \
 """SELECT uuid_id FROM %s_tbl_view WHERE id = %%(id)s"""
 
+SQL_SELECT_CM_DATES_FROM_MASTER = \
+"""SELECT datum_feststellung, beendigung_5 FROM master_tbl_view WHERE id = %s"""
+
 SQL_CREATE_REPEAT_GROUP = \
 """SELECT %s(%%(master_id)s,  %%(uuid)s)"""
 
@@ -515,6 +521,14 @@
     row = cur.next()
     if not row: return None
     return row[0]
+    
+def get_cm_dates(cur, case_id):
+    """Load the beginning and the end dates from the Case Management"""
+    cur.execute(SQL_SELECT_CM_DATES_FROM_MASTER %  (case_id,))
+    row = cur.next()
+    if not row:
+        return None
+    return row
 
 def create_master(cur, uuid=None):
     cur.execute(SQL_CREATE_MASTER_DS, { 'uuid': uuid })
@@ -601,7 +615,7 @@
 
 class XMLHandler(DefaultHandler):
 
-    def __init__(self, case_store):
+    def __init__(self, case_store, cur):
         DefaultHandler.__init__(self)
         self.mode       = EXPECT_CASES
         self.ignore     = 0
@@ -609,6 +623,8 @@
         self.chars      = None
         self.case_store = case_store
         self.case       = None
+        self.uuid       = None
+        self.cursor     = cur
 
     def startElement(self, name, attrs):
         if self.mode == EXPECT_CASES:
@@ -663,7 +679,39 @@
                 self.relation.uuid = self.chars.strip().lower()
                 if not UUID_RE.match(self.relation.uuid):
                     raise StandardError("UUID is invalid")
+                self.uuid = self.chars.strip().lower()
                 #print >> sys.stderr, "uuid: %s" % self.relation.uuid
+                
+            # Special logic for date of beginning and end of the case management
+            #
+            # Kind of longish hack because the XML import from Waska does not compare
+            # the new data with the current data in the DB (to only update what needs
+            # to be updated)
+            if name in ['datum_feststellung', 'beendigung_5']:
+                try:
+                    cm_id = get_id_for_uuid(self.cursor, 'master', self.uuid)
+                except Expeption, e:
+                    print "Could not get ID from UUID"
+                
+                try:
+                    cm_date_data = get_cm_dates(self.cursor, cm_id)
+                except Exception, e:
+                    print "Could not load CM start/end dates"
+                
+                if cm_date_data != set():
+                    #print cm_date_data
+                    year, month, day = [int(x) for x in self.chars.strip().split("-")]
+                    new_cm_date = datetime.date(year, month, day)
+                    
+                    if name == 'datum_feststellung':
+                        old_cm_date = cm_date_data[0] # Start date of the CM
+                    else:
+                        old_cm_date = cm_date_data[1] # End date of the CM
+                    
+                    if old_cm_date != new_cm_date and new_cm_date < datetime.date(2010, 01, 01):
+                        print "new dates!"
+                        # Error text not really important since it will not be passed to the user
+                        raise StandardError("Datum darf nicht vor dem 1.1.2010 liegen")
 
             self.mode = EXPECT_FIELD
             self.chars = None
@@ -775,7 +823,7 @@
     try:
         cur = con.cursor()
         case_store = CaseStore(con, cur)
-        handler = XMLHandler(case_store)
+        handler = XMLHandler(case_store, cur)
         parse(f, handler)
     finally:
         if cur:



More information about the Mpuls-commits mailing list