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


Python Constants.error_wrong_json_format方法代码示例

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


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

示例1: post

# 需要导入模块: from constants import Constants [as 别名]
# 或者: from constants.Constants import error_wrong_json_format [as 别名]
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('userID', type=str, help='User ID', location='form', required=True)
        parser.add_argument('userData', type=str, help='User Data', location='form', required=True)
        parser.add_argument('userToken', type=str, help='User Token', location='form', required=True)
        args = parser.parse_args()

        user_id = args['userID']
        token = args['userToken']

        model = BaseResource.check_user_credentials_with_credentials(user_id, token)

        if not isinstance(model, PersonModel):
            # Some error happens here
            return model

        json_data = args['userData']

        try:
            json_data = json.loads(json_data)
        except ValueError:
            return Constants.error_wrong_json_format()

        if not isinstance(json_data, list):
            return Constants.error_wrong_json_structure()

        print json_data

        result = []
        for event_dict in json_data:
            if isinstance(event_dict, dict):
                event_model = EventModel.find_event(event_dict.get(EventModel.k_event_id))

                event_model.creator_id = user_id
                event_model.configure_with_dict(event_dict)

                db.session.add(event_model)
                db.session.commit()

                event_json = event_model.to_dict()

                result.append(event_json)

        time_stamp = datetime.utcnow()
        response = dict()
        response[Constants.k_time_stamp] = time_stamp.isoformat()
        response['result'] = result

        # print response

        return response
开发者ID:ned1988,项目名称:TeamExpensesBackend,代码行数:53,代码来源:synchronise_resource.py

示例2: post

# 需要导入模块: from constants import Constants [as 别名]
# 或者: from constants.Constants import error_wrong_json_format [as 别名]
    def post(self):
        # user_id = request.form['userID']
        # token = request.form['userToken']
        # event_id = request.form['eventID']

        # model = BaseResource.check_user_credentials_with_credentials(user_id, token)
        #
        # if not isinstance(model, PersonModel):
        #     # Some error happens here
        #     return model

        # items = EventModel.query.filter_by(event_id=event_id).all()
        # if len(items) > 0:
        #     return {'status': 'event_not_exist'}, 401

        team_members_json = request.form["teamMembersID"]

        try:
            team_members = json.loads(team_members_json)
        except ValueError:
            return Constants.error_wrong_json_format()

        if not isinstance(team_members, list):
            return Constants.error_wrong_json_structure()

        result = {}
        for team_member in team_members:
            local_user_id = team_member["user_id"]

            if local_user_id is None:
                continue

            person_model = PersonModel()

            person_model.first_name = team_member["first_name"]
            person_model.last_name = team_member["last_name"]

            # Add person to the model
            db.session.add(person_model)
            db.session.commit()

            result[local_user_id] = person_model.to_dict()

        return result
开发者ID:ned1988,项目名称:TeamExpensesBackend,代码行数:46,代码来源:event_add_team_members_resource.py


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