Esempio n. 1
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     article = self.object
     context['form'] = ArticleCommentForm()
     comments = article.comments.order_by('-created_at')
     self.paginate_comments_to_context(comments, context)
     return context
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     queryset = super().get_queryset()
     if self.search_query:
         queryset = queryset.filter(Q(tags__name__iexact=self.search_query))
         return queryset
     context = super().get_context_data(**kwargs)
     context['form'] = ArticleCommentForm()
     context['tags'] = ArticleTagForm()
     comments = context['article'].comments.order_by('-created_at')
     self.paginate_comments_to_context(comments, context)
     return context
Esempio n. 3
0
 def post(self, request, *args, **kwargs):
     form = ArticleCommentForm(data=request.POST)
     article_pk = kwargs.get('pk')
     article = get_object_or_404(Article, pk=article_pk)
     if form.is_valid():
         Comment.objects.create(author=form.cleaned_data['author'],
                                text=form.cleaned_data['text'],
                                article=article)
         return redirect('article_view', pk=article_pk)
     else:
         return render(request,
                       'article/article.html',
                       context={
                           'form': form,
                           'article': article
                       })