Ejemplo n.º 1
0
    # We can do it with a zcml file or manually.
    # 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
Ejemplo n.º 2
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.
Ejemplo n.º 3
0
from dolmen.template import TALTemplate

from cromlech.dawnlight import ViewLookup
from cromlech.dawnlight import view_locator, query_view
from cromlech.configuration.utils import load_zcml
from cromlech.i18n import register_allowed_languages


TEMPLATES_DIR = os.path.join(os.path.dirname(__file__), 'templates')


def get_template(filename):
    return TALTemplate(os.path.join(TEMPLATES_DIR, filename))


view_lookup = ViewLookup(view_locator(query_view))


def configuration(global_conf, zcml_file, langs):
    """A factory for the configuration middleware.
    It's usually used to initialize some parameters,
    register components and possibly wrap the requested
    apps.
    """

    # Read the ZCML
    # -------------
    # We make sure it's called only once.
    # There's no builtin safeguard to verify that.
    load_zcml(zcml_file)
Ejemplo n.º 4
0
        unconsumed = stack[:]
        while unconsumed:
            for consumer in self.lookup(obj):
                any_consumed, obj, unconsumed = consumer(
                    request, obj, unconsumed)
                if any_consumed:
                    notify(BeforeTraverseEvent(obj, request))
                    break
            else:
                break

        notify(ModelFoundEvent(obj, request))
        return obj, unconsumed


located_view = ViewLookup(view_locator(query_view))
base_model_lookup = UVCModelLookup()


class Site(object):

    def __init__(self, model, name):
        self.model = model
        self.name = name

    def __enter__(self):
        root = self.model(self.name)
        setSite(root)
        return root

    def __exit__(self, exc_type, exc_value, traceback):
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-

from .utils import security_check as component_protector
from . import Principal, Interaction, unauthenticated_principal

from cromlech.dawnlight import DawnlightPublisher
from cromlech.dawnlight import ViewLookup, view_locator, query_view
from ul.browser.publication import Publication, base_model_lookup
from cromlech.browser import getSession
from zope.security.proxy import removeSecurityProxy

secured_view = ViewLookup(component_protector(view_locator(query_view)))


class SecurePublication(Publication):

    layers = None

    def get_publisher(self,
                      view_lookup=secured_view,
                      model_lookup=base_model_lookup):
        publisher = DawnlightPublisher(model_lookup, view_lookup)
        return publisher.publish

    def get_credentials(self, environ):
        session = getSession()
        user = environ.get('REMOTE_USER') or session.get('username')
        return user

    def principal_factory(self, username):
        if username:
Ejemplo n.º 6
0
def restful_query_view(request, obj, name=""):
    method = request.method
    target = methods.get(method)
    result = queryMultiAdapter((obj, request), target, name=name)
    if result is None and method != FALLBACK:
        result = queryMultiAdapter((obj, request), target, name=name)
    return result


def view_querier(request, obj, name=""):
    if IRESTRequest.providedBy(request):
        return restful_query_view(request, obj, name)
    return query_view(request, obj, name)


view_lookup = ViewLookup(view_locator(view_querier))


class Site(object):

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

    def __enter__(self):
        setSite(self.root)
        return self.root

    def __exit__(self, exc_type, exc_value, traceback):
        setSite()

Ejemplo n.º 7
0
# -*- coding: utf-8 -*-

from .utils import security_check as component_protector
from . import Principal, Interaction, unauthenticated_principal

from cromlech.dawnlight import DawnlightPublisher
from cromlech.dawnlight import ViewLookup, view_locator, query_view
from ul.browser.publication import Publication, base_model_lookup
from cromlech.browser import getSession
from zope.security.proxy import removeSecurityProxy


secured_view = ViewLookup(component_protector(view_locator(query_view)))


class SecurePublication(Publication):

    layers = None

    def get_publisher(
            self, view_lookup=secured_view, model_lookup=base_model_lookup):
        publisher = DawnlightPublisher(model_lookup, view_lookup)
        return publisher.publish

    def get_credentials(self, environ):
        session = getSession()
        user = environ.get('REMOTE_USER') or session.get('username')
        return user

    def principal_factory(self, username):
        if username:
Ejemplo n.º 8
0
# It behaves like a dict but has an additional `authenticate` method
# used by the form.
auth = Auth({
    'demo': 'demo',
    'admin': 'admin',
})


# 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.