def article_post(request): sections = SectionForum.objects.all() if request.method == "POST": article_post_form = ArticlePostForm(data=request.POST) if article_post_form.is_valid(): cd = article_post_form.cleaned_data #try: new_article = ArticlePost() new_article.author = request.user new_article.title = cd.get('title') new_article.ueditor_body = cd.get('content') new_article.section_belong_fk = SectionForum.objects.get( name=request.POST.get('secsb')) new_article.save() # 更新用户动态 new_action = common_member_action_log() new_action.uid = request.user new_action.pid = new_article new_action.action = 'post' new_action.save() common_member.objects.filter(id=request.user.id).update( posts=request.user.posts + 1) #url = reverse('') url = reverse('article_detail', kwargs={ 'pid': new_article.pid, 'slug': new_article.slug }) #print(url) return HttpResponseRedirect(url) #return HttpResponse('1') #except: #return HttpResponse("2") else: return HttpResponse("3") else: article_post_form = ArticlePostForm() context = {'sections': sections} return render(request, "x_fatie_demo.html", { "article_post_form": article_post_form, "sections": sections })
def section_all(request, section_slug): section = SectionForum.objects.filter(slug=section_slug).first() posts = ArticlePost.objects.filter( section_belong_fk=section).order_by('-pub_date')[0:2 * Num_per_page] post_num = ArticlePost.objects.filter(section_belong_fk=section).count() if request.method == "POST": post_form = FastPostForm(data=request.POST) if post_form.is_valid(): cd = post_form.cleaned_data #try: new_article = ArticlePost() new_article.author = request.user new_article.title = cd.get('title') new_article.ueditor_body = cd.get('content') new_article.section_belong_fk = section new_article.save() # 更新用户动态 new_action = common_member_action_log() new_action.uid = request.user new_action.pid = new_article new_action.action = 'post' new_action.save() common_member.objects.filter(id=request.user.id).update( posts=request.user.posts + 1) form = FastPostForm() context = { 'section': section, 'post_num': post_num, 'posts': posts, 'form': form, } return render(request, 'x_bankuai_demo.html', context)
def article_post(request): if request.method == "POST": article_post_form = ArticlePostForm(data=request.POST) if article_post_form.is_valid(): cd = article_post_form.cleaned_data #try: new_article = ArticlePost() new_article.author = request.user new_article.title = cd.get('title') new_article.ueditor_body = cd.get('content') new_article.save() # 更新用户动态 new_action = common_member_action_log() new_action.uid = request.user new_action.pid = new_article new_action.action = 'post' new_action.save() #url = reverse('') url = reverse('article_detail', kwargs={ 'pid': new_article.pid, 'slug': new_article.slug }) #print(url) return HttpResponseRedirect(url) #return HttpResponse('1') #except: #return HttpResponse("2") else: return HttpResponse("3") else: article_post_form = ArticlePostForm() return render(request, "x_fatie_demo.html", {"article_post_form": article_post_form})