Example #1
0
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)

    # Register the i18n preferences
    # -----------------------------
    # Needed by the templating system to resolve the
    # translation by retrieving the active language
    # from the request. All this system lives in `cromlech.i18n`.
    allowed = langs.strip().replace(',', ' ').split()
    register_allowed_languages(allowed)

    def app_wrapper(app):
        """The effective middleware. Here, we do not make use
        of the wrapping capabilities, but it can be used to
        add other explicit middlewares.
        """
        return app

    return app_wrapper
Example #2
0
def router(conf, session_key, zcml, dsn, name):
    allowed = ('de',)
    register_allowed_languages(allowed)
    config.ALLOWED_LANGUAGES = None

    load_zcml(zcml)

    setSecurityPolicy(GenericSecurityPolicy)

    # We register our SQLengine under a given name
    engine = create_engine(dsn, name)
    # We use a declarative base, if it exists we bind it and create
    engine.bind(Base)
    metadata = Base.metadata
    metadata.create_all(engine.engine, checkfirst=True)

    # Router
    root = URLMap()
    admin_app = Admin(session_key, engine, name)
    root['/admin'] = localize(admin_app)
    root['/'] = localize(User(session_key, engine, name))

    root.__runner__ = admin_app.__runner__

    return root
Example #3
0
def app_factory(global_conf, url, zcml, langs):
    # load the ZCML
    load_zcml(zcml)

    # register the allowed languages
    register_allowed_languages([lang.strip() for lang in langs.split(',')])

    # create, register and populate the base DB/Engine
    engine = create_and_register_engine(url, DB_KEY)
    engine.bind(Base)
    Base.metadata.create_all()
    return Application(engine)
Example #4
0
def routing(conf, files, **kwargs):
    languages = kwargs['langs']
    allowed = languages.strip().replace(',', ' ').split()
    allowed = ('de',)
    register_allowed_languages(allowed)

    load_zcml(kwargs['zcml'])

    setSecurityPolicy(GenericSecurityPolicy)
    name = kwargs.get('name', 'school')

    # We register our SQLengine under a given name
    if not 'engine' in kwargs:
        dsn = kwargs['dsn']    
        engine = create_engine(dsn, name)
    else:
        engine = EngineServer(kwargs['engine'], name)

    # We use a declarative base, if it exists we bind it and create
    engine.bind(Base)
    metadata = Base.metadata
    metadata.create_all(engine.engine, checkfirst=True)

    # Extract possible layer
    layer = kwargs.get('layer')
    if layer is not None:
        layer_iface = eval_loader(layer)
    else:
        layer_iface = None

    title = kwargs.get('title', 'BG ETEM')

    # We create the session wrappper
    session_key = "session"
    key = key_from_file(path.join(kwargs['root'], 'jwt.key'))
    session_wrapper = Session(key, 60, environ_key=session_key)

    # Applications configuration
    smtp = kwargs.get('smtp', '10.33.115.55')
    setup = Configuration(
        title, session_key, engine, name, None, layer_iface, smtp)

    # Router
    root = URLMap()
    quizz = localize(anonymous.Application(setup))
    root['/'] = localize(company.Application(setup))
    root['/register'] = localize(company.Registration(setup))
    root['/quizz'] = quizz
    root['/befragung'] = quizz
    root['/json'] = localize(remote.Application(setup))
    return session_wrapper(root.__call__)
Example #5
0
def keeper(global_conf, pubkey, dburl,
           zcml_file=None, portals=None, session_key="gatekeeper.session",
           langs="en,de,fr", **kwargs):

    engine = create_engine(dburl, "admin")
    engine.bind(Admin)

    """A factory used to bootstrap the TrajectApplication.
    As the TrajectApplication will use SQL, we use this
    'once and for all' kind of factory to configure the
    SQL connection and inject the demo datas.
    """
    if zcml_file is not None:
        load_zcml(zcml_file)

    if portals is not None:
        pconfig = ConfigParser.ConfigParser()
        pconfig.read(portals)
        for name in pconfig.sections():
            portal = dict(pconfig.items(name))
            xmlutil = XMLRPCPortal(
                portal['inner'], portal['title'], portal['outer'])
            getGlobalSiteManager().registerUtility(xmlutil, IPortal, name=name)

    allowed = langs.strip().replace(',', ' ').split()
    register_allowed_languages(allowed)
    site = GateKeeper(engine)

    def publisher(environ, start_response):

        @tlib.signed_cookie(pubkey)
        def publish(request, root):
            view = uvclight.query_view(request, site, name=u'index')
            if view is not None:
                return view
            return uvclight.query_view(request, site, name=u'notfound'), None

        session = environ[session_key].session
        setSession(session)
        request = Request(environ)
        view, error = publish(request, site)
        if error is not None:
            view = uvclight.query_view(request, site, name=u'unauthorized')
            view.set_message(error.title)
        response = view()

        return response(environ, start_response)
    return publisher
Example #6
0
def app_factory(global_conf, name, zcml_file, langs='en'):
    load_zcml(zcml_file)
    allowed = langs.strip().replace(',', ' ').split()
    register_allowed_languages(allowed)
    return WSGIApplication(name)
Example #7
0
 def i18n_loader(*args, **kwargs):
     languages = getattr(kwargs, method)(arg_name, fallback)
     assert languages and isinstance(languages, (str, unicode))
     allowed = languages.strip().replace(',', ' ').split()
     register_allowed_languages(allowed)
     return func(*args, **kwargs)