selectors.py
changeset 2084 923788d1f9c6
parent 2082 633b175811d0
child 2181 94ca417b9b07
equal deleted inserted replaced
2083:f8f94c2951d3 2084:923788d1f9c6
   418 def anonymous_user():
   418 def anonymous_user():
   419     return ~ authenticated_user()
   419     return ~ authenticated_user()
   420 
   420 
   421 @objectify_selector
   421 @objectify_selector
   422 @lltrace
   422 @lltrace
   423 def primary_view(cls, req, rset, row=None, col=0, view=None, **kwargs):
   423 def primary_view(cls, req, rset=None, row=None, col=0, view=None, **kwargs):
   424     """accept if view given as named argument is a primary view, or if no view
   424     """accept if view given as named argument is a primary view, or if no view
   425     is given
   425     is given
   426     """
   426     """
   427     if view is not None and not view.is_primary():
   427     if view is not None and not view.is_primary():
   428         return 0
   428         return 0
   429     return 1
   429     return 1
   430 
   430 
   431 @objectify_selector
   431 @objectify_selector
   432 @lltrace
   432 @lltrace
   433 def match_context_prop(cls, req, rset, row=None, col=0, context=None,
   433 def match_context_prop(cls, req, rset=None, row=None, col=0, context=None,
   434                        **kwargs):
   434                        **kwargs):
   435     """accept if:
   435     """accept if:
   436     * no context given
   436     * no context given
   437     * context (`basestring`) is matching the context property value for the
   437     * context (`basestring`) is matching the context property value for the
   438       given cls
   438       given cls
   459     def __str__(self):
   459     def __str__(self):
   460         return '%s(%s)' % (self.__class__.__name__,
   460         return '%s(%s)' % (self.__class__.__name__,
   461                            ','.join(sorted(str(s) for s in self.expected)))
   461                            ','.join(sorted(str(s) for s in self.expected)))
   462 
   462 
   463     @lltrace
   463     @lltrace
   464     def __call__(self, cls, req, rset, row=None, col=0, **kwargs):
   464     def __call__(self, cls, req, rset=None, row=None, col=0, **kwargs):
   465         try:
   465         try:
   466             if not req.search_state[0] in self.expected:
   466             if not req.search_state[0] in self.expected:
   467                 return 0
   467                 return 0
   468         except AttributeError:
   468         except AttributeError:
   469             return 1 # class doesn't care about search state, accept it
   469             return 1 # class doesn't care about search state, accept it
   552 class match_view(match_search_state):
   552 class match_view(match_search_state):
   553     """accept if the current view is in one of the expected vid given to the
   553     """accept if the current view is in one of the expected vid given to the
   554     initializer
   554     initializer
   555     """
   555     """
   556     @lltrace
   556     @lltrace
   557     def __call__(self, cls, req, rset, row=None, col=0, view=None, **kwargs):
   557     def __call__(self, cls, req, rset=None, row=None, col=0, view=None, **kwargs):
   558         if view is None or not view.id in self.expected:
   558         if view is None or not view.id in self.expected:
   559             return 0
   559             return 0
   560         return 1
   560         return 1
   561 
   561 
   562 
   562 
   569     """
   569     """
   570     def __init__(self, registry, oid):
   570     def __init__(self, registry, oid):
   571         self.registry = registry
   571         self.registry = registry
   572         self.oid = oid
   572         self.oid = oid
   573 
   573 
   574     def __call__(self, cls, req, rset, *args, **kwargs):
   574     def __call__(self, cls, req, rset=None, *args, **kwargs):
   575         try:
   575         try:
   576             cls.vreg.select(self.registry, self.oid, req, rset=rset, **kwargs)
   576             cls.vreg.select(self.registry, self.oid, req, rset=rset, **kwargs)
   577             return 1
   577             return 1
   578         except NoSelectableObject:
   578         except NoSelectableObject:
   579             return 0
   579             return 0
   848     def __init__(self, action, once_is_enough=False):
   848     def __init__(self, action, once_is_enough=False):
   849         super(has_permission, self).__init__(once_is_enough)
   849         super(has_permission, self).__init__(once_is_enough)
   850         self.action = action
   850         self.action = action
   851 
   851 
   852     @lltrace
   852     @lltrace
   853     def __call__(self, cls, req, rset, row=None, col=0, **kwargs):
   853     def __call__(self, cls, req, rset=None, row=None, col=0, **kwargs):
   854         if rset is None:
   854         if rset is None:
   855             return 0
   855             return 0
   856         user = req.user
   856         user = req.user
   857         action = self.action
   857         action = self.action
   858         if row is None:
   858         if row is None:
   933             return 0
   933             return 0
   934 
   934 
   935     def __repr__(self):
   935     def __repr__(self):
   936         return u'<rql_condition "%s" at %x>' % (self.rql, id(self))
   936         return u'<rql_condition "%s" at %x>' % (self.rql, id(self))
   937 
   937 
       
   938 
   938 class but_etype(EntitySelector):
   939 class but_etype(EntitySelector):
   939     """accept if the given entity types are not found in the result set.
   940     """accept if the given entity types are not found in the result set.
   940 
   941 
   941     See `EntitySelector` documentation for behaviour when row is not specified.
   942     See `EntitySelector` documentation for behaviour when row is not specified.
   942 
   943