[refactoring] Move MatchIsETypePredicate to a separate module
authorRabah Meradi <rabah.meradi@logilab.fr>
Fri, 24 Jul 2015 13:39:18 +0200
changeset 11600 473754eac7c1
parent 11599 f8ba6ea94af9
child 11601 23a62d151382
[refactoring] Move MatchIsETypePredicate to a separate module
pyramid_cubicweb/predicates.py
pyramid_cubicweb/rest_api.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pyramid_cubicweb/predicates.py	Fri Jul 24 13:39:18 2015 +0200
@@ -0,0 +1,18 @@
+"""Contains predicates used in Pyramid views.
+"""
+
+
+class MatchIsETypePredicate(object):
+    """A predicate that match if a given etype exist in schema.
+    """
+    def __init__(self, matchname, config):
+        self.matchname = matchname
+
+    def text(self):
+        return 'match_is_etype = %s' % self.matchname
+
+    phash = text
+
+    def __call__(self, info, request):
+        return info['match'][self.matchname].lower() in \
+            request.registry['cubicweb.registry'].case_insensitive_etypes
--- a/pyramid_cubicweb/rest_api.py	Fri Jul 24 13:40:36 2015 +0200
+++ b/pyramid_cubicweb/rest_api.py	Fri Jul 24 13:39:18 2015 +0200
@@ -4,22 +4,7 @@
 from pyramid.httpexceptions import HTTPNotFound
 from pyramid.view import view_config
 from pyramid_cubicweb.resources import EntityResource, ETypeResource
-
-
-class MatchIsETypePredicate(object):
-    def __init__(self, matchname, config):
-        self.matchname = matchname
-        self.etypes = frozenset(
-            k.lower() for k in config.registry['cubicweb.registry']['etypes'])
-
-    def text(self):
-        return 'match_is_etype = %s' % self.matchname
-
-    phash = text
-
-    def __call__(self, info, request):
-        return info['match'][self.matchname].lower() in \
-            request.registry['cubicweb.registry'].case_insensitive_etypes
+from pyramid_cubicweb.predicates import MatchIsETypePredicate
 
 
 @view_config(