當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。