Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(14)  |  Call(12)  |  Derive(0)  |  Import(2)

src/m/e/mediadrop-HEAD/mediadrop/lib/auth/permission_system.py   mediadrop(Download)
 
from mediadrop.lib.auth.api import PermissionSystem, UserPermissions
from mediadrop.lib.auth.query_result_proxy import QueryResultProxy, StaticQuery
from mediadrop.model import DBSession, Group, User
from mediadrop.plugin.abc import AbstractClass, abstractmethod
        can_access_item = \
            lambda item: perm.contains_permission(permission_name, item.resource)
        return QueryResultProxy(query, filter_=can_access_item)
 
    def raise_error(self, permission, resource):
            result = policy.access_condition_for_query(query, permission_name, perm)
            if result == True:
                return QueryResultProxy(query)
            elif result == False:
                return StaticQuery([])
            return StaticQuery([])
        restricted_query = query.distinct().filter(or_(*conditions))
        return QueryResultProxy(restricted_query)
 
 

src/m/e/mediadrop-HEAD/mediadrop/lib/auth/tests/query_result_proxy_test.py   mediadrop(Download)
from sqlalchemy.orm import sessionmaker
 
from mediadrop.lib.auth.query_result_proxy import QueryResultProxy
from mediadrop.lib.test.pythonic_testcase import *
 
        self._populate_database()
        self.query = self.session.query(User).order_by(asc(User.id))
        self.proxy = QueryResultProxy(self.query)
 
    def _tearDown(self):
    def test_can_fetch_single_item(self):
        filter_ = lambda item: item.activity >= 4
        self.proxy = QueryResultProxy(self.query, filter_=filter_)
        assert_equals('quuux', self._name(self.proxy.first()))
        assert_equals(None, self.proxy.first())
    def test_can_initialize_proxy_with_offset(self):
        self.proxy = QueryResultProxy(self.query, start=2)
        assert_equals(['baz', 'quux'], self._next_names(n=2))
 
    def test_can_specify_filter_callable(self):
        filter_ = lambda item: item.activity % 2 == 1
        self.proxy = QueryResultProxy(self.query, filter_=filter_)