Python pyramid.view.view_config() Examples

The following are 3 code examples of pyramid.view.view_config(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyramid.view , or try the search function .
Example #1
Source File:    From janus-cloud with GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, **settings):
        method = self.__class__.__name__.split('_')[0].upper()
        super(_rest_view, self).__init__(request_method=method,
        # add CORS OPTIONS method support for registered REST view
        route_name = settings['route_name']
        if route_name in self.cors_route:
        handler = PrefligthHandlerFactory(route_name, method)
        self.cors_route[route_name] = handler
        view_config(request_method='OPTIONS', route_name=route_name, _depth=1)(handler)
        # dirty hack
        # to get caller's module, in order to inject preflight_handler to that module
        # so when scan configuration, pyramid will pick OPTIONS for that route
        module = inspect.getmodule(inspect.getouterframes(inspect.currentframe())[0][0].f_back)
        setattr(module, 'preflight_'+route_name, handler) 
Example #2
Source File:    From channelstream with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def shared_messages(request):
    server_state = get_state()
    schema = schemas.MessageBodySchema(context={"request": request}, many=True)
    data = schema.load(request.json_body)
    data = [m for m in data if m.get("channel") or m.get("pm_users")]
    for msg in data:
        gevent.spawn(operations.pass_message, msg, server_state.stats)
    return list(data)

# prepare v1 version
# @view_config(route_name="api_v1_messages", request_method="POST", renderer="json") 
Example #3
Source File:    From muesli with GNU General Public License v3.0 5 votes vote down vote up
def api_login(request):
    user = request.db.query(models.User).filter_by(
    exp = datetime.timedelta(days=muesli.config["api"]["KEY_EXPIRATION"])
    token = models.BearerToken(client="Personal Token",
                               description="Requested from API",
    jwt_token = request.create_jwt_token(, admin=(user.is_admin),, expiration=exp)
    if user:
        return {
            'result': 'ok',
            'token': jwt_token
    return {'result': 'error'}

# Only for testing purposes. If it is decided that this should be implemented
# the function needs to be changed to work similar to api_login
#@view_config(route_name='api_login', renderer='json', request_method='GET')
#def refresh(request):
#    user = request.db.query(models.User).get(request.authenticated_userid)
#    if user:
#        return {
#            'result': 'ok',
#            'token': request.create_jwt_token(, admin=(user.is_admin))
#        }
#    return {'result': 'error'}