コード例 #1
0
ファイル: views.py プロジェクト: gyw040518/utopia
def system_add(request):
    """
    System add view
    添加参数
    """
    header_title, path1, path2 = u'添加系统', u'灰度管理', u'添加系统'
    system_rule_all = Rule.objects.all()
    rule_name = ''
    system_rule = Rule.objects.filter(name=rule_name)

    content_list = []
    for content in system_rule:
        content_list.append(content)

    old_version = content_list
    new_version = [a for a in content_list if a not in old_version]


    af = SystemForm()
    default_setting = get_object(Setting, name='default')



    if request.method == 'POST':
        af_post = SystemForm(request.POST)
        name = request.POST.get('name', '')
        rule_name = request.POST.get('rule_name','')
        old_version = request.POST.get('old_version',[])
        new_version = request.POST.get('new_version',[])
        obj_rule = get_object(Rule,name=rule_name)
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            if System.objects.filter(name=name):
                error = u'该系统名称 %s 已存在!' % name
                raise ServerError(error)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                system_save = af_post.save(commit=False)
                system_save.save()
                af_post.save_m2m()

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

    return my_render('upgray/system_add.html', locals(), request)
コード例 #2
0
def system_add(request):
    """
    System add view
    添加参数
    """
    header_title, path1, path2 = u'添加系统', u'灰度管理', u'添加系统'
    system_rule_all = Rule.objects.all()
    rule_name = ''
    system_rule = Rule.objects.filter(name=rule_name)

    content_list = []
    for content in system_rule:
        content_list.append(content)

    old_version = content_list
    new_version = [a for a in content_list if a not in old_version]

    af = SystemForm()
    default_setting = get_object(Setting, name='default')

    if request.method == 'POST':
        af_post = SystemForm(request.POST)
        name = request.POST.get('name', '')
        rule_name = request.POST.get('rule_name', '')
        old_version = request.POST.get('old_version', [])
        new_version = request.POST.get('new_version', [])
        obj_rule = get_object(Rule, name=rule_name)
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            if System.objects.filter(name=name):
                error = u'该系统名称 %s 已存在!' % name
                raise ServerError(error)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                system_save = af_post.save(commit=False)
                system_save.save()
                af_post.save_m2m()

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

    return my_render('upgray/system_add.html', locals(), request)
コード例 #3
0
def system_edit(request):
    """
    edit a system
    修改系统
    """
    header_title, path1, path2 = u'修改系统', u'灰度管理', u'修改系统'

    system_id = request.GET.get('id', '')
    system = get_object(System, id=system_id)
    system_rule_all = Rule.objects.all()
    rule_name = request.GET.get("rule_name", '')

    if rule_name:
        system_find = System.objects.filter(rule_name=rule_name)

    af = SystemForm(instance=system)

    if request.method == 'POST':
        af_post = SystemForm(request.POST, instance=system)
        name = request.POST.get('name', '')
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            system_test = get_object(System, name=name)
            if system_test and system_id != unicode(system_test.id):
                emg = u'该系统名称 %s 已存在!' % name
                raise ServerError(emg)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                af_save = af_post.save(commit=False)
                af_save.save()
                af_post.save_m2m()
                info = system_diff(af_post.__dict__.get('initial'),
                                   request.POST)
                smg = u'系统 %s 修改成功' % system
            else:
                emg = u'系统 %s 修改失败' % system
                return my_render('upgray/error.html', locals(), request)
            return HttpResponseRedirect(
                reverse('system_detail') + '?id=%s' % system_id)

    return my_render('upgray/system_edit.html', locals(), request)
コード例 #4
0
ファイル: views.py プロジェクト: gyw040518/utopia
def system_edit(request):
    """
    edit a system
    修改系统
    """
    header_title, path1, path2 = u'修改系统', u'灰度管理', u'修改系统'

    system_id = request.GET.get('id', '')
    system = get_object(System, id=system_id)
    system_rule_all = Rule.objects.all()
    rule_name = request.GET.get("rule_name", '')

    if rule_name:
        system_find = System.objects.filter(rule_name=rule_name)

    af = SystemForm(instance=system)

    if request.method == 'POST':
        af_post = SystemForm(request.POST, instance=system)
        name = request.POST.get('name', '')
        use_default_auth = request.POST.get('use_default_auth', '')
        try:
            system_test = get_object(System, name=name)
            if system_test and system_id != unicode(system_test.id):
                emg = u'该系统名称 %s 已存在!' % name
                raise ServerError(emg)
        except ServerError:
            pass
        else:
            if af_post.is_valid():
                af_save = af_post.save(commit=False)
                af_save.save()
                af_post.save_m2m()
                info = system_diff(af_post.__dict__.get('initial'), request.POST)
                smg = u'系统 %s 修改成功' % system
            else:
                emg = u'系统 %s 修改失败' % system
                return my_render('upgray/error.html', locals(), request)
            return HttpResponseRedirect(reverse('system_detail')+'?id=%s' % system_id)

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