def app_add(request): """ App add view 添加应用 """ header_title, path1, path2 = u'添加应用', u'应用管理', u'添加应用' app_group_all = AppGroup.objects.all() af = AppForm() default_setting = get_object(Setting, name='default') if request.method == 'POST': af_post = AppForm(request.POST) 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 App.objects.filter(name=str(name)): error = u'该应用名称 %s 已存在!' % name raise ServerError(error) except ServerError: pass else: if af_post.is_valid(): app_save = af_post.save(commit=False) app_save.is_active = True if is_active else False app_save.save() af_post.save_m2m() msg = u'应用 %s 添加成功' % name else: esg = u'应用 %s 添加失败' % name return my_render('upapp/app_add.html', locals(), request)
def map_edit_batch(request): af = AppForm() name = request.user.username app_group_all = AppGroup.objects.all() if request.method == 'POST': app_env = request.POST.get('app_env', '') group = request.POST.getlist('group', []) comment = request.POST.get('comment', '') use_default_auth = request.POST.get('use_default_auth', '') app_id_all = unicode(request.GET.get('app_id_all', '')) app_id_all = app_id_all.split(',') for app_id in app_id_all: alert_list = [] app = get_object(App, id=app_id) if app: if app_env: if app.app_env != app_env: app.app_env = app_env alert_list.append([u'环境', app.app_env, app_env]) if use_default_auth: if use_default_auth == 'default': app.use_default_auth = 1 alert_list.append( [u'使用默认管理账号', app.use_default_auth, u'默认']) if group: group_new, group_old, group_new_name, group_old_name = [], app.group.all( ), [], [] for group_id in group: g = get_object(AppGroup, id=group_id) if g: group_new.append(g) if not set(group_new) < set(group_old): group_instance = list(set(group_new) | set(group_old)) for g in group_instance: group_new_name.append(g.name) for g in group_old: group_old_name.append(g.name) app.group = group_instance alert_list.append([ u'应用组', ','.join(group_old_name), ','.join(group_new_name) ]) if comment: if app.comment != comment: app.comment = comment alert_list.append([u'备注', app.comment, comment]) app.save() if alert_list: recode_name = unicode(name) + ' - ' + u'批量' AppRecord.objects.create(app=app, username=recode_name, content=alert_list) return my_render('upapp/map_update_status.html', locals(), request) return my_render('upapp/map_edit_batch.html', locals(), request)
def map_edit(request): """ edit a app 修改应用 """ header_title, path1, path2 = u'修改应用', u'应用管理', u'修改应用' app_id = request.GET.get('id', '') app = get_object(App, id=app_id) af = AppForm(instance=app) if request.method == 'POST': af_post = AppForm(request.POST, instance=app) 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: app_test = get_object(App, name=name) if app_test and app_id != unicode(app_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 = app_diff(af_post.__dict__.get('initial'), request.POST) smg = u'应用 %s 修改成功' % value else: emg = u'应用 %s 修改失败' % value return my_render('upapp/error.html', locals(), request) return HttpResponseRedirect(reverse('map_detail')+'?id=%s' % app_id) return my_render('upapp/app_edit.html', locals(), request)
def map_edit(request): """ edit a app 修改应用 """ header_title, path1, path2 = u'修改应用', u'应用管理', u'修改应用' app_id = request.GET.get('id', '') app = get_object(App, id=app_id) af = AppForm(instance=app) if request.method == 'POST': af_post = AppForm(request.POST, instance=app) 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: app_test = get_object(App, name=name) if app_test and app_id != unicode(app_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 = app_diff(af_post.__dict__.get('initial'), request.POST) smg = u'应用 %s 修改成功' % value else: emg = u'应用 %s 修改失败' % value return my_render('upapp/error.html', locals(), request) return HttpResponseRedirect( reverse('map_detail') + '?id=%s' % app_id) return my_render('upapp/app_edit.html', locals(), request)