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


Python Validator.validated方法代码示例

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


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

示例1: post

# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import validated [as 别名]
    def post(self):
        u"""
        Creates new card and adds it to group.
        :return: Card
        """

        v = Validator(card_schema)
        args = v.validated(request.get_json())

        if args is None:
            return ApiResponse(status=4001, errors=v.errors)

        foreign = args.get(u'foreign')
        native = args.get(u'native')
        group_id = args.get(u'group_id')

        transcription = args.get(u'transcription', u'')
        context = args.get(u'context', u'')

        user = self.ss.get_user()
        group = self.gs.single(group_id, user)

        exists_card = self.cs.exists(user, foreign, user.foreign_lng)
        if exists_card:
            return ApiResponse(status=409, errors=CardsErrors.card_already_exists(foreign, [u'foreign']))

        card = self.cs.create(user, group, foreign, native, transcription, context)
        if card is None:
            return ApiResponse(status=500, errors=ServerErrors.internal_server_error([]))

        return card
开发者ID:h-qub,项目名称:wordeater-web,代码行数:33,代码来源:cards.py

示例2: post

# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import validated [as 别名]
    def post(self):
        us = ServiceLocator.resolve(ServiceLocator.USERS)
        ss = ServiceLocator.resolve(ServiceLocator.SESSIONS)

        v = Validator(user_signin_schema)

        args = v.validated(request.get_json())
        if args is None:
            return ApiResponse(status=4001, errors=v.errors)

        login = args.get(u'login')
        password = args.get(u'password')

        user = us.sign_in(login, password)
        if user is None:
            return ApiResponse(status=4001, errors=errors.SignErrors.login_or_password_wrong(['login', 'password']))

        token = us.make_auth_token(user)

        # Save the user to session
        ss.create(user, token)

        user[u'auth_token'] = token

        return user
开发者ID:h-qub,项目名称:wordeater-web,代码行数:27,代码来源:users.py

示例3: validated_method_example

# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import validated [as 别名]
def validated_method_example():
    """validated能返回验证后的document, 下面的代码给出了一种对输入的数据流进行处理的例子。
    """
    schema = {"value": {"type": "number"}}
    v = Validator(schema)
    
    documents = [
        {"value": 1},
        {"value": [1, 2, 3]},
        {"value": 2},
        ]
    valid_documents = [x for x in [v.validated(y) for y in documents] if x is not None]
    print(valid_documents)
    
# validated_method_example()
开发者ID:MacHu-GWU,项目名称:Learn-Cerberus,代码行数:17,代码来源:lsn01_quickstart.py

示例4: post

# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import validated [as 别名]
    def post(self):
        """

        :return:
        """

        v = Validator(translation_schema)
        args = v.validated(request.get_json())

        if args is None:
            return ApiResponse(status=4001, errors=v.errors)

        text = args.get(u'text')
        lang = self.ts.detect(text)

        return {
            u'lang': lang
        }
开发者ID:h-qub,项目名称:wordeater-web,代码行数:20,代码来源:translations.py

示例5: patch

# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import validated [as 别名]
    def patch(self, card_id):
        u"""
        Update card entity
        :param card_id: card's id
        :return: updated card
        """

        v = Validator(card_schema)
        args = v.validated(request.get_json())

        if args is None:
            return ApiResponse(status=4001, errors=v.errors)

        user = self.ss.get_user()

        card = self.cs.get(user, ObjectId(card_id))
        if card is None:
            return ApiResponse(status=404, errors=CardsErrors.card_dont_exists([]))

        foreign = args.get(u'foreign')
        native = args.get(u'native')
        transcription = args.get(u'transcription', card.transcription)
        context = args.get(u'context', card.foreign_context)

        duplicate_card = self.cs.single(user, foreign, user.foreign_lng)
        if duplicate_card.id != card.id:
            return ApiResponse(status=409, errors=CardsErrors.card_already_exists(foreign, [u'foreign']))

        try:
            card.foreign = foreign
            card.native = native
            card.transcription = transcription
            card.context = context

            card.save()
        except Exception as ex:
            error(u'CardApi.patch(card_id={0})'.format(card_id), ex)

            return ApiResponse(status=500, errors=ServerErrors.internal_server_error([]))
开发者ID:h-qub,项目名称:wordeater-web,代码行数:41,代码来源:cards.py

示例6: post

# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import validated [as 别名]
    def post(self):
        """
        Translate text
        :return:
        """

        v = Validator(picture_schema)
        args = v.validated(request.get_json())

        if args is None:
            return ApiResponse(status=4001, errors=v.errors)

        text = args.get(u'text')

        try:
            picture = self.ps.get(text)
            if picture:
                return picture

            return self.ps.add(text, self.gs.random(text))
        except Exception as ex:
            error(u'PicturesRandomAPI.post(text={0})'.format(text), ex)

            return ApiResponse(status=500, errors=ServerErrors.internal_server_error([]))
开发者ID:h-qub,项目名称:wordeater-web,代码行数:26,代码来源:pictures.py


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