Example #1
0
def del_info(appname, modelName):
    '''
        this api is used to delete card from server,
        Request URL:  /appname/rule/rule/delete
        HTTP Method: POST
        Parameters:
            {
                "items":[3, 2]
            }
        Return:
            {
                "status": 0,
                "msg": "delete locale success",
                "data": {
                    "failed": [],
                    "success": [{"id": 3}, {"id":2}]
                }
    '''
    # check post data
    required_list = {
        'items&need&list',
    }
    data = get_valid_params(request, required_list)
    if isinstance(data, Response):
        return data

    # delete logic
    return info_del(appname, modelName, data["items"])
Example #2
0
def rule_delete(appname):
    '''
        this api is used to delete rule,
        when one rule refered, the rule cannot removed
        Request URL:  /appname/rule/rule/delete
        HTTP Method: POST
        Parameters:
            {
                "items":[3, 2]
            }
        Return:
            {
                "status": 0,
                "msg": "delete rule success",
                "data": {
                    "failed": [],
                    "success": [{"id": 3}, {"id": 2}]
                }
    '''
    # check post data
    required_list = {
        'items&need&list',
    }
    data = get_valid_params(request, required_list)
    if isinstance(data, Response):
        return data

    # delete logic
    return delete_rule_info(appname, data["items"])
Example #3
0
def mod_info(appname, modelName):
    '''
        this api is used to modify one rule
        Request URL:  /appname/rule/rule/update
        HTTP Method:POST
        Parameters:
        {
           "id": 1,
           "title": "xxxx"
        }
        Return :
        {
            "status":0
            "data":{
                "id": 1,
                "title":"海豚英文版"
            }
        }
    '''
    # check post data
    MODELNAME = get_model_cls(modelName)
    required_list = list(MODELNAME.params) + ["id&need&int", ]
    data = get_valid_params(request, required_list)
    if isinstance(data, Response):
        return data
    return info_mod(appname, MODELNAME, data)
Example #4
0
def rule_add(appname):
    '''
        create api to add rule.
        Request URL:  /appname/rule/rule/add
        Http Method: POST
        Parameters :
            {
                "title": "xxxx"
                "min_version": 0,
                "max_version": 0,
                "source":[1],
                "locale":[1],
                "operator":[1],
                "package":[1],
                "min_value": 0,
                "max_value": 0,
                "gray_scale": 100,
                "gray_start": 1
            }
        Return :
        {
            "status":0
            "data":{
                "items":[
                    {
                        "id": 1,
                        "title":"海豚英文版",
                        "min_version": 0,
                        "max_version": 0,
                        "first_created": "2015-02-05 21:37:38",
                        "last_modified": "2015-02-05 21:37:38"
                    },
                    {
                        "id": 2,
                        "title":"联通",
                        "min_version": 0,
                        "max_version": 0,
                        "first_created": "2015-02-05 21:37:38",
                        "last_modified": "2015-02-05 21:37:38"
                    }
                ]
            }
        }

    '''
    # check post data
    data = get_valid_params(request, Rule.params)
    if isinstance(data, Response):
        return data

    # check the id of  pn/op/src/lc
    rule_params = ["package", "operator", "source", "locale"]
    data = check_rule_params(appname, data, rule_params)
    if isinstance(data, Response):
        return data

    # add logic
    return create(appname, Rule, data)
