diff --git a/const.py b/const.py index 4f7e43a..324aa2b 100644 --- a/const.py +++ b/const.py @@ -32,7 +32,7 @@ ('医用面罩式雾化器', ), ('测体温设备', ), ('空气消毒设备', ), - ('医用紫外线消毒车', ), + ('医用紫外线消毒车', ) ] """ @@ -45,7 +45,7 @@ 'donate_account_info', 'donate_cur_status', 'donate_audit_status', - 'donate_audit_person', + 'donate_audit_person' ] FACTORY_HEADERS = [ 'factory_prov', @@ -57,7 +57,7 @@ 'factory_note', 'factory_link', 'factory_audit_status', - 'factory_reviewer', + 'factory_reviewer' ] CLINIC_HEADERS = [ 'clinic_unit', @@ -76,7 +76,7 @@ 'hotel_note', 'hotel_link', 'hotel_audit_status', - 'hotel_audit_person', + 'hotel_audit_person' ] LOGISTICS_HEADERS = [ 'logistics_name', @@ -100,5 +100,5 @@ 'hospital_contact', 'hospital_note', 'hospital_audit_status', - 'hospital_audit_person', + 'hospital_audit_person' ] diff --git a/utils.py b/utils.py index b3de8fd..d0dcc7a 100644 --- a/utils.py +++ b/utils.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from flask import Blueprint, current_app, request +from werkzeug.exceptions import * import os import json import datetime @@ -17,47 +18,54 @@ data = Blueprint('register', __name__) -@data.route('/json_test') +@data.route('/json_test', methods=['GET']) def json_test(): path = os.path.join("/root/api-server/", "test.json") return json_helper(path) -@data.route('/xml_test') +@data.route('/xml_test', methods=['GET']) def xml_test(): path = os.path.join("/root/api-server/", "test.xml") return xml_helper(path) -@data.route('/hospital_list') +@data.route('/hospital_list', methods=['GET']) def hospital_list(): resp = { 'success': False, 'data': [], 'msg': '', } + code = 200 try: - hosptials_data = csv_with_medical_supplier(current_app.config['HOSPITAL_PATH'], HOSPITAL_HEADERS) + hosptials_data = csv_with_medical_supplier( + current_app.config['HOSPITAL_PATH'], HOSPITAL_HEADERS) if 'limit' in request.args or 'skip' in request.args: skip = request.args.get('skip', type=int) limit = request.args.get('limit', type=int) hosptials_data_len = len(hosptials_data) if skip < 0 or limit < 0 or limit > 50: - raise Exception('Bad input parameter.') + raise BadRequest('Bad input parameter.') if skip > hosptials_data_len: - raise Exception("Index out of range.") + raise BadRequest("Index out of range.") if skip + limit > hosptials_data_len: limit = hosptials_data_len - skip resp['data'] = hosptials_data[skip:skip+limit] else: resp['data'] = hosptials_data resp['success'] = True - except Exception as e: + except HTTPException as e: + code = e.code resp['msg'] = str(e) - return json.dumps(resp, ensure_ascii=False),(400 if not resp['success'] else 200) + except Exception as ex: + code = 500 + resp['msg'] = str(ex) + + return json.dumps(resp, ensure_ascii=False), code -@data.route('/hotel_list') +@data.route('/hotel_list', methods=['GET']) @auth.login_required def hotel_list(): resp = { @@ -74,16 +82,17 @@ def hotel_list(): return json.dumps(resp, ensure_ascii=False) -@data.route('/logistical_list') +@data.route('/logistics_list', methods=['GET']) @auth.login_required -def logistical_list(): +def logistics_list(): resp = { 'success': False, 'data': [], 'msg': '', } try: - resp_data = csv_with_medical_supplier(current_app.config['LOGISITICAL_PATH'], LOGISTICS_HEADERS) + resp_data = csv_with_medical_supplier( + current_app.config['LOGISITICAL_PATH'], LOGISTICS_HEADERS) resp['success'] = True resp['data'] = resp_data except Exception as e: @@ -91,7 +100,7 @@ def logistical_list(): return json.dumps(resp, ensure_ascii=False) -@data.route('/news_list') +@data.route('/news_list', methods=['GET']) @auth.login_required def news_list(): resp = { @@ -108,7 +117,7 @@ def news_list(): return json.dumps(resp, ensure_ascii=False) -@data.route('/donation_list') +@data.route('/donation_list', methods=['GET']) @auth.login_required def donation_list(): resp = { @@ -117,7 +126,8 @@ def donation_list(): 'msg': '', } try: - resp_data = csv_helper(current_app.config['DONATION_PATH'], DONATION_HEADERS) + resp_data = csv_helper( + current_app.config['DONATION_PATH'], DONATION_HEADERS) resp['success'] = True resp['data'] = resp_data except Exception as e: @@ -125,7 +135,7 @@ def donation_list(): return json.dumps(resp, ensure_ascii=False) -@data.route('/factory_list') +@data.route('/factory_list', methods=['GET']) @auth.login_required def factory_list(): resp = { @@ -134,7 +144,8 @@ def factory_list(): 'msg': '', } try: - resp_data = csv_with_medical_supplier(current_app.config['FACTORY_PATH'], FACTORY_HEADERS) + resp_data = csv_with_medical_supplier( + current_app.config['FACTORY_PATH'], FACTORY_HEADERS) resp['success'] = True resp['data'] = resp_data except Exception as e: @@ -142,7 +153,7 @@ def factory_list(): return json.dumps(resp, ensure_ascii=False) -@data.route('/clinic_list') +@data.route('/clinic_list', methods=['GET']) @auth.login_required def clinic_list(): resp = { @@ -151,14 +162,16 @@ def clinic_list(): 'msg': '', } try: - resp_data = csv_helper(current_app.config['CLINIC_PATH'], CLINIC_HEADERS) + resp_data = csv_helper( + current_app.config['CLINIC_PATH'], CLINIC_HEADERS) resp['success'] = True resp['data'] = resp_data except Exception as e: resp['msg'] = str(e) return json.dumps(resp, ensure_ascii=False) -@data.route('/hospital_list_json') + +@data.route('/hospital_list_json', methods=['GET']) def hospital_list_json(): resp = { 'success': False, @@ -166,7 +179,7 @@ def hospital_list_json(): 'msg': '', } try: - resp_data= json_helper(current_app.config['JSON_HOSPITAL_PATH']) + resp_data = json_helper(current_app.config['JSON_HOSPITAL_PATH']) resp['success'] = True resp['data'] = resp_data except Exception as e: @@ -174,9 +187,7 @@ def hospital_list_json(): return json.dumps(resp, ensure_ascii=False) - - -@data.route('/hotel_list_json') +@data.route('/hotel_list_json', methods=['GET']) def hotel_list_json(): resp = { 'success': False, @@ -192,8 +203,8 @@ def hotel_list_json(): return json.dumps(resp, ensure_ascii=False) -@data.route('/logstics_list_json') -def logstics_list_json(): +@data.route('/logistics_list_json', methods=['GET']) +def logistics_list_json(): resp = { 'success': False, 'data': [], @@ -208,7 +219,7 @@ def logstics_list_json(): return json.dumps(resp, ensure_ascii=False) -@data.route('/news_list_json') +@data.route('/news_list_json', methods=['GET']) def news_list_json(): resp = { 'success': False, @@ -224,7 +235,7 @@ def news_list_json(): return json.dumps(resp, ensure_ascii=False) -@data.route('/donation_list_json') +@data.route('/donation_list_json', methods=['GET']) def donation_list_json(): resp = { 'success': False, @@ -240,7 +251,7 @@ def donation_list_json(): return json.dumps(resp, ensure_ascii=False) -@data.route('/factory_list_json') +@data.route('/factory_list_json', methods=['GET']) def factory_list_json(): resp = { 'success': False, @@ -256,7 +267,7 @@ def factory_list_json(): return json.dumps(resp, ensure_ascii=False) -@data.route('/clinic_list_json') +@data.route('/clinic_list_json', methods=['GET']) def clinic_list_json(): resp = { 'success': False,