當前位置: 首頁>>代碼示例>>Python>>正文


Python Constants.error_wrong_json_structure方法代碼示例

本文整理匯總了Python中constants.Constants.error_wrong_json_structure方法的典型用法代碼示例。如果您正苦於以下問題:Python Constants.error_wrong_json_structure方法的具體用法?Python Constants.error_wrong_json_structure怎麽用?Python Constants.error_wrong_json_structure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在constants.Constants的用法示例。


在下文中一共展示了Constants.error_wrong_json_structure方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from constants import Constants [as 別名]
# 或者: from constants.Constants import error_wrong_json_structure [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_structure [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_structure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。