예제 #1
0
def check_content(appname, projectname, applabel, module, id, data):
    '''
    this api is used to check content
    Request URL: /<projectname>/auth/<applabel>/<modulename>/check/<id>
    HTTP Method: POST
    Parameters:
        {
            "checked": 3,
            "mark": ""
        }
    Return:
     {
        "status":0
        "data":{
            "id": 1,
            "checked": 3,
            "release": 1,
            "last_modified": "2015-04-16 14:10:37"
            }
        "msg":""
     }
    '''
    id = int(id)
    cond = {
        "check_id": id, 'projectname': projectname, "check_uid": data["uid"],
        "app_name": applabel, "module_name": module}
    check_info = CheckList.find_one(appname, cond, None)
    if not check_info:
        _LOGGER.info("check info id %s is not submit" % id)
        return json_response_error(
            PARAM_ERROR, data, msg="invalid id, %s is not submit" % id)

    #update response info in coll
    info = update_status_by_id(
        appname, projectname, module, id, data["checked"])
    if not info:
        return json_response_error(
            PARAM_ERROR, data, msg="invalid id,check parameters")

    #update check list
    data["last_modified"] = now_timestamp()
    CheckList.update(appname, cond, data)
    _send_email_to_user(
        appname, projectname, module, data["uid"], check_info["submit_uid"],
        id, data["mark"])
    return json_response_ok(info)
예제 #2
0
def checklist_create(appname, projectname, applabel, module, uid, ids):
    '''
    this api to add checklist.
    Request URL: /<projectname>/auth/<applabel>/<modulename>/submit
    Parameters:
    {
        'app_name': 'homeadmin',
        'module_name': 'banner',
        'items': [1, 2, 3]
    }
    '''
    data = {"success": [], "failed": []}
    check_uids = []
    check_uids = get_check_uids(appname, projectname, applabel, module)
    ids = [int(id) for id in ids]
    for id in ids:
        info = update_status_by_id(appname, projectname, module, id, 1)
        if not info:
            data["failed"].append(id)
            continue
        cond = {
            "check_id": id, 'projectname': projectname, "submit_uid": uid,
            "app_name": applabel, "module_name": module}
        old_check_info = CheckList.find_one(appname, cond, {"_id": 0})
        if old_check_info:
            old_check_info["status"] = 1
            old_check_info["mark"] = ""
            old_check_info["check_uid"] = check_uids
            old_check_info["last_modified"] = now_timestamp()
            CheckList.update(appname, cond, old_check_info)
        else:
            checklist_instance = CheckList.new(
                projectname, applabel, module, id, uid, check_uids)
            CheckList.save(appname, checklist_instance)
        data["success"].append(info)
    _send_email_to_assessor(appname, projectname, module, uid, check_uids, ids)
    if data["failed"]:
        return json_response_error(PARAM_ERROR, data, msg="invalid id")
    return json_response_ok(data)