def update_article(request,articleid=0): typeid = request.POST.get('typeid', '') title = request.POST.get('title', '') u_text = request.POST.get('u_text', '') if articleid==0: a = Article(title=title, typeid=typeid, authorname=request.user.username) a.save() a_addon = AddonArticle(aid=a.aid, content=u_text, authorip=request.META['REMOTE_ADDR']) a_addon.save() sort_img(a.aid) return render_to_response('edit-article.html', {'form': EditForm(), 'page_title': u'添加新文章', 'result_aid':a.aid, 'aid':articleid},context_instance=RequestContext(request,processors=[custom_proc]))#articleid是0时,表示添加新文章 else: a = get_object_or_404(Article, aid=articleid) if request.user.username==a.authorname or in_editor_group(request.user): a.title = title a.typeid = typeid #a.is_verified = None a_addon = AddonArticle.objects.get(aid=articleid) a_addon.content = u_text c=a_addon.content a.save() a_addon.save() sort_img(a.aid) else: return show_article(request,articleid,{'no_perm':True}) return show_article(request,a.aid,{'has_edited':True})
def profile_page(request, username='', ): if not username or username == request.user.username or username==request.user.id: user = request.user is_self = True else: try: user = Member.objects.get(id=username) except: user = get_object_or_404(Member,username=username) page = request.GET.get('page','') profile_dict={ 'id':user.id, 'username':user.username, 'nickname':user.nickname, 'email':user.email, } verify_auth=in_editor_group(request.user) resume_auth=in_admin_group(request.user) article_list = [{'aid':a.aid, 'is_deleted':a.is_deleted, 'is_verified':a.is_verified, 'is_headline':a.is_headline, 'title':a.title, 'authorname':a.authorname, 'typename':Type.objects.get(typeid=a.typeid).typename} for a in Article.objects.filter(authorname=user.username) if (not a.is_deleted or resume_auth) and (a.is_verified or verify_auth or a.authorname==request.user.username)] article_list = pag(article_list,page,20) return render_to_response('member-profile.html',{'profile_dict':profile_dict, 'article_list':article_list, 'verify_auth':verify_auth, 'resume_auth':resume_auth, 'page_title':user.username},context_instance=RequestContext(request,processors=[custom_proc]))
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 show_article(request, articleid, status={}, verify_form=None): a = get_object_or_404(Article, aid=articleid) if a.is_verified or in_editor_group(request.user) or request.user.username==a.authorname: if not a.is_deleted or in_admin_group(request.user): a_addon = AddonArticle.objects.get(aid=articleid) type = Type.objects.get(typeid=a.typeid) content = a_addon.content try: author = Member.objects.get(username=a.authorname) nickname = author.nickname except: nickname = a.authorname return render_to_response('show-article.html', {'article':a, 'nickname':nickname, 'content':content, 'type':type, 'newest':get_new_article(), 'status':status, 'verify_form':verify_form, 'page_title':a.title},context_instance=RequestContext(request,processors=[custom_proc]))
def list_article(request, u='', list_method='all'): verify_auth=in_editor_group(request.user) if not verify_auth: return Http404() resume_auth=in_admin_group(request.user) list_all = False if not u or u == request.user.username or u==request.user.id: user = request.user is_self = True if not u: list_all = True else: try: user = Member.objects.get(id=u) except: user = get_object_or_404(Member,username=u) page = request.GET.get('page','') if list_all: articles = Article.objects.all() else: articles = Article.objects.filter(authorname=user.username) article_list = [{'aid':a.aid, 'is_deleted':a.is_deleted, 'is_verified':a.is_verified, 'is_headline':a.is_headline, 'title':a.title, 'authorname':a.authorname, 'typename':Type.objects.get(typeid=a.typeid).typename} for a in articles if check_article(a,list_method,verify_auth,resume_auth)] article_list = pag(article_list,page,20) list_method_dict = {list_method:1} return render_to_response('wheel/list-article.html',{'article_list':article_list, 'resume_auth':resume_auth, 'verify_auth':verify_auth, 'user':user, 'list_all':list_all, 'method':list_method_dict, 'page_title':u'article manage'},context_instance=RequestContext(request,processors=[custom_proc]))
def edit_article(request,articleid=0): page_title=u'添加新文章' if request.method == 'POST': form = EditForm(request.POST) if form.is_valid(): return update_article(request,articleid) else: if articleid==0: form = EditForm() else: a = get_object_or_404(Article, aid=articleid) if request.user.username==a.authorname or in_editor_group(request.user): a_addon = AddonArticle.objects.get(aid=articleid) form = EditForm(initial={'title':a.title, 'typeid':a.typeid, 'u_text':a_addon.content}) page_title=u'编辑-%s'%(a.title) else: return show_article(request,articleid,{'no_perm':True}) return render_to_response('edit-article.html', {'form': form, 'page_title': page_title, 'aid':articleid},context_instance=RequestContext(request,processors=[custom_proc]))
def verify_article(request,articleid,status={}): if not in_editor_group(request.user): status={'no_perm':True} return show_article(request,articleid,status) else: a = get_object_or_404(Article, aid=articleid) if request.method=='POST': form = VerifyForm(request.POST,initial={'aid':a.aid}) if form.is_valid(): is_verified=format_boolean(request.POST.get('is_verified')) is_headline=request.POST.get('is_headline') is_slideshow=request.POST.get('is_slideshow') slideshow_img=request.POST.get('slideshow_img') a.is_verified=is_verified a.is_headline=is_headline a.is_slideshow=is_slideshow if is_slideshow and slideshow_img is not '0': a.slideshow_img=ImageUpload.objects.get(thumb_path=slideshow_img) a.save() status={'be_verified':True} return show_article(request,articleid,status) else: status['verify_failed']=True status['to_verify']=True verify_form=VerifyForm(request.POST,initial={'aid':a.aid}) return show_article(request,articleid,status,verify_form) else: thumb_path='' if a.is_slideshow: thumb_path=a.slideshow_img.thumb_path verify_form=VerifyForm(initial={'is_verified':a.is_verified, 'is_headline':a.is_headline, 'is_slideshow':a.is_slideshow, 'aid':a.aid, 'slideshow_img':thumb_path}) status={'to_verify':True} return show_article(request,articleid,status,verify_form)