def resume_article(request,articleid): '''可以与delete_article重构为同一个视图''' a = get_object_or_404(Article, aid=articleid) if in_admin_group(request.user): a.is_deleted=False a.save() return redirect(request, URL_PRE+'/member/profile/%s/'%(a.authorname)) else: raise Http404()
def login(request): if not request.user.is_authenticated(): next='' if request.GET.get('next'): next='?next='+request.GET.get('next') if request.method == 'POST': form = LoginForm(request.POST) e=form.errors if form.is_valid(): username = request.POST.get('username', '') password = request.POST.get('password', '') user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: auth.login(request, user) return redirect(request,URL_PRE+"/") else: return render_form_page(request,next,'login.html',LoginForm,error={'pwd_wrong':True}) return render_form_page(request,next,'login.html',LoginForm) else: return redirect(request,URL_PRE+"/")
def delete_article(request,articleid): a = get_object_or_404(Article, aid=articleid) if request.user.username==a.authorname or in_editor_group(request.user): a.is_deleted=True a.is_verified=False a.is_slideshow=False a.is_headline=False a.save() return redirect(request, URL_PRE+'/member/profile/%s/'%(a.authorname))#目前还没法在重定向的页面中提示删除成功,待完善 else: return show_article(request,articleid,{'no_perm':True})
def useradd(request): if in_admin_group(request.user): error={} if request.method == 'POST': form = UseraddForm(request.POST) if form.is_valid(): post_data=form.cleaned_data username,pw,email,nickname = post_data['username'],post_data['password'],post_data['email'],post_data['nickname'] try: user = Member.objects.create_user(username, email, pw) user.nickname=nickname uaddon = MemberAddon(mid=user.id) user.save() uaddon.save() return redirect(request,'/wheel/') except: error['name_wrong']=True#实际上也可能会是邮箱出错 return render_form_page(request,'','wheel/useradd.html',UseraddForm,{},error) else: return HttpResponseRedirect('/')
def logout(request): auth.logout(request) return redirect(request,URL_PRE+"/")