コード例 #1
0
ファイル: views.py プロジェクト: wangyouyan/Python
def url_edit(request):
    """
    Url  edit view
    """
    header_title, path1, path2 = u'编辑URL', u'资产管理', u'编辑URL'
    url_id = request.GET.get('id', '')
    url = get_object(Url_info, id=url_id)
    if request.method == 'POST':
        url_form  = UrlForm(request.POST, instance=url)

        if url_form.is_valid():
            url_form.save()
            return HttpResponseRedirect(reverse('url_list'))
        else:
            emg = "error"
            return my_render('jasset/url_edit.html', locals(), request)
    else:
        url_form = UrlForm(instance=url)
        print url_form
        return my_render('jasset/url_edit.html', locals(), request)
コード例 #2
0
ファイル: views.py プロジェクト: wangyouyan/Python
def url_add(request):
    """
    Url   add view
    """
    header_title, path1, path2 = u'添加URL', u'资产管理', u'添加URL'
    if request.method == 'POST':
        url_form = UrlForm(request.POST)

        if url_form.is_valid():
            url = url_form.cleaned_data['url']
            if Url_info.objects.filter(url=url):
                emg = u'添加URL失败, 此 %s 已存在!' % url
                return my_render('jasset/url_add.html', locals(), request)
            else:
                url_form.save()
                smg = u'URL: %s添加成功' % url
            return HttpResponseRedirect(reverse('url_list'))
    else:
        url_form = UrlForm()
    return my_render('jasset/url_add.html', locals(), request)