[Formed-commits] r296 - in trunk: . formed/formed formed/formed/model formed/formed/plugins formed/formed/plugins/modify
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 28 12:50:50 CET 2008
Author: teichmann
Date: 2008-11-28 12:50:49 +0100 (Fri, 28 Nov 2008)
New Revision: 296
Added:
trunk/formed/formed/plugins/modify/
trunk/formed/formed/plugins/modify/__init__.py
trunk/formed/formed/plugins/modify/rules.py
Modified:
trunk/ChangeLog
trunk/formed/formed/config.py
trunk/formed/formed/model/data.py
trunk/formed/formed/model/nodecomponents.py
Log:
Added stub for required fields rules generator. Ported WidgetCollector from Offline client.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-11-27 16:53:42 UTC (rev 295)
+++ trunk/ChangeLog 2008-11-28 11:50:49 UTC (rev 296)
@@ -1,3 +1,13 @@
+2008-11-28 Sascha L. Teichmann <teichmann at intevation.de>
+
+ * formed/formed/model/data.py, formed/formed/model/nodecomponents.py:
+ Ported WidgetCollector from Offline client.
+
+ * formed/formed/plugins/modify/__init__.py, formed/formed/plugins/modify,
+ formed/formed/plugins/modify/rules.py: Stub for required rules generator.
+
+ * formed/formed/config.py: Bind new filter to FormEd
+
2008-11-27 Torsten Irländer <torsten.irlaender at intevation.de>
* formed/formed/model/data.py: Added new attribute mark for rules
Modified: trunk/formed/formed/config.py
===================================================================
--- trunk/formed/formed/config.py 2008-11-27 16:53:42 UTC (rev 295)
+++ trunk/formed/formed/config.py 2008-11-28 11:50:49 UTC (rev 296)
@@ -25,6 +25,8 @@
from formed.plugins.export.xsd import ExportAsXMLSchema
from formed.plugins.export.xls import ExportKeyValueTableAsXLS
+from formed.plugins.modify.rules import GenerateRequiredRules
+
#from formed.plugins.export.old_sql import \
# ExportStoredProcedureFilter, \
# ExportViewsFilter
@@ -57,6 +59,7 @@
# ExportViewsFilter(),
ExportAsXMLSchema(),
ExportKeyValueTableAsXLS(),
+ GenerateRequiredRules(),
DataImportFilter(),
DataExportFilter()
]
Modified: trunk/formed/formed/model/data.py
===================================================================
--- trunk/formed/formed/model/data.py 2008-11-27 16:53:42 UTC (rev 295)
+++ trunk/formed/formed/model/data.py 2008-11-28 11:50:49 UTC (rev 296)
@@ -23,49 +23,33 @@
import os
-class PageNode(Node):
+class WidgetCollector(object):
+
def __init__(self):
- Node.__init__(self)
+ self.widgets = []
- def allWidgets(self, mode=None, allModes=None):
+ def visitor(self, nc):
+ if isinstance(nc, Node):
+ if isinstance(nc, (RadioNode, ChoiceNode)):
+ self.widgets.append(nc)
+ return VISIT_IGNORE_CHILDREN
+ if isinstance(nc, GroupNode) and nc.isRepeat() and nc != self:
+ return VISIT_IGNORE_CHILDREN
+ elif isinstance(nc, Leaf) and not isinstance(nc,
+ (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
+ self.widgets.append(nc)
- widgets = []
+ return VISIT_CONTINUE
- def visitor(nc):
- if isinstance(nc, Node):
- if isinstance(nc, (RadioNode, ChoiceNode)):
- widgets.append(nc)
- return VISIT_IGNORE_CHILDREN
- if isinstance(nc, GroupNode) and nc.isRepeat():
- return VISIT_IGNORE_CHILDREN
- elif isinstance(nc, Leaf) and not isinstance(nc,
- (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
- widgets.append(nc)
-
- return VISIT_CONTINUE
+class PageNode(Node):
+ def __init__(self):
+ Node.__init__(self)
- self.visit(visitor, mode, allModes)
-
- return widgets
+ def allWidgets(self, mode=None, allModes=None):
+ collector = WidgetCollector()
+ self.visit(collector.visitor, mode, allModes)
+ return collector.widgets
-# def allWidgets(self, mode=None, allModes=None):
-# widgets = []
-# for nc in self.walk(mode, allModes):
-# if isinstance(nc, Node):
-# if isinstance(nc, (RadioNode, ChoiceNode)):
-# widgets.append(nc)
-# elif isinstance(nc, Leaf):
-# if isinstance(nc, BoolLeaf):
-# parent = nc.parent
-# if isinstance(parent, (RadioNode, ChoiceNode)):
-# continue
-# widgets.append(nc)
-# elif isinstance(nc, (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
-# continue
-# else:
-# widgets.append(nc)
-#
-# return widgets
class GroupNode(Node):
def __init__(self):
Node.__init__(self)
@@ -87,26 +71,10 @@
self.setAttribute("invisible", invisible)
def allWidgets(self, mode=None, allModes=None):
+ collector = WidgetCollector()
+ self.visit(collector.visitor, mode, allModes)
+ return collector.widgets
- widgets = []
-
- def visitor(nc):
- if isinstance(nc, Node):
- if isinstance(nc, (RadioNode, ChoiceNode)):
- widgets.append(nc)
- return VISIT_IGNORE_CHILDREN
- if isinstance(nc, GroupNode) and nc.isRepeat() and nc != self:
- return VISIT_IGNORE_CHILDREN
- elif isinstance(nc, Leaf) and not isinstance(nc,
- (RuleLeaf, ExternalChoiceListLeaf, InfoLeaf)):
- widgets.append(nc)
-
- return VISIT_CONTINUE
-
- self.visit(visitor, mode, allModes)
-
- return widgets
-
class MatrixNode(GroupNode):
def __init__(self):
GroupNode.__init__(self)
Modified: trunk/formed/formed/model/nodecomponents.py
===================================================================
--- trunk/formed/formed/model/nodecomponents.py 2008-11-27 16:53:42 UTC (rev 295)
+++ trunk/formed/formed/model/nodecomponents.py 2008-11-28 11:50:49 UTC (rev 296)
@@ -411,4 +411,14 @@
if isinstance(nc, clazz):
yield nc
+ def visit(self, visitor, mode=None, parentModes=None):
+ if self.root:
+ self.root.visit(visitor)
+
+ def walk(self, mode=None, parentModes=None):
+ if self.root:
+ for nc in self.root.walk(mode, parentModes):
+ yield nc
+
+
# vim:set ts=4 sw=4 si et sta sts=4:
Added: trunk/formed/formed/plugins/modify/__init__.py
===================================================================
--- trunk/formed/formed/plugins/modify/__init__.py 2008-11-27 16:53:42 UTC (rev 295)
+++ trunk/formed/formed/plugins/modify/__init__.py 2008-11-28 11:50:49 UTC (rev 296)
@@ -0,0 +1 @@
+# do not delete me!
Added: trunk/formed/formed/plugins/modify/rules.py
===================================================================
--- trunk/formed/formed/plugins/modify/rules.py 2008-11-27 16:53:42 UTC (rev 295)
+++ trunk/formed/formed/plugins/modify/rules.py 2008-11-28 11:50:49 UTC (rev 296)
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007, 2008 by Intevation GmbH
+#
+# FormEd is free software under the terms of the
+# GNU General Public License Version 3. See file
+# LICENSE coming with the source of FormEd for details.
+#
+# Authors:
+# Sascha L. Teichmann <teichmann at intevation.de>
+
+from formed.plugins.plugin import Filter
+
+import formed.model.data as data
+
+class GenerateRequiredRules(Filter):
+
+ def getMenuName(self):
+ return u"Generate required rules"
+
+ def getDescription(self):
+ return u"Generate rules for fields that are required."
+
+ def filterDocument(self, main):
+ document = main.getDocument()
+ mode = main.getSelectedMode()
+ allModes = main.getAllModes()
+
+ collector = data.WidgetCollector()
+ document.visit(collector.visitor, mode, allModes)
+ widgets = collector.widgets
+ print len(widgets)
+
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 enc=utf-8 :
+
More information about the Formed-commits
mailing list