示例#1
0
def rule_edit(request):
    """
    edit a rule
    修改应用
    """
    header_title, path1, path2 = u'修改规则', u'灰度管理', u'修改规则'

    rule_id = request.GET.get('id', '')
    rule = get_object(Rule, id=rule_id)
    af = RuleForm(instance=rule)
    if request.method == 'POST':
        af_post = RuleForm(request.POST, instance=rule)
        name = request.POST.get('name', '')
        shortname = request.POST.get('shortname', '')
        is_active = True if request.POST.get('is_active') == '1' else False
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            rule_name_test = get_object(Rule, name=name)
            if rule_name_test and rule_id != unicode(rule_name_test.id):
                emg = u'该规则名称 %s 已存在!' % name
                raise ServerError(emg)
            rule_shortname_test = get_object(Rule, shortname=shortname)
            if rule_shortname_test and rule_id != unicode(
                    rule_shortname_test.id):
                error = u'该规则简称 %s 已存在!' % shortname
                raise ServerError(error)
            if len(shortname) < 3 or len(shortname) > 6:
                error = u'该规则简称称 %s 不符合要求, 规则简称必须是3-6个字母!' % shortname
                raise ServerError(error)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                af_save = af_post.save(commit=False)
                af_save.is_active = True if is_active else False
                af_save.save()
                af_post.save_m2m()
                info = rule_diff(af_post.__dict__.get('initial'), request.POST)
                smg = u'规则 %s 修改成功' % name
            else:
                emg = u'规则 %s 修改失败' % name
                return my_render('upgray/error.html', locals(), request)
            return HttpResponseRedirect(
                reverse('rule_detail') + '?id=%s' % rule_id)

    return my_render('upgray/rule_edit.html', locals(), request)
示例#2
0
文件: views.py 项目: gyw040518/utopia
def rule_edit(request):
    """
    edit a rule
    修改应用
    """
    header_title, path1, path2 = u'修改规则', u'灰度管理', u'修改规则'

    rule_id = request.GET.get('id', '')
    rule = get_object(Rule, id=rule_id)
    af = RuleForm(instance=rule)
    if request.method == 'POST':
        af_post = RuleForm(request.POST, instance=rule)
        name = request.POST.get('name', '')
        shortname = request.POST.get('shortname','')
        is_active = True if request.POST.get('is_active') == '1' else False
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            rule_name_test = get_object(Rule, name=name)
            if rule_name_test and rule_id != unicode(rule_name_test.id):
                emg = u'该规则名称 %s 已存在!' % name
                raise ServerError(emg)
            rule_shortname_test = get_object(Rule,shortname=shortname)
            if rule_shortname_test and rule_id != unicode(rule_shortname_test.id):
                error = u'该规则简称 %s 已存在!' % shortname
                raise ServerError(error)
            if len(shortname) < 3 or len(shortname) > 6 :
                error = u'该规则简称称 %s 不符合要求, 规则简称必须是3-6个字母!' % shortname
                raise ServerError(error)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                af_save = af_post.save(commit=False)
                af_save.is_active = True if is_active else False
                af_save.save()
                af_post.save_m2m()
                info = rule_diff(af_post.__dict__.get('initial'), request.POST)
                smg = u'规则 %s 修改成功' % name
            else:
                emg = u'规则 %s 修改失败' % name
                return my_render('upgray/error.html', locals(), request)
            return HttpResponseRedirect(reverse('rule_detail')+'?id=%s' % rule_id)

    return my_render('upgray/rule_edit.html', locals(), request)
示例#3
0
def rule_add(request):
    """
    Rule add view
    添加应用
    """
    header_title, path1, path2 = u'添加规则', u'灰度管理', u'添加规则'
    af = RuleForm()
    default_setting = get_object(Setting, name='default')
    if request.method == 'POST':
        af_post = RuleForm(request.POST)
        name = request.POST.get('name', '')
        shortname = request.POST.get('shortname', '')
        is_active = True if request.POST.get('is_active') == '1' else False
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            if Rule.objects.filter(name=name):
                error = u'该规则名称 %s 已存在!' % name
                raise ServerError(error)
            if Rule.objects.filter(shortname=str(shortname)):
                error = u'该规则简称称 %s 已存在!' % shortname
                raise ServerError(error)
            if len(shortname) > 6 or len(shortname) < 3:
                error = u'该规则简称称 %s 不符合要求, 规则简称必须是3-6个字母!' % shortname
                raise ServerError(error)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                rule_save = af_post.save(commit=False)
                rule_save.is_active = True if is_active else False
                rule_save.save()
                af_post.save_m2m()

                msg = u'规则 %s 添加成功' % name
            else:
                esg = u'规则 %s 添加失败' % name

    return my_render('upgray/rule_add.html', locals(), request)
示例#4
0
文件: views.py 项目: gyw040518/utopia
def rule_add(request):
    """
    Rule add view
    添加应用
    """
    header_title, path1, path2 = u'添加规则', u'灰度管理', u'添加规则'
    af = RuleForm()
    default_setting = get_object(Setting, name='default')
    if request.method == 'POST':
        af_post = RuleForm(request.POST)
        name = request.POST.get('name', '')
        shortname = request.POST.get('shortname','')
        is_active = True if request.POST.get('is_active') == '1' else False
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            if Rule.objects.filter(name=name):
                error = u'该规则名称 %s 已存在!' % name
                raise ServerError(error)
            if Rule.objects.filter(shortname=str(shortname)):
                error = u'该规则简称称 %s 已存在!' % shortname
                raise ServerError(error)
            if len(shortname) > 6 or len(shortname) < 3:
                 error = u'该规则简称称 %s 不符合要求, 规则简称必须是3-6个字母!' % shortname
                 raise ServerError(error)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                rule_save = af_post.save(commit=False)
                rule_save.is_active = True if is_active else False
                rule_save.save()
                af_post.save_m2m()

                msg = u'规则 %s 添加成功' % name
            else:
                esg = u'规则 %s 添加失败' % name

    return my_render('upgray/rule_add.html', locals(), request)