selectors.py
changeset 8034 b07d61090706
parent 8032 bcb87336c7d2
child 8190 2a3c1b787688
child 8395 41729460d8c3
--- a/selectors.py	Fri Oct 28 10:34:12 2011 +0200
+++ b/selectors.py	Fri Oct 28 11:31:11 2011 +0200
@@ -406,11 +406,11 @@
 class ExpectedValueSelector(Selector):
     """Take a list of expected values as initializer argument and store them
     into the :attr:`expected` set attribute. You may also give a set as single
-    argument, which will be then be referenced as set of expected values,
+    argument, which will then be referenced as set of expected values,
     allowing modifications to the given set to be considered.
 
     You should implement one of :meth:`_values_set(cls, req, **kwargs)` or
-    :meth:`_get_value(cls, req, **kwargs)` method which should respectivly
+    :meth:`_get_value(cls, req, **kwargs)` method which should respectively
     return the set of values or the unique possible value for the given context.
 
     You may also specify a `mode` behaviour as argument, as explained below.
@@ -1505,6 +1505,30 @@
         return frozenset(req.form)
 
 
+class match_edited_type(ExpectedValueSelector):
+    """return non-zero if main edited entity type is the one specified as
+    initializer argument, or is among initializer arguments if `mode` == 'any'.
+    """
+
+    def _values_set(self, cls, req, **kwargs):
+        try:
+            return frozenset((req.form['__type:%s' % req.form['__maineid']],))
+        except KeyError:
+            return frozenset()
+
+
+class match_form_id(ExpectedValueSelector):
+    """return non-zero if request form identifier is the one specified as
+    initializer argument, or is among initializer arguments if `mode` == 'any'.
+    """
+
+    def _values_set(self, cls, req, **kwargs):
+        try:
+            return frozenset((req.form['__form_id'],))
+        except KeyError:
+            return frozenset()
+
+
 class specified_etype_implements(is_instance):
     """Return non-zero score if the entity type specified by an 'etype' key
     searched in (by priority) input context kwargs and request form parameters