def setup_modul(config, modul): """Setup routes and views for the activated actions of the given model of the modul. :config: Pylons config instance :modul: The module for which the new routes will be set up. """ clazz = helpers.dynamic_import(modul.clazzpath) log.info("Setup modul '%s'" % modul.name) # Reload modul old_actions = list(a.url for a in modul.actions) for bclazz in clazz.__bases__: if issubclass(bclazz, Mixin): for action in bclazz.get_mixin_actions(): if not action.url in old_actions: action.mid = clazz._modul_id modul.actions.append(action) NTDBSession.add(action) NTDBSession.commit() for action in modul.actions: _setup_web_action(config, action, clazz, web_action_view_mapping) _setup_rest_action(config, action, clazz, rest_action_view_mapping)
def setup_modul(config, modul): """Setup routes and views for the activated actions of the given model of the modul. :config: Pylons config instance :modul: The module for which the new routes will be set up. """ clazz = helpers.dynamic_import(modul.clazzpath) log.info("Setup modul '%s'" % modul.name) # Reload modul old_actions = list(a.url for a in modul.actions) for bclazz in clazz.__bases__: if hasattr(bclazz, "get_mixin_actions"): for action in bclazz.get_mixin_actions(): if not action.url in old_actions: action.mid = clazz._modul_id modul.actions.append(action) NTDBSession.add(action) NTDBSession.commit() for action in modul.actions: # Link is a special actions which does not need a view. So # ignore it (e.g Link action). if not action.url: continue _setup_web_action(config, action, clazz, web_action_view_mapping) _setup_rest_action(config, action, clazz, rest_action_view_mapping)
def user_factory(handler, registry): global ANONYMOUS_USER if ANONYMOUS_USER is None: login = registry.settings.get("auth.anonymous_user") try: ANONYMOUS_USER = db.query(User).filter(User.login == login).one() except NoResultFound: log.error( "Misconfigured anonymous user '{}'. User not found.".format( login)) sys.exit(1) def user_tween(request): if static_urls.match(request.path): return handler(request) # Cache must be existing. Because we are in a tween this code # is executed _before_ the "NewRequest" event is handled in the # application which usually ensures that the cache is # initialised. So we will "pre"-init the cache here. init_cache(request) if not request.user: # Do not (re)-authorize the user on logout and autologout # pages. if request.path not in [ request.route_path("autologout"), request.route_path("logout") ]: request.user = ANONYMOUS_USER request.session["auth.anonymous_user"] = ANONYMOUS_USER.login request.session.save() headers = remember(request, ANONYMOUS_USER.id) return HTTPFound(location=request.path, headers=headers) return handler(request) return user_tween
def user_factory(handler, registry): global ANONYMOUS_USER if ANONYMOUS_USER is None: login = registry.settings.get("auth.anonymous_user") ANONYMOUS_USER = db.query(User).filter(User.login == login).one() def user_tween(request): if not request.user: log.info("Anonymous login") request.user = ANONYMOUS_USER request.session["auth.anonymous_user"] = ANONYMOUS_USER.login request.session.save() target_url = request.route_path("home") headers = remember(request, ANONYMOUS_USER.id) return HTTPFound(location=target_url, headers=headers) return handler(request) return user_tween
def setup_modules(config): """Will iterate over all configured modules in the application. Configured modules are loaded from database. For each module it will call the setup_modul method.""" for modul in NTDBSession.query(ModulItem).all(): setup_modul(config, modul)