Example #1
0
def white_url(request):
    title = u'URL白名单管理'

    if request.method == "POST":
        form = WhiteList_Add(data=request.POST)
        if form.is_valid():
            add_success = True
            if not WhiteUrl.objects.filter(user=Userinfo.objects.get(user=request.user),url=form.cleaned_data['white_url']):
                newwhiteurl = WhiteUrl(   user = Userinfo.objects.get(user=request.user),
                                    url=form.cleaned_data['white_url'],
                                    addtime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                newwhiteurl.save()
                try:
                    whiteurls = ResUrl.objects.filter(user=Userinfo.objects.get(user=request.user),url=form.cleaned_data['white_url'])
                    for i in whiteurls:
                        i.iswhite = True
                        i.save()
                    add = True
                except:
                    add = True
            return render_to_response('usersettings/white_url.html',locals(), context_instance = RequestContext(request))
        else:
            return render_to_response('error.html',locals(), context_instance = RequestContext(request))

    return render_to_response('usersettings/white_url.html',locals(), context_instance = RequestContext(request))
Example #2
0
def add_white_url(request):
    form = WhiteList_Add(data=request.GET)
    if form.is_valid():
        newwhiteurl = WhiteUrl(   user = Userinfo.objects.get(user=request.user),
                                url=form.cleaned_data['white_url'],
                                addtime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        newwhiteurl.save()
        add_success = True
        id = request.GET.get('id')
        editresurl = ResUrl.objects.get(id=id)
        editresurl.iswhite = True
        editresurl.save()
        add_success = True
        return HttpResponseRedirect('/user_statistic/url/')
    else:
        return render_to_response('error.html',locals(), context_instance = RequestContext(request))