Пример #1
0
# used by the form.
auth = Auth({
    'demo': 'demo',
    'admin': 'admin',
    'grok': 'grok',
})


# The publisher is a 2 times component that is in charge of looking up
# the model and the view, given an URL.
# It relies on traversers to handle the publishing.
# Here, we provide a custom way to retrieve views, using a security-aware
# function.
# See `dawnlight` and `cromlech.dawnlight` for more information.
publisher = DawnlightPublisher(
    view_lookup=ViewLookup(view_locator(secure_query_view)),
).publish


class Session(object):

    def __init__(self, session):
        self.session = session

    def __enter__(self):
        setSession(self.session)
        return self.session

    def __exit__(self, type, value, traceback):
        # Traceback or not, we reset the session thread-local.
        # Exiting the block, we don't want the session set.
Пример #2
0
    # We init it here, just to have the view lookup working.
    from crom import monkey, implicit
    monkey.incompat()  # incompat means it changes the behavior of the iface
    implicit.initialize()  # we create a new registry and make it the default

    # we define our publisher
    from cromlech.dawnlight import DawnlightPublisher
    from cromlech.browser.interfaces import IView
    from cromlech.dawnlight import ViewLookup, view_locator
    from cromlech.webob.request import Request

    def query_view(request, context, name=""):
        return IView.component(context, request, name=name)

    view_lookup = ViewLookup(view_locator(query_view))
    Publisher = DawnlightPublisher(view_lookup=view_lookup)

    # We read the zodb conf and initialize it
    from cromlech.zodb import init_db_from_file
    with open(config['zodb']['config'], 'r') as fd:
        db = init_db_from_file(fd)

    # We create our ZODB connection manager
    import transaction
    from cromlech.zodb.controlled import Connection

    class ZODBApplication(object):
        def __init__(self, db):
            self.db = db

        async def handle(self, request):
Пример #3
0
 def get_publisher(self,
                   view_lookup=secured_view,
                   model_lookup=base_model_lookup):
     publisher = DawnlightPublisher(model_lookup, view_lookup)
     return publisher.publish