示例#1
0
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))
示例#2
0
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))
示例#3
0
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))
示例#4
0
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'}))
示例#5
0
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))
示例#6
0
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'}))
示例#7
0
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))
示例#8
0
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))
示例#9
0
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接口获取"}))
示例#10
0
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'}))
示例#11
0
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))
示例#12
0
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接口获取"}))
示例#13
0
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接口获取"}))
示例#14
0
            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,