示例#1
0
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)
示例#2
0
文件: views.py 项目: gyw040518/utopia
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)
示例#3
0
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)
示例#4
0
文件: views.py 项目: gyw040518/utopia
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)