[Formed-commits] r298 - in trunk: . formed/formed/plugins/export formed/formed/plugins/web

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 3 12:43:44 CET 2008


Author: teichmann
Date: 2008-12-03 12:43:43 +0100 (Wed, 03 Dec 2008)
New Revision: 298

Modified:
   trunk/ChangeLog
   trunk/formed/formed/plugins/export/xsd.py
   trunk/formed/formed/plugins/web/controllers.py
Log:
Added unknown int -999999 to integer
      fields as an accepted value. Generate schema for radio groups too.




Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-12-01 10:24:57 UTC (rev 297)
+++ trunk/ChangeLog	2008-12-03 11:43:43 UTC (rev 298)
@@ -1,3 +1,11 @@
+2008-12-03	Sascha L. Teichmann <teichmann at intevation.de>
+
+	* formed/formed/plugins/web/controllers.py: compute changeset more correctly in
+	  storage of fields.
+
+	* formed/formed/plugins/export/xsd.py: Added unknown int -999999 to integer
+	  fields as an accepted value. Generate schema for radio groups too.
+
 2008-12-01	Torsten Irländer <torsten.irlaender at intevation.de>
 
 	Added autmatic generation of required rules

Modified: trunk/formed/formed/plugins/export/xsd.py
===================================================================
--- trunk/formed/formed/plugins/export/xsd.py	2008-12-01 10:24:57 UTC (rev 297)
+++ trunk/formed/formed/plugins/export/xsd.py	2008-12-03 11:43:43 UTC (rev 298)
@@ -45,10 +45,17 @@
 
 <xs:simpleType name="simple_date_type">
   <xs:restriction base="xs:date">
-    <xs:pattern value="[0-9]{4}-[0-9]{2}-[0-9]{2}"/>
+    <xs:pattern value="[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}"/>
   </xs:restriction>
 </xs:simpleType>
 
+<xs:simpleType name="unknown_integer">
+  <xs:restriction base="xs:integer">
+    <xs:minInclusive value="-999999"/>
+    <xs:maxInclusive value="-999999"/>
+  </xs:restriction>
+</xs:simpleType>
+
 <xs:element name="repeat_group_type" abstract="true"/>
 
 <xs:element name="case">
@@ -165,7 +172,9 @@
     def dump(self, out):
         print >> out, '<xs:simpleType name="%s_type">' % self.name
         self.dumpAnnotation(out)
-        print >> out, '  <xs:restriction base="xs:integer">'
+        print >> out, '  <xs:union memberTypes="unknown_integer">'
+        print >> out, '    <xs:simpleType>'
+        print >> out, '      <xs:restriction base="xs:integer">'
 
         minV, maxV = self.nc.getMinValue(), self.nc.getMaxValue()
 
@@ -179,12 +188,14 @@
             minV, maxV = min(minV, maxV), max(minV, maxV)
 
         if not minV is None:
-            print >> out, '    <xs:minInclusive value="%d"/>' % minV
+            print >> out, '        <xs:minInclusive value="%d"/>' % minV
 
         if not maxV is None:
-            print >> out, '    <xs:maxInclusive value="%d"/>' % maxV
+            print >> out, '        <xs:maxInclusive value="%d"/>' % maxV
 
-        print >> out, '  </xs:restriction>'
+        print >> out, '      </xs:restriction>'
+        print >> out, '    </xs:simpleType>'
+        print >> out, '  </xs:union>'
         print >> out, '</xs:simpleType>'
 
 class EnumerationType:
@@ -369,8 +380,45 @@
 
     @checkMode
     def _createRadioGroup(self, radio):
-        print >> sys.stderr, "RadioGroup: %s (Not supported yet)" % radio.getName()
+        kvs = {}
+        keys_values = []
+        try:
+            for c in radio.children:
+                if isinstance(c, data.ExternalChoiceListLeaf):
+                    cc = c.getChildren()
+                    if cc:
+                        for ccc in cc:
+                            desc = ccc.getDescription()
+                            if not desc: desc = ""
+                            kvs[int(ccc.getValue())] = desc
+                elif isinstance(c, data.BoolLeaf):
+                    desc = c.getDescription()
+                    if not desc: desc = ""
+                    kvs[int(c.getValue())] = desc
+        except ValueError:
+            print >> sys.stderr, "WARNING: radio '%s' contains none integer values" % radio.getName()
+            return
 
+        if not kvs:
+            print >> sys.stderr, "WARNING: radio '%s' contains no values" % radio.getName()
+            return
+
+        keys_values = list(kvs.iteritems())
+        keys_values.sort()
+
+        enum_name = "enum_%d_type" % len(self.enums)
+
+        enum = EnumerationType(enum_name, keys_values)
+
+        base = self.findEnumeration(enum)
+
+        if not base:
+            base = enum
+            self.enums.append(enum)
+
+        self.tableStack[-1].appendItem(
+            BasedType(radio.getName(), radio, base.name))
+
     @checkMode
     def _createGroup(self, group):
         repeat = group.isRepeat()

Modified: trunk/formed/formed/plugins/web/controllers.py
===================================================================
--- trunk/formed/formed/plugins/web/controllers.py	2008-12-01 10:24:57 UTC (rev 297)
+++ trunk/formed/formed/plugins/web/controllers.py	2008-12-03 11:43:43 UTC (rev 298)
@@ -560,7 +560,10 @@
                     # Hopefully this one causes no trouble any more
                     old_errors.pop(k, None)
                     # the empty array is for the rules
-                    to_be_set[k] = (checkAndConvert(widget, value), [])
+                    nv = checkAndConvert(widget, value)
+                    ov = ds.getValue(k)
+                    if nv != ov:
+                        to_be_set[k] = (nv, [])
             except SematicError, inst:
                 ei = ErrorItem(pageName, value)
                 ei.addMessage(inst.value)
@@ -569,6 +572,11 @@
             except KeyError, inst:
                 pass
 
+        print "real changeset {"
+        for k, v in to_be_set.iteritems():
+            print "\t", k, ":", repr(v[0])
+        print "}"
+
         # flag to indicate if we should flush the page
         dirty = False
 



More information about the Formed-commits mailing list