two use cases for the 'not' selector tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 18 Feb 2009 20:25:12 +0100
branchtls-sprint
changeset 828 394927376a01
parent 827 3f08481e6e51
child 829 ea092805d8f8
two use cases for the 'not' selector
selectors.py
web/views/basetemplates.py
--- a/selectors.py	Wed Feb 18 20:23:43 2009 +0100
+++ b/selectors.py	Wed Feb 18 20:25:12 2009 +0100
@@ -346,17 +346,14 @@
 
 @objectify_selector
 @lltrace
-def anonymous_user(cls, req, *args, **kwargs):
+def authenticated_user(cls, req, *args, **kwargs):
     """accept if user is anonymous"""
     if req.cnx.anonymous_connection:
-        return 1
-    return 0
+        return 0
+    return 1
 
-@objectify_selector
-@lltrace
-def authenticated_user(cls, req, *args, **kwargs):
-    """accept if user is authenticated"""
-    return not anonymous_user()(cls, req, *args, **kwargs)
+def anonymous_user():
+    return ~ authenticated_user()
 
 @objectify_selector
 @lltrace
--- a/web/views/basetemplates.py	Wed Feb 18 20:23:43 2009 +0100
+++ b/web/views/basetemplates.py	Wed Feb 18 20:25:12 2009 +0100
@@ -75,15 +75,11 @@
         return 0
     return view.templatable
 
-@objectify_selector
-def non_templatable_view(cls, req, rset, *args, **kwargs):
-    return not templatable_view()(cls, req, rset, *args, **kwargs)
-
 
 class NonTemplatableViewTemplate(MainTemplate):
     """main template for any non templatable views (xml, binaries, etc.)"""
     id = 'main-template'
-    __select__ = non_templatable_view()
+    __select__ = ~ templatable_view()
     
     def call(self, view):
         view.set_request_content_type()