[Mpuls-commits] r324 - in wasko/trunk: . waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Mar 4 10:35:56 CET 2009


Author: teichmann
Date: 2009-03-04 10:35:54 +0100 (Wed, 04 Mar 2009)
New Revision: 324

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/model/casexml.py
Log:
Remove unicode problem with XML import.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-03-04 07:26:18 UTC (rev 323)
+++ wasko/trunk/ChangeLog.txt	2009-03-04 09:35:54 UTC (rev 324)
@@ -1,5 +1,10 @@
 2009-03-04	Sascha L. Teichmann	<teichmann at intevation.de>
 
+	* waskaweb/model/casexml.py: Fixed unicode problem and removed 
+	  debug output.
+
+2009-03-04	Sascha L. Teichmann	<teichmann at intevation.de>
+
 	Store cases to data base. This is an intermediate commit 
 	suffering from UnicodeDecodeErrors 
 	(Python's unicode support really s*cks).

Modified: wasko/trunk/waskaweb/model/casexml.py
===================================================================
--- wasko/trunk/waskaweb/model/casexml.py	2009-03-04 07:26:18 UTC (rev 323)
+++ wasko/trunk/waskaweb/model/casexml.py	2009-03-04 09:35:54 UTC (rev 324)
@@ -299,13 +299,15 @@
     return row[0]
 
 def store_changes(cur, changes, ds_id):
-    print >> sys.stderr, "changes: %s" % repr(changes)
     if not changes: return
     fields = ['%s = %%(%s)s' % (v, v) for v in changes.iterkeys()]
     update = SQL_UPDATE_MASTER % (",".join(fields), ds_id)
-    print >> sys.stderr, "%s" % repr(update)
     cur.execute(update, changes)
 
+def convert_from_db(s):
+    if type(s) == str: return unicode(s, 'utf-8')
+    return s
+
 def import_xml(f, formed):
 
     master_handler = MasterHandler(formed)
@@ -336,32 +338,26 @@
             create_case, data = True, None
 
             if master_handler.uuid:
-                print >> sys.stderr, "found uuid '%s'" % repr(master_handler.uuid)
+                #print >> sys.stderr, "found uuid '%s'" % repr(master_handler.uuid)
                 ds_id = get_id_for_uuid(cur, 'master', master_handler.uuid)
                 if not ds_id is None:
-                    pass
-                    print >> sys.stderr, "case %d already exists" % ds_id
+                    #print >> sys.stderr, "case %d already exists" % ds_id
                     cur.execute(SQL_SELECT_ALL_FROM_MASTER % { 'ds_id': ds_id })
                     row = cur.fetchone()
                     if not row:
                         raise StandardError("could not load data for id '%s'" % ds_id)
-                    data = dict(zip([n[0] for n in cur.description], row))
+                    data = dict(zip([n[0] for n in cur.description], map(convert_from_db, row)))
                     create_case = False
-                else:
-                    print >> sys.stderr, "case with uuid '%s' does not exists" % repr(
-                        master_handler.uuid)
-            else:
-                print >> sys.stderr, "case does not have an uuid"
-                #master_handler.uuid = str(uuid4())
+                #else:
+                #    print >> sys.stderr, "case with uuid '%s' does not exists" % repr(
+                #        master_handler.uuid)
+            #else:
+            #    print >> sys.stderr, "case does not have an uuid"
 
-            print >> sys.stderr, "I was here - 1"
-
             if data is None:
-                print >> sys.stderr, "preset case with defaults from formed"
+                # print >> sys.stderr, "preset case with defaults from formed"
                 data = formed.name2default
 
-            print >> sys.stderr, "I was here - 2"
-
             changed = {}
 
             def get_data(var):
@@ -370,20 +366,12 @@
                 except KeyError:
                     return data.get(var)
 
-            # now apply the rules
+            # apply the rules
 
-            print >> sys.stderr, "I was here - 3"
-
             errors = []
 
-            print >> sys.stderr, "len data: %d" % len(master_handler.data)
-
             for var, value in master_handler.data:
-                print >> sys.stderr, "checking rules for '%s': '%s'" % (
-                    var, repr(value))
                 old_value = get_data(var)
-                print >> sys.stderr, "t1: %s t2: %s" % (
-                    type(old_value), type(value))
                 if old_value == value: continue
 
                 rules = formed.getRulesForVariable(var)
@@ -410,18 +398,13 @@
                 if okay:
                     changed[var] = value
 
-            print >> sys.stderr, "errors: %s" % errors
             if errors:
                 raise StandardError("rule checking failed")
 
-            print >> sys.stderr, "I was here - 3"
             if create_case:
-                print >> sys.stderr, "I was here - 4"
                 ds_id = create_master(cur, master_handler.uuid)
 
-            print >> sys.stderr, "I was here - 5"
             store_changes(cur, changed, ds_id)
-            print >> sys.stderr, "I was here - 6"
 
             con.commit()
         except:



More information about the Mpuls-commits mailing list