[Mpuls-commits] r3328 - in base/trunk: . mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 3 18:47:57 CEST 2010


Author: bh
Date: 2010-08-03 18:47:55 +0200 (Tue, 03 Aug 2010)
New Revision: 3328

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/model/case.py
Log:
* mpulsweb/model/case.py (MPulsXMLImporter.import_xml): Extend
base class method to better handle rule violations.
(MPulsXMLImporter.format_errors): Helper method to format the rule
errors as HTML
Requires libformed revision 209:efef2d1727d3


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-08-03 15:17:45 UTC (rev 3327)
+++ base/trunk/ChangeLog	2010-08-03 16:47:55 UTC (rev 3328)
@@ -1,3 +1,11 @@
+2010-08-03  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/model/case.py (MPulsXMLImporter.import_xml): Extend
+	base class method to better handle rule violations.
+	(MPulsXMLImporter.format_errors): Helper method to format the rule
+	errors as HTML
+	Requires libformed revision 209:efef2d1727d3
+
 2010-08-03  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	Issue664:

Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py	2010-08-03 15:17:45 UTC (rev 3327)
+++ base/trunk/mpulsweb/model/case.py	2010-08-03 16:47:55 UTC (rev 3328)
@@ -1294,6 +1294,32 @@
 WHERE m.uuid_id = %(uuid)s
 """
 
+    def import_xml(self, db, infile):
+        """Extend the base class method to reformat rule violation exceptions
+        """
+        try:
+            XMLImporter.import_xml(self, db, infile)
+        except XMLImportException, e:
+            if e.set_data_errors:
+                raise XMLImportException(self.format_errors(e.uuid,
+                                                            e.set_data_errors))
+            raise
+
+    def format_errors(self, uuid, error_items):
+        out = []
+        out.append(h.escape(_("The case with UUID '%s' could not be"
+                              " imported due to rule violations") % uuid))
+        out.append("<ul>\n")
+        for key, errors in error_items.iteritems():
+            node_name = key.split(':')[0]
+            for error in errors:
+                element = g.formedTree.findByName(node_name)
+                out.append("<li><strong>%s:</strong> %s\n"
+                           % (h.escape(element.getDescription()),
+                              h.escape(error.msg)))
+        out.append("</ul>\n")
+        return h.literal("".join(out))
+
     def import_allowed(self, cursor, uuid):
         if self.uuid_anonymized(cursor, uuid):
             raise XMLImportException(u"Die Akte mit UUID '%s' ist bereits"



More information about the Mpuls-commits mailing list