def etcd_add(request): """ Etcd add view 添加参数 """ header_title, path1, path2 = u'添加参数', u'参数管理', u'添加参数' etcd_group_all = EtcdGroup.objects.all() af = EtcdForm() default_setting = get_object(Setting, name='default') if request.method == 'POST': af_post = EtcdForm(request.POST) value = request.POST.get('value', '') name = request.POST.get('name', '') is_active = True if request.POST.get('is_active') == '1' else False use_default_auth = request.POST.get('use_default_auth', '') try: if Etcd.objects.filter(name=str(name)): error = u'该参数名 %s 已存在!' % name raise ServerError(error) except ServerError: pass else: if af_post.is_valid(): etcd_save = af_post.save(commit=False) if not value: etcd_save.value = name etcd_save.is_active = True if is_active else False etcd_save.save() af_post.save_m2m() msg = u'参数 %s 添加成功' % name else: esg = u'参数 %s 添加失败' % name return my_render('upetcd/etcd_add.html', locals(), request)
def etcd_edit(request): """ edit a etcd 修改参数 """ header_title, path1, path2 = u'修改参数', u'参数管理', u'修改参数' etcd_id = request.GET.get('id', '') etcd = get_object(Etcd, id=etcd_id) af = EtcdForm(instance=etcd) if request.method == 'POST': af_post = EtcdForm(request.POST, instance=etcd) value = request.POST.get('value', '') name = request.POST.get('name', '') is_active = True if request.POST.get('is_active') == '1' else False use_default_auth = request.POST.get('use_default_auth', '') try: etcd_test = get_object(Etcd, name=name) if etcd_test and etcd_id != unicode(etcd_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.is_active = True if is_active else False af_save.save() af_post.save_m2m() info = etcd_diff(af_post.__dict__.get('initial'), request.POST) smg = u'参数 %s 修改成功' % value else: emg = u'参数 %s 修改失败' % value return my_render('upetcd/error.html', locals(), request) return HttpResponseRedirect( reverse('etcd_detail') + '?id=%s' % etcd_id) return my_render('upetcd/etcd_edit.html', locals(), request)
def etcd_edit(request): """ edit a etcd 修改参数 """ header_title, path1, path2 = u'修改参数', u'参数管理', u'修改参数' etcd_id = request.GET.get('id', '') etcd = get_object(Etcd, id=etcd_id) af = EtcdForm(instance=etcd) if request.method == 'POST': af_post = EtcdForm(request.POST, instance=etcd) value = request.POST.get('value', '') name = request.POST.get('name', '') is_active = True if request.POST.get('is_active') == '1' else False use_default_auth = request.POST.get('use_default_auth', '') try: etcd_test = get_object(Etcd, name=name) if etcd_test and etcd_id != unicode(etcd_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.is_active = True if is_active else False af_save.save() af_post.save_m2m() info = etcd_diff(af_post.__dict__.get('initial'), request.POST) smg = u'参数 %s 修改成功' % value else: emg = u'参数 %s 修改失败' % value return my_render('upetcd/error.html', locals(), request) return HttpResponseRedirect(reverse('etcd_detail')+'?id=%s' % etcd_id) return my_render('upetcd/etcd_edit.html', locals(), request)