def get_context_data(self, **kwargs): context = super(ArticleView, self).get_context_data(**kwargs) context['article'] = self.article context['related_articles'] = self.article.related_articles.all() context['vote_form'] = VoteForm(instance=self.opinion) # context['comments'] = ArticleComment.objects.filter(article = self.article).filter(is_verified=True) context['cookie_user'] = self.cookie_user context['recent_related'] = Article.get_by_category(self.article.first_category().get_root()).exclude(pk=self.article.pk).order_by('-created_at')[:6] return context
def get_context_data(self, **kwargs): context = super(ArticleListViewByCategory, self).get_context_data(**kwargs) category_name = self.kwargs['category_name'] page = self.request.GET.get('page') category = ArticleCategory.from_url_string(category_name) articles = Article.get_by_category(category).order_by('-created_at') context['category'] = category tag = self.request.GET.get('tag') if tag: articles = articles.filter(tags__name=tag) paginator = Paginator(articles, self.article_per_page) try: context['articles'] = paginator.page(page) except EmptyPage: context['articles'] = paginator.page(paginator.num_pages) except PageNotAnInteger: context['articles'] = paginator.page(1) return context