for i in range(len(id)): try: doc = dict(db[id[i]]) list_info[doc['_id']] = doc['status'] except ResourceNotFound: print('There is no such a file!') return 200, list_info # Update status. elif operation.lower() == 'delete': resp = db_op.db_operate(db_server, 'online_info', 'delete', id = id) return resp # Flask for accounts. online_info_handler = Blueprint('online_info', __name__) db_server = db_op.get_server() @online_info_handler .route('', methods=['DELETE', 'PUT']) def resp_online_info(): response = {} data = eval(str(request.data, encoding="utf-8")) if request.method == 'DELETE': id = data['_id'] resp = db_online_info(db_server, 'delete', id = id,) response['resp'] = resp return response elif request.method == 'PUT': id = data['_id'] status = data['status'] resp = db_online_info(db_server, 'update', id = id, status = status) response['resp'] = resp return response
from flask import Flask, request, Blueprint from couchdb import ResourceConflict, ResourceNotFound from db_op import db_operate, get_server # Flask for personal_info. personal_info_handler = Blueprint('personal_info', __name__) db_server = get_server() def get_batch_info(db_server, data): id_list = data['_id'] if type(id_list) != list: id_list = [id_list] db1 = db_server['personal_info'] db2 = db_server['online_info'] db3 = db_server['distance'] info_list = [] for id in id_list: user_info = {'_id': id} try: doc1 = dict(db1[id]) user_info['first_name'] = doc1['first_name'] user_info['last_name'] = doc1['last_name'] except ResourceNotFound: user_info['first_name'] = '' user_info['last_name'] = '' try: doc2 = dict(db2[id]) user_info['status'] = doc2['status'] except ResourceNotFound: user_info['status'] = ''