当前位置: 首页>>代码示例>>Python>>正文


Python view.view_config方法代码示例

本文整理汇总了Python中pyramid.view.view_config方法的典型用法代码示例。如果您正苦于以下问题:Python view.view_config方法的具体用法?Python view.view_config怎么用?Python view.view_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.view的用法示例。


在下文中一共展示了view.view_config方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pyramid import view [as 别名]
# 或者: from pyramid.view import view_config [as 别名]
def __init__(self, **settings):
        method = self.__class__.__name__.split('_')[0].upper()
        super(_rest_view, self).__init__(request_method=method,
                                         **settings)
        # add CORS OPTIONS method support for registered REST view
        route_name = settings['route_name']
        if route_name in self.cors_route:
            self.cors_route[route_name].add_method(method)
            return
        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) 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:19,代码来源:common.py

示例2: shared_messages

# 需要导入模块: from pyramid import view [as 别名]
# 或者: from pyramid.view import view_config [as 别名]
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") 
开发者ID:Channelstream,项目名称:channelstream,代码行数:14,代码来源:server.py

示例3: api_login

# 需要导入模块: from pyramid import view [as 别名]
# 或者: from pyramid.view import view_config [as 别名]
def api_login(request):
    user = request.db.query(models.User).filter_by(
        email=request.POST['email'].strip(),
        password=sha1(request.POST['password'].encode('utf-8')).hexdigest()
    ).first()
    exp = datetime.timedelta(days=muesli.config["api"]["KEY_EXPIRATION"])
    token = models.BearerToken(client="Personal Token",
                               user=user,
                               description="Requested from API",
                               expires=datetime.datetime.utcnow()+exp
                               )
    request.db.add(token)
    request.db.flush()
    jwt_token = request.create_jwt_token(user.id, admin=(user.is_admin), jti=token.id, expiration=exp)
    request.db.commit()
    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(user.id, admin=(user.is_admin))
#        }
#    return {'result': 'error'} 
开发者ID:muesli-hd,项目名称:muesli,代码行数:35,代码来源:viewsUser.py


注:本文中的pyramid.view.view_config方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。