def edit_post(request, model, pk): profile = request.user.get_profile() if model == "comment": post = Comment.objects.get(pk=pk) form = CommentForm(instance=post) elif model == "post": post = Post.objects.get(pk=pk) form = PostForm(instance=post) elif model == "message": post = Message.objects.get(pk=pk) form = MessageForm(instance=post) if post.author == profile: print "" if request.POST: if model == "comment": form = CommentForm(request.POST, instance=post) elif model == "post": form = PostForm(request.POST, instance=post) elif model == "message": form = MessageForm(request.POST, instance=post) if form.is_valid(): form.save() return HttpResponseRedirect("/") return render( request, "publication/change_post.html", {"model": model, "form": form, "post": post, "profile": profile} ) else: return HttpResponseRedirect("/")
def edit_post(request, pk_thread=None, pk_post=None): """Edit a thread.""" post = get_object_or_404(Post, pk=pk_post) thread = get_object_or_404(Thread, pk=pk_thread) forum = Forum.objects.get(thread__pk=pk_thread) is_admin = False club = Club.objects.get(forum=forum) student = StudentProfile.objects.get(user=request.user) if Member.objects.filter(club=club, student__user=request.user, admin=True): is_admin = True if pk_post: post = get_object_or_404(Post, pk=pk_post) if post.creator != request.user and is_admin == False: raise Http404 else: post = Post(creator=request.user) if request.POST: form = CommentForm(request.POST, instance=post) if form.is_valid(): form.save() return HttpResponseRedirect( reverse("forum.views.thread", args=[pk_thread]) + "?page=last") else: form = CommentForm(instance=post) return render_to_response('forum/post_edit.html', add_csrf(request, form=form), context_instance=RequestContext(request))
def add_comment(request, id): form = CommentForm(request.POST) if form.is_valid(): post = Blog.objects.get(id=id) form.save(post = post) return HttpResponseRedirect('/')
def edit_post(request, pk_thread=None, pk_post=None): """Edit a thread.""" post = get_object_or_404(Post, pk=pk_post) thread = get_object_or_404(Thread, pk=pk_thread) forum = Forum.objects.get(thread__pk=pk_thread) is_admin = False club = Club.objects.get(forum=forum) student = StudentProfile.objects.get(user=request.user) if Member.objects.filter(club=club, student__user=request.user, admin=True): is_admin = True if pk_post: post = get_object_or_404(Post, pk=pk_post) if post.creator != request.user and is_admin == False: raise Http404 else: post = Post(creator=request.user) if request.POST: form = CommentForm(request.POST, instance=post) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("forum.views.thread", args=[pk_thread]) + "?page=last") else: form = CommentForm(instance=post) return render_to_response('forum/post_edit.html', add_csrf(request, form=form), context_instance=RequestContext(request))
def post(self, request, slug): product = get_object_or_404(Product, slug=slug) like = True if request.user.is_authenticated(): like = Likes.objects.filter(user=request.user, product=product).exists() comments = Comment.objects.filter(product=product, pub_date__range=[ t.now() - t.timedelta(hours=24), t.now() ]).values('name', 'comment') form = CommentForm(request.POST) if form.is_valid(): form.save() messages.success(request, 'Your comment has been added!') return redirect(reverse('test_task:product_detail', args=[product.slug])) else: messages.error(request, 'Your comment is not added.') context = {'product': product, 'comments': comments, 'form': form, 'like': like} return render(request, 'test_task/product_detail.html', context)
def comments(request): comments_list = Comment.objects.order_by('-created_at') if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): captcha_response = request.POST.get['g-recaptcha-response'] data = { 'secret': '6LcdyuAUAAAAAGtSgh1HroDq1k6SMMHjX0g8AJ9c', 'response': captcha_response } r = requests.post( 'https://www.google.com/recaptcha/api/siteverify', data=data) result = r.json() if result['success']: form.save() messages.success(request, 'New comment added with success!') else: messages.error(request, 'Invalid reCAPTCHA. Please try again.') return redirect('comments') else: form = CommentForm() return render(request, 'comments.html', { 'form': form, 'comments': comments_list })
def comment(request, id): form = CommentForm(request.POST) form = form.save(commit=False) form.ticket_id = id form.user_id = request.user.id form.save() return redirect(reverse('support'))
def blog_detail(request, slug): # try: # log_write(request) # except: # pass user = request.user content = get_object_or_404(Blog, slug=slug) comments = Comment.objects.filter(blog=content) context = {'content': content, 'comments': comments} context.update(csrf(request)) if request.method == 'POST' and user.is_authenticated(): comment_form = CommentForm(request.POST) if comment_form.is_valid(): ip = request.META['REMOTE_ADDR'] comment_form.save(content, user, ip) return redirect(request.META['HTTP_REFERER']) else: comment_form = CommentForm() context['comment_form'] = comment_form Blog.objects.filter(id=content.id).update( views_count=F('views_count') + random.randint(1, 3) ) return render(request, 'blog/blog_detail.html', context)
def blog_detail(request, slug): user = request.user SLUGS = [ 'slug', 'drupal_slug', 'nid', 'id', ] for slug_name in SLUGS: try: if 'id' not in slug_name or slug.isdigit(): content = Blog.objects.get(**{slug_name: slug}) break except Blog.DoesNotExist: continue else: raise Http404 comments = Comment.objects.filter(blog=content).order_by('-create_time') contents = {'content': content, 'comments': comments} contents.update(csrf(request)) if request.method == 'POST' and user.is_authenticated(): comment_form = CommentForm(request.POST) if comment_form.is_valid(): ip = request.META['REMOTE_ADDR'] comment_form.save(content, user, ip) return redirect(request.META['HTTP_REFERER']) else: comment_form = CommentForm() contents['comment_form'] = comment_form return render(request, 'blog/blog_detail.html', contents)
def add_comment(request, cloth_id): if request.POST: form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.item = Cloth.objects.get(id=cloth_id, is_published=True) form.save() return redirect('/wear/detail/%s/' % cloth_id)
def addcomment(request, article_id): if request.POST: form = CommentForm(request.POST) if form.is_valid(): Comment = form.save(commit=False) Comment.comment_article = article.objects.get(id = article_id) form.save() return redirect('/article/get/%s/' % article_id)
def post_detail(request, pk, temlate_name="blog/post_detail.html"): post = get_object_or_404(Post, pk=pk) comments = post.comments.all() form = CommentForm(request.POST or None) if form.is_valid(): form.save(pk) form = CommentForm() # return HttpResponseRedirect(reverse('post_detail', args=[post_id])) return direct_to_template(request, temlate_name, {"post": post, "comments": comments, "form": form})
def post(request): output = dict(success=False) form = CommentForm(None, request.POST) if form.is_valid(): form.save(request.user) output['success'] = True else: output['errors'] = form.get_errors() return HttpResponse(json.dumps(output), "text/javascript")
def addcomment(request, article_id): if request.POST: form = CommentForm(request.POST) if form.is_valid(): form = form.save(commit=False) # form.comments_article_id = article_id form.comments_article = Article.objects.get(pk = article_id) form.save() return HttpResponseRedirect(reverse('article:detail',args = (article_id,)))
def addcomment(request, product_id, product_slug): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment=form.save(commit=False) comment.comments_product=Product.objects.get(slug=product_slug) form.save() request.session.set_expiry(10) request.session['pause']=True return redirect('/product/product_slug/product_id/%s' %product_id)
def addcomment(request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_article = Article.objects.get(id=article_id) form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/articles/get/%s/' % article_id)
def addcomment(request, article_id): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_article = Article.objects.get(id=article_id) form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/articles/get/%s/' % article_id)
def add_comment(request, Lot_id): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_for_lot = Lot.objects.get(id=Lot_id) form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('http://localhost:8181/show/show_details/%s/' % Lot_id)
def addcomment (request, article_id): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False)#забороняє зберігати одразу в БД, при тому записуючи в comment значення тектстового поля comment.comments_article = Article.objects.get(id=article_id) form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/articles/get/%s/' % article_id) #повернути на ту саму сторінку з якої писався коментар
def addcomment(request, product_id): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_author = request.user comment.comments_product = Product.objects.get(id=product_id) form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/products/get/%s/' % product_id)
def post(self, request, *args, **kwargs): self.object = self.get_object() form = CommentForm(object=self.object, data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(self.object.get_absolute_url()) context = self.get_context_data(object=self.object, form=form) return self.render_to_response(context)
def add_comment(request,id): post = Post.objects.filter(id=id) if post: post = post[0] if 'POST' == request.method: form = CommentForm(request.POST) if form.is_valid(): form.save() else: form = CommentForm() return render(request, 'blog/blogger.html', { 'form' : form , 'post': post} )
def add_comment(request, blog_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.user = request.user comment.comments_blog = BlogPost.objects.get(id=blog_id) form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/')
def addcomment(request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) #из брауз.отправились в commentform и присвоились в form if form.is_valid(): comment = form.save(commit=False) #commit=False для того что бы form.save не сохранял данные в базу пока не получить comments_article comment.comments_article = Article.objects.get(id=article_id) # comment.comments_user = auth.get_user(request).username form.save() # request.session.set_expiry(60) #создает объект сессии который живет в течении 60 сек request.session['pause'] = True return redirect('/articles/get/%s/' % article_id)
def addcomment(request, article_id, *args, **kwargs): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.article = Article.objects.get(id=article_id) comment.user_from_id = auth.get_user(request).id form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/articles/get/%s/' % article_id)
def addcomment(request, item_id): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): user_id = User.objects.all() comment = form.save(commit=False) comment.comments_item = Item.objects.get(id=item_id) comment.comments_from = User.objects.get(id=user_id) form.save() request.session.set_expiry(30) request.session['pause'] = True return redirect('/items/get/%s/' % item_id)
def save_comment(request, msg_pk): if request.POST: message = Message.objects.get(pk=msg_pk) form = CommentForm(message, user=request.user, data=request.POST) if form.is_valid(): form.save() return redirect("/socials/message/{}".format(msg_pk, )) else: return render(request, "message_board/message.html", { "message": message, "comment_form": form })
def addcomment(request,book_id): if request.POST and ("pause" not in request.session): form=CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_book=Book.objects.get(id=book_id) comment.comments_from=request.user comment.comments_date=timezone.now() form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/books/get/%s/'%book_id)
def addcomment(request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_article = Article.objects.get(id = article_id) comment.comments_date = datetime.datetime.now() comment.comments_from = auth.get_user(request) form.save() request.session.set_expiry(60) # SESSION 60 sec request.session['pause'] = True # SESSION return redirect('/articles/get/%s/' % article_id)
def addcomment(request, book_id): if request.POST and ("pause" not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_book = Book.objects.get(id=book_id) comment.comments_from = request.user comment.comments_date = timezone.now() form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/books/get/%s/' % book_id)
def addcomment(request, article_id): if request.POST and ("pause" not in request.session): # check on POST request and for absence of pause-session form = CommentForm(request.POST) # write information from POST in variable if form.is_valid(): comment = form.save(commit=False) # cancel autosave in our form (there not all fields: article_id is cut) comment.comments_article = Article.objects.get(id=article_id) # equal data to our DB comment.comments_from_id = auth.get_user(request).id comment.comments_date = datetime.now() form.save() request.session.set_expiry(60) # making time for session 60 sec request.session['pause'] = True # crate 'pause'-session return redirect('/articles/get/%s/' % article_id)
def addcomment (request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): id_cur_user=auth.get_user(request).id comment = form.save(commit=False) comment.comments_article = Article.objects.get(id=article_id) comment.comments_from = apps.get_model("auth", "User").objects.all().filter(id=id_cur_user)[0] form.save() request.session.set_expiry(60) request.session['pause']=True return redirect('/articles/get/%s/' % article_id)
def post(request, id): post = Post.objects.get(id=id) form = CommentForm() comments = Comment.objects.filter(post = post, approved = True) teve_comentario = False if request.method == 'POST': comment = Comment(post=post) form = CommentForm(request.POST, instance=comment) if form.is_valid(): teve_comentario = True form.save() return render(request, "post.html", locals())
def form_valid(self, form): # Topic form is valid, no validate comment form comment_form = CommentForm(self.request.POST) if not comment_form.is_valid(): return self.form_invalid() form.instance.creator = self.request.user topic = form.save() comment_form.instance.topic = topic comment_form.instance.creator = self.request.user comment_form.save() return HttpResponseRedirect(topic.get_absolute_url())
def addcomment(request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): id_cur_user = auth.get_user(request).id comment = form.save(commit=False) comment.comments_article = Article.objects.get(id=article_id) comment.comments_from = apps.get_model( "auth", "User").objects.all().filter(id=id_cur_user)[0] form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/articles/get/%s/' % article_id)
def add_comment(request, pk): if request.POST and ('pause' not in request.session): # make variable (instance class CommentForm) form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comment_article = Article.objects.get(id=pk) comment.comment_name_id = auth.get_user(request).id form.save() messages.success(request, "Comment successfully added") request.session.set_expiry(60) request.session['pause'] = True return redirect('articles:article_detail', pk)
def addcomment(request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comments_article = Article.objects.get(id=article_id) comment.comments_from_id = auth.get_user(request).id comment.comments_date = datetime.now() form.save() request.session.set_expiry(60) request.session['pause'] = True return redirect('/articles/get/%s/' % article_id)
def addcoment(request, article_id): if request.POST and 'pause' not in request.session: form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit = False) comment.comments_article = Article.objects.get(id = article_id) comment.comments_date = now_time user_id = auth.get_user(request).id comment.comments_user = User.objects.get(id = user_id) form.save() request.session.set_expiry(60) request.session['pause'] = True url = request.META.get('HTTP_REFERER') return redirect(url)
def add_comment(request, event_id): e = Event.objects.get(id=event_id) if request.method == "POST": f = CommentForm(request.POST) if f.is_valid(): user_logger.debug('COMMENTED: '+request.user.username+' to '+event_id) c = f.save(commit=False) c.pub_date = timezone.now() c.username = request.user.username c.event = e c.save() return HttpResponseRedirect('/events/get/%s' % event_id) else: f = CommentForm() args = {} args.update(csrf(request)) args['event'] = e args['form'] = f return render_to_response('listing.html', args, context_instance=RequestContext(request))
def post_view(request, post_id): post = get_object_or_404(Post,id=post_id) if not post.active: return HttpResponseNotFound() other_posts = Post.objects.filter(tag=post.tag).exclude(id=post.id)[:10] captcha = CaptchasDotNet(client = 'barauskas',secret = 'K1Qurc2oCY09sJA63cpseGEz3zOpwzDeZeR6YNvf') if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): if captcha.verify(form.cleaned_data['captcha'],request.session.get('rand','')): form.instance.post = post comment = form.save() #comment.post = post #comment.save() form = CommentForm(initial={'author':get_user_name()}) else: form.errors['captcha']=['Captcha is unvalid!'] else: form = CommentForm(initial={'author':get_user_name()}) rand = str(int(random()*1000000)) request.session['rand']=rand return render_to_response('blog/view.html', {'post': post, 'other_posts': other_posts, 'form': form, 'captcha':captcha.image_url(rand) }, context_instance=RequestContext(request))
def add_comment(request, book_id): book = Book.objects.get(id=book_id) if request.POST: f = CommentForm(request.POST) if f.is_valid(): c = f.save(commit=False) c.book = book c.save() return HttpResponseRedirect('/books/book/%s' % books_id) else: f = CommentForm() args = {} args.update(csrf(request)) args['book'] = book args['form'] = f # right box args['menu'] = Menu.objects.all() args['pop_books'] = Book.objects.all().order_by('likes').reverse()[:10] args['new_books'] = Book.objects.all().order_by('date').reverse()[:10] args['cats'] = Category.objects.all() args['tags'] = Tag.objects.all() args['current_item'] = 'книги' # user args['username'] = auth.get_user(request).username # poll args['question_web'] = Question.objects.get(text=u"Как вам наш сайт?") args['choices'] = Choice.objects.filter(question_id=args['question_web'].id) return render_to_response('book/book.html', args)
def add_comment(request, article_id): a = Article.objects.get(id=article_id) if request.method == "POST": f = CommentForm(request.POST) if f.is_valid(): c = f.save(commit=False) c.pub_date = timezone.now() c.article = a c.save() messages.success(request, "You Comment was added") return HttpResponseRedirect('/articles/get/%s' % article_id) else: f = CommentForm() args = {} args.update(csrf(request)) args['article'] = a args['form'] = f return render_to_response('add_comment.html', args)
def addcomment(request, page_number, Article_id): if request.POST and ('pause' not in request.session): # and ('pause' not in request.session) для добавления комментария только 1 в set_expiry(60) - минуту form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) # получить данные из формы comment.Comments_id = Article.objects.get(id=Article_id) form.save() # сохранить изменения в форме #<--для сесии учебное request.session.set_expiry(60) request.session['pause'] = True #для сесии учебное--> #return redirect('articles/%s' % Article_id) return redirect('/articles/page/%s/' % page_number)
def add_comment(request, article_id): print article_id a = Article.objects.get(id=article_id) values = {} values.update(csrf(request)) values['form'] = CommentForm() values['article'] = a page = render_to_response("add_comment.html", values) print "Checking whether a form was submitted" print request.method if request.method == 'POST': print "Form submitted" f = CommentForm(request.POST) if f.is_valid(): print "Form is valid" c = f.save(commit=False) c.pub_date = timezone.now() c.article = a c.save() page = HttpResponseRedirect('/articles/get/%s' % article_id) return page
def create_comment_answer(request, answer_id): a = Answer.objects.get(id=answer_id) if request.POST: f = CommentForm(request.POST) if f.is_valid(): c = f.save(commit=False) c.pub_date = timezone.now() c.related_answer = a c.posted_by = request.user c.save() a.num_comments += 1 a.comments.add(c) a.save() return HttpResponseRedirect('/get/%s' % a.related_article_id) else: f = CommentForm() args = {} args.update(csrf(request)) args['article'] = a args['form'] = f return render(request, 'add_comment.html', args)
def get_post(request, slug): event = get_object_or_404(EventModel, slug=slug) comm_parent = Comment.objects.filter(is_parent=True).filter(post=event) if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) parent_obj = None try: parent_id = Comment.objects.get( id=int(request.POST.get("parent_id"))) except: parent_id = None if parent_id: parent_qs = Comment.objects.filter(id=parent_id.id) if parent_qs: parent_obj = parent_qs.first() comment.is_parent = False else: comment.is_parent = True comment.post = event comment.user = request.user comment.parent = parent_obj comment.save() return render(request, 'posts/Offer-page.html', { 'events': event, 'comm_parent': comm_parent, 'user': request.user })
def add(request): user = request.user if request.method == 'GET': initial = {} if user.is_authenticated(): try: profile = request.user.get_profile() except: profile = None initial['username'] = '******'.join([ name for name in user.last_name, user.first_name, getattr(profile, 'middle_name', '') if name ]) if not initial['username']: initial['username'] = request.user.username initial['email'] = request.user.email initial['base_object'] = request.GET.get('bid') initial['re'] = request.GET.get('re') form = CommentForm(initial=initial) else: data = dict([(key, value.strip()) for key, value in request.POST.items()]) form = CommentForm(data) if form.is_valid(): comment = form.save() if user.is_authenticated(): comment.author = user comment.save() return u"Спасибо за Ваш комментарий! После рассмотрения модератором он будет опубликован!<p><a href=''>Обновить страницу</a></p>" context = {'form': form} return template_loader.get_template("tsogu_comments_form.html").render( RequestContext(request, context))
def comment(request, id): print("enter!!!") context = {} print(Post.objects.all()) print("comment!!") post = get_object_or_404(Post, id=id) if (not post): context['error'] = 'The post does not exist.' return render(request, 'grumblr/comments.json', context, content_type='application/json') new_comment = Comment.objects.create(author_user_profile=get_object_or_404( UserProfile, user=request.user), time=datetime.datetime.now(), post=post) comment_form = CommentForm(request.POST, instance=new_comment) if not comment_form.is_valid(): context['error'] = 'The comment is invalid.' return render(request, 'grumblr/comments.json', context, content_type='application/json') new_comment = comment_form.save() context['comment'] = new_comment return render(request, 'grumblr/comment.html', context)
def add_comment(request, pk): if request.user.is_authenticated(): if request.POST.has_key("text") and request.POST["text"]: author = request.user comment = MoseyerComment(moseyer=Moseyer.objects.get(pk=pk)) cf = CommentForm(request.POST, instance=comment) comment = cf.save(commit=False) comment.author = author comment.save() return HttpResponseRedirect("/mosey/decision/{}".format(pk))
def edit_comment(request, id, com): comment = get_object_or_404(Comment, pk=com) if request.method == "POST": form = CommentForm(request.POST, request.FILES, instance=comment) if form.is_valid(): comment.content = form.save() return redirect(featured_detail, id) else: form = CommentForm(instance=comment) return render(request, 'comments/editcomment.html', {'form': form})
def leave_comment(request, slug): 'stand-alone comment form, shown mostly after validation fails.' article = get_object_or_404(Article, slug=slug) # instantiate a form if request.method == 'POST': data = request.POST.copy() data['article_slug'] = slug comment_form = CommentForm(data) if comment_form.is_valid(): comment_form.save() return HttpResponseRedirect('/%s/#comments' % slug) else: comment_form = CommentForm() return render_to_response( 'blog/leave_comment.html', RequestContext(request, dict(comment_form=comment_form, article=article)))
def addcomment(request, article_id): if request.POST and ('pause' not in request.session): form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.comment_article = Article.objects.get(id=article_id) form.save request.session.set_expiery(60) request.session['pause'] = True return redirect('/article/get/%s/' % article_id, context_instance=RequestContext(request))
def add_comment_to_post(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return redirect('post_detail', pk=post.pk) else: form = CommentForm() return render(request, 'blog/comment_form.html', {'form': form})
def add_comment_to_post(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return HttpResponseRedirect('/spectre/') else: form = CommentForm() return render(request, 'add_comment_to_post.html', {'form': form})
def post(request, pk): post = Post.objects.get(pk=pk) form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return redirect(request.path) d = dict(post=post, form=form, user=request.user) d.update(csrf(request)) return render_to_response("blog_detail.html", d, context_instance=RequestContext(request))
def view_post(request, slug): post = get_object_or_404(BlogPage, slug=slug) form = CommentForm(request.POST or None) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return redirect(request.path) return render_to_response('/blog/blog_page.html', { 'post': post, 'form': form, }, context_instance=RequestContext(request))