def message_api(request): if request.method == 'GET': query = dict() for key, value in request.GET.iteritems(): query[key] = value message = Message.find_one(**query) if message is None: return JSONResponse(jsonfy({{"errmsg": "not found"}})) return JSONResponse(jsonfy(message)) elif request.method == 'POST': query = dict() for key, value in request.POST.iteritems(): query[key] = value if "_id" in query.keys(): message = Message.find_one(_id=ObjectId(query["_id"])) else: message = Message.find_one(name=query["name"]) if message is None: message = Message(**query) message.save() return JSONResponse(jsonfy(message)) else: message.update(**query) if "module" in query: norms = Norm.find_all(belong_message=str(message.id)) for norm in norms: norm.update(module=query["module"]) return JSONResponse(jsonfy(message))
def norm_api(request): if request.method == 'GET': query = dict() for key, value in request.GET.iteritems(): query[key] = value norm = Norm.find_one(**query) if norm is None: return JSONResponse(jsonfy({{"errmsg": "not found"}})) return JSONResponse(jsonfy(norm)) elif request.method == 'POST': query = dict() for key, value in request.POST.iteritems(): query[key] = value if "_id" in query.keys(): norm = Norm.find_one(_id=ObjectId(query["_id"])) else: norm = Norm.find_one(name=query["name"], belong_message=query["belong_message"]) if norm is None: norm = Norm(**query) norm.save() return JSONResponse(jsonfy(norm)) else: norm.update(**query) return JSONResponse(jsonfy(norm))
def norm_list_api(request): if request.method == 'GET': query = dict() for key, value in request.GET.iteritems(): if key != "order": query[key] = value norms = Norm.find_all(**query) if len(norms) == 0: return JSONResponse(jsonfy({"errmsg": "not found"})) return JSONResponse(jsonfy(norms))
def job_del_api(request): if request.method == 'POST': message_id = request.POST.get("message_id") job = JobTimmer.find_one(message_id=ObjectId(message_id)) if job is not None: job.remove() return JSONResponse(status=status.HTTP_200_OK, data=jsonfy({'result': 'ok'})) return JSONResponse(status=status.HTTP_200_OK, data=jsonfy({'errmsg': 'not found'}))
def job_list_api(request): if request.method == 'GET': query = dict() for key, value in request.GET.iteritems(): if key != "order": query[key] = value jobs = JobTimmer.find_all(**query) if len(jobs) == 0: return JSONResponse(jsonfy([])) return JSONResponse(jsonfy(jobs))
def norm_delete_api(request): if request.method == "POST": query = dict() for key, value in request.POST.iteritems(): query[key] = value norm = Norm.find_one(**query) if norm is None: return JSONResponse(jsonfy({{"errmsg": "not found"}})) norm.remove() return JSONResponse(status=status.HTTP_200_OK, data=jsonfy({'result': 'ok'}))
def people_group_api(request): if request.method == "GET": groups = PeopleGroup.find_all() return JSONResponse(jsonfy(groups)) elif request.method == "POST": group_name = request.POST.get('group_name') people_list = load(request.POST.get("people_list")) print people_list group = PeopleGroup.find_one(group_name=group_name) if group is None: group = PeopleGroup(group_name=group_name, people_list=people_list) group.save() else: group.update(people_list=people_list) return JSONResponse(jsonfy(group))
def message_list_api(request): if request.method == 'GET': query = dict() for key, value in request.GET.iteritems(): if key != "order": query[key] = value messages = Message.find_all(**query) if len(messages) == 0: return JSONResponse(jsonfy({"errmsg": "not found"})) for message in messages: job = JobTimmer.find_one(message_id=ObjectId(message.id)) if job is not None: message.__dict__["timer"] = job.run_time else: message.__dict__["timer"] = "" return JSONResponse(jsonfy(messages))
def send_others_api(request): if request.method == "GET": message_id = request.GET.get("id") date = (request.GET.get("date")) current_user = get_current_user() try: message_str = format_message(message_id=message_id, date=datetime.datetime.strptime( date, "%Y-%m-%d").date(), check=True) except ValueError, e: return JSONResponse(jsonfy({"errmsg": e.message})) except KeyError, e: errmsg = "" for norm in e.message: errmsg += norm.name + ", " return JSONResponse(jsonfy({"errmsg": errmsg + u"\n指标无法从APP接口获取"}))
def message_delete_api(request): if request.method == "POST": query = dict() for key, value in request.POST.iteritems(): query[key] = value message = Message.find_one(**query) if message is None: return JSONResponse(jsonfy({"errmsg": "not found"})) message.remove() norms = Norm.find_all(belong_message=(query["_id"])) for norm in norms: norm.remove() jobs = JobTimmer.find_all(message_id=ObjectId(query["_id"])) for job in jobs: job.remove() return JSONResponse(status=status.HTTP_200_OK, data=jsonfy({'result': 'ok'}))
def job_add_api(request): if request.method == 'POST': message_id = request.POST.get("message_id") run_time = request.POST.get("run_time") job = JobTimmer.find_one(message_id=ObjectId(message_id)) if job is not None: job.remove() job = JobTimmer(message_id=ObjectId(message_id), run_time=run_time) job.save() return JSONResponse(jsonfy(job))
def send_me_api(request): if request.method == "GET": try: message_id = request.GET.get("id") date = (request.GET.get("date")) current_user = get_current_user() message_str = format_message(message_id=message_id, date=datetime.datetime.strptime( date, "%Y-%m-%d").date()) return JSONResponse( (send_message(phone=current_user.get("phone"), msg=message_str, user_num=global_config.get("staffId")))) except ValueError, e: return JSONResponse(jsonfy({"errmsg": e.message})) except KeyError, e: errmsg = "" for norm in e.message: errmsg += norm.name + ", " return JSONResponse(jsonfy({"errmsg": errmsg + u"\n指标无法从APP接口获取"}))
def message_str_api(request): if request.method == "GET": message_id = request.GET.get("id") date = (request.GET.get("date")) print datetime.datetime.strptime(date, "%Y-%m-%d").date() try: return JSONResponse( jsonfy({ 'message': format_message(message_id=message_id, date=datetime.datetime.strptime( date, "%Y-%m-%d").date()) })) except ValueError, e: return JSONResponse(jsonfy({"errmsg": e.message})) except KeyError, e: errmsg = "" for norm in e.message: errmsg += norm.name + ", " return JSONResponse(jsonfy({"errmsg": errmsg + u"\n指标无法从APP接口获取"}))
return JSONResponse( jsonfy({ 'message': format_message(message_id=message_id, date=datetime.datetime.strptime( date, "%Y-%m-%d").date()) })) except ValueError, e: return JSONResponse(jsonfy({"errmsg": e.message})) except KeyError, e: errmsg = "" for norm in e.message: errmsg += norm.name + ", " return JSONResponse(jsonfy({"errmsg": errmsg + u"\n指标无法从APP接口获取"})) except Exception, e: return JSONResponse(jsonfy({"errmsg": "数据出错"})) @api_view(["GET"]) def send_me_api(request): if request.method == "GET": try: message_id = request.GET.get("id") date = (request.GET.get("date")) current_user = get_current_user() message_str = format_message(message_id=message_id, date=datetime.datetime.strptime( date, "%Y-%m-%d").date()) return JSONResponse( (send_message(phone=current_user.get("phone"), msg=message_str,