def new_form(): from run import mongo form = request_to_class(request.json) try: insert_form(mongo, form) except ServerSelectionTimeoutError as e: return jsonify({'code': '500', 'message': e}) dict_json = dict_serializable(form.model) return jsonify({'code': '200', 'message': '', 'data': [dict_json]})
def new_user(): from run import mongo user = request_to_class(request.json) try: insert_user(mongo, user) except ServerSelectionTimeoutError as e: return jsonify({'code': 500, 'message': e}) dict_json = dict_serializable(user.model) return jsonify({'code': 200, 'message': '', 'data': [dict_json]})
def get_form(_id): from run import mongo try: forms = find_form(mongo, {'_id': ObjectId(_id)}) except PyMongoError as e: return jsonify({'code': '500', 'message': ''}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(form) for form in forms] })
def new_item_type(): from run import mongo item_type = request_to_class(request.json) try: insert_item_type(mongo, item_type) except: return jsonify({'code': '500', 'message': ''}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(item_type.model)] })
def change_form(_id): from run import mongo try: update_form(mongo, {'_id': ObjectId(_id)}, request.json) except: return jsonify({'code': '500', 'message': ''}) forms = find_form(mongo, {'_id': ObjectId(_id)}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(form) for form in forms] })
def get_item_type(_id): from run import mongo try: item_types = find_item_type(mongo, {'_id': ObjectId(_id)}) except: return jsonify({'code': '500', 'message': ''}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(item_type) for item_type in item_types] })
def change_form_meta(_id): from run import mongo try: delete_form_meta(mongo, {'_id': ObjectId(_id)}) except PyMongoError as e: return jsonify({'code': '500', 'message': e}) form_meta = request_to_class(request.json) try: insert_form_meta(mongo, form_meta) except ServerSelectionTimeoutError as e: return jsonify({'code': '500', 'message': e}) dict_json = dict_serializable(form_meta.model) return jsonify({'code': '200', 'message': '', 'data': [dict_json]})
def get_user(_id): from run import mongo try: user_datas = find_user(mongo, {'_id': {"$in": {ObjectId(_id)}}}) except PyMongoError as e: return jsonify({'code': '500', 'message': e}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(user_data) for user_data in user_datas] })
def new_event(_id): from run import mongo try: user_datas = User() user_datas_cursor = find_user(mongo, {'_id': {"$in": {ObjectId(_id)}}}) # user_datas=update_event(request.json,mongo,{'_id':ObjectId(_id)}) except PyMongoError as e: return jsonify({'code': '500', 'message': e}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(user_data) for user_data in user_datas] })
def get_form_metas(): url_condition = UrlCondition(request.args) from run import mongo try: form_metas = find_form_meta(mongo, url_condition.filter_dict) except PyMongoError as e: return jsonify({'code': '500', 'message': e}) form_metas = sort_limit(form_metas, url_condition.sort_limit_dict) paginate = Paginate(form_metas, url_condition.page_dict) form_metas_list = [ to_json_list(form_meta) for form_meta in paginate.data_page ] prev = None if paginate.has_prev: prev = url_for('form_meta_blueprint.get_form_metas', _page=paginate.page - 1) next = None if paginate.has_next: next = url_for('form_meta_blueprint.get_form_metas', _page=paginate.page + 1) return jsonify({ 'code': '200', 'message': '', 'data': [ dict_serializable(form_metas_list_node) for form_metas_list_node in form_metas_list ], 'prev': prev, 'next': next, 'has_prev': paginate.has_prev, 'has_next': paginate.has_next, 'total': paginate.total, 'page_num': paginate.page_num, 'page_now': paginate.page, 'per_page': paginate.per_page })
def change_event(_id, event_id): from run import mongo events = request_to_class_event(request.json) try: delete_event(mongo, {'event_id': ObjectId(event_id)}) except PyMongoError as e: return jsonify({'code': '500', 'message': e}) try: user_datas = update_event(mongo, events, {'_id': ObjectId(_id)}) except ServerSelectionTimeoutError as e: return jsonify({'code': '500', 'message': e}) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(user_data) for user_data in user_datas] })
def get_lessons(): url_condition = UrlCondition(request.args) from run import mongo try: lessons = find_lessons(mongo, url_condition.filter_dict) except Exception as e: return jsonify({ 'code':500, 'message':str(e), 'lessons':None }),500 lessons = sort_limit(lessons, url_condition.sort_limit_dict) paginate = Paginate(lessons, url_condition.page_dict) return jsonify({ 'code': 200, 'message': '', 'lessons': [dict_serializable(lesson) for lesson in lessons], 'total': paginate.total, }),200
def get_lesson(_id): from run import mongo try: lesson = find_lesson(mongo, _id) except Exception as e: return jsonify({ 'code':500, 'message':str(e), 'lesson':None }),500 if lesson is None: return jsonify({ 'code':404, "message":'Not found', 'lesson':None }),404 return jsonify({ 'code':200, 'message':'', 'lesson':dict_serializable(lesson) if lesson is not None else None }),200
def get_item_types(): url_condition = UrlCondition(request.args) from run import mongo try: item_types = find_item_type(mongo, url_condition.filter_dict) except: return jsonify({'code': '500', 'message': ''}) item_types = sort_limit(item_types, url_condition.sort_limit_dict) paginate = Paginate(item_types, url_condition.page_dict) prev = None if paginate.has_prev: prev = url_for('item_type_blueprint.get_item_types', _page=paginate.page - 1) next = None if paginate.has_next: next = url_for('item_type_blueprint.get_item_types', _page=paginate.page + 1) return jsonify({ 'code': '200', 'message': '', 'data': [dict_serializable(item_type) for item_type in item_types], 'prev': prev, 'next': next, 'has_prev': paginate.has_prev, 'has_next': paginate.has_next, 'total': paginate.total, 'page_num': paginate.page_num, 'page_now': paginate.page, 'per_page': paginate.per_page })