add the match_http_method predicate (closes #2559932)
authorDavid Douard <david.douard@logilab.fr>
Thu, 17 Jan 2013 14:55:07 +0100
changeset 8751 1a97d46701e7
parent 8750 405d63b8fa6f
child 8752 e19f4bba89cd
add the match_http_method predicate (closes #2559932) This aim at creating views which are selected on other HTTP methods (PUT, DELETE, ...)
predicates.py
--- a/predicates.py	Thu Mar 21 18:35:19 2013 +0100
+++ b/predicates.py	Thu Jan 17 14:55:07 2013 +0100
@@ -1470,6 +1470,15 @@
         return frozenset(req.form)
 
 
+class match_http_method(ExpectedValuePredicate):
+    """Return non-zero score if one of the HTTP methods specified as
+    initializer arguments is the HTTP method of the request (GET, POST, ...).
+    """
+
+    def __call__(self, cls, req, **kwargs):
+        return int(req.http_method() in self.expected)
+
+
 class match_edited_type(ExpectedValuePredicate):
     """return non-zero if main edited entity type is the one specified as
     initializer argument, or is among initializer arguments if `mode` == 'any'.