示例#1
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)
示例#2
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)