Example #5
0
def rule_update(appname):
    '''
        this api is used to modify one rule
        Request URL:  /appname/rule/rule/update
        HTTP Method:POST
        Parameters:
            {
                "title": "xxxx"
                "min_version": 0,
                "max_version": 0,
                "source":[1],
                "locale":[1],
                "operator":[1],
                "package":[1],
                "min_value": 0,
                "max_value": 0,
                "gray_scale": 100,
                "gray_start": 1
            }
        Return :
        {
            "status":0
            "data":{
                "id": 1,
                "title":"海豚英文版",
                "min_version": 0,
                "max_version": 0,
                "first_created": "2015-02-05 21:37:38",
                "last_modified": "2015-02-05 21:37:38"
            }
        }
        '''
    # check post data
    required_list = list(Rule.params) + ["id&need&int", ]
    data = get_valid_params(request, required_list)
    if isinstance(data, Response):
        return data

    # check the id of  pn/op/src/lc
    rule_params = ["package", "operator", "source", "locale"]
    data = check_rule_params(appname, data, rule_params)
    if isinstance(data, Response):
        return data
    return info_mod(appname, Rule, data)
Example #6
0
def add_info(appname, modelName):
    '''
        create api to add rule.
        Request URL:  /appname/rule/rule/add
        Http Method: POST
        Parameters :
            {
                "title": "xxxx",
                "code::"xxxx", #operator need
                "package_name:"xxxx" #package need
            }
        Return :
        {
            "status":0
            "data":{
                "items":[
                    {
                        "id": 1,
                        "title":"海豚英文版",
                        "first_created": "2015-02-05 21:37:38",
                        "last_modified": "2015-02-05 21:37:38"
                    },
                    {
                        "id": 2,
                        "title":"联通",
                        "first_created": "2015-02-05 21:37:38",
                        "last_modified": "2015-02-05 21:37:38"
                    }
                ]
            }
        }
    '''
    MODELNAME = get_model_cls(modelName)
    # check post data
    data = get_valid_params(request, MODELNAME.params)
    if isinstance(data, Response):
        return data
    # view logic
    return create(appname, MODELNAME, data)
Example #7
0
def refer_info_add(appname):
    '''
        create api to add refered info.
        Request URL:  /appname/rule/referInfo/add
        Http Method: POST
        Parameters :
        {
           "target_field": "rule",
           "target_id": 1,
           "refered_data":{
                "modelName" : "category",
                "id" : 1,
                "modelField" : "rule"
            }
        }
        Return :
        {
            "status":0
            "data":{}
        }

    '''
    # check post data
    data = get_valid_params(request, ReferInfo.params)
    if isinstance(data, Response):
        return data

    # get required args
    target_field = data.get("target_field")
    target_id = int(data.get("target_id"))
    refered_data = data.get("refered_data")
    old_id = data.get("old_target_id")

    # add logic
    add_refered_info(
        appname, target_field, target_id, refered_data, old_id)

    return json_response_ok({}, msg="add refered info  success")
Example #8
0
def get_info(appname, modelName):
    '''
        this api is used to view one rule
        Request URL:  /<appname>/rule/<modelName>/edit
        Http Method: GET
        Parameters : id
        Return :
        {
            "status":0
            "data":{
                "id": 1,
                "title":"海豚英文版"
            }
        }
     '''
    required_list = {
        'id&need&int',
    }
    data = get_valid_params(request, required_list)
    if isinstance(data, Response):
        return data
    # this method get info by id
    cond = {"_id": int(data["id"])}
    return info_get(appname, modelName, cond)
Example #9
0
def refer_info_delete(appname):
    '''
        this api is used to de refered info,
        Request URL:  /appname/rule/referInfo/delete
        HTTP Method: POST
        Parameters:
        {
           "target_field": "rule",
           "target_id": 1,
           "unrefered_data":{
                "modelName" : "category",
                "id" : 1,
                "modelField" : "rule"
            }
        }
        Return:
            {
                "status": 0,
                "msg": "de refered info success",
                "data": {}
    '''
    # check post data
    params = {
        'target_field&need&str',
        'target_id&need&int',
        "unrefered_data&need&dict",
    }
    data = get_valid_params(request, params)
    if isinstance(data, Response):
        return data
    target_field = data.get("target_field")
    target_id = int(data.get("target_id"))
    unrefered_data = data.get("unrefered_data")

    delete_refered_info(appname, target_field, target_id, unrefered_data)
    return json_response_ok({})