def detail(request, pk, slug): topic = Topic.objects.get_public_or_404(pk, request.user) if topic.slug != slug: return HttpResponsePermanentRedirect(topic.get_absolute_url()) utils.topic_viewed(request=request, topic=topic) comments = ( Comment.objects .for_topic(topic=topic) .with_likes(user=request.user) .with_polls(user=request.user) .order_by('date')) comments = paginate( comments, per_page=config.comments_per_page, page_number=request.GET.get('page', 1)) return render( request=request, template_name='spirit/topic/detail.html', context={ 'topic': topic, 'comments': comments})
def detail(request, topic_id, slug): topic_private = get_object_or_404( TopicPrivate.objects.select_related('topic'), topic_id=topic_id, user=request.user) topic = topic_private.topic if topic.slug != slug: return HttpResponsePermanentRedirect(topic.get_absolute_url()) topic_viewed(request=request, topic=topic) comments = ( Comment.objects .for_topic(topic=topic) .with_likes(user=request.user) .with_polls(user=request.user) .order_by('date')) comments = paginate( comments, per_page=config.comments_per_page, page_number=request.GET.get('page', 1) ) return render( request=request, template_name='spirit/topic/private/detail.html', context={ 'topic': topic, 'topic_private': topic_private, 'comments': comments,})
def get_context_data(self, **kwargs): ctx = super(TagPinnedDetail, self).get_context_data(**kwargs) topics = Topic.objects\ .visible(self.request.user)\ .with_bookmarks(user=self.request.user)\ .filter(is_pinned=True)\ .order_by('-is_globally_pinned', '-is_pinned', '-last_active')\ .select_related('user', 'user__st', 'last_commenter', 'last_commenter__st')\ .prefetch_related('topictagrelation_set', 'topictagrelation_set__tag')\ topics = paginate( topics, per_page=20, page_number=self.request.GET.get('page', 1) ) ctx.update({ 'tag': { 'slug': 'pinned', 'name': 'Pinned', 'description': 'Topics that are pinned to the top', }, 'topics': topics, }) return ctx
def detail(request, pk, slug): bu = BanUser.objects.filter(username=request.user).first() topic = Topic.objects.get_public_or_404(pk, request.user) if topic.slug != slug: return HttpResponsePermanentRedirect(topic.get_absolute_url()) utils.topic_viewed(request=request, topic=topic) comments = Comment.objects\ .for_topic(topic=topic)\ .with_likes(user=request.user)\ .with_polls(user=request.user)\ .order_by('date') comments = paginate(comments, per_page=config.comments_per_page, page_number=request.GET.get('page', 1)) for c in comments: if bu and bu.is_baned and c.user == request.user: c.is_removed = 0 c.date = c.date + datetime.timedelta(hours=8) #strdatetime = now.strftime("%Y-%m-%d %H:%M:%S") c.date = c.date.strftime("%m-%d") context = {'topic': topic, 'comments': comments} return render(request, 'spirit/topic/detail.html', context)
def get_context_data(self, **kwargs): ctx = super(TagDetail, self).get_context_data(**kwargs) tag = self.object topics = Topic.objects\ .visible(self.request.user)\ .with_bookmarks(user=self.request.user)\ .order_by('-is_globally_pinned', '-is_pinned', '-last_active')\ .select_related('user', 'user__st', 'last_commenter', 'last_commenter__st')\ .prefetch_related('topictagrelation_set', 'topictagrelation_set__tag')\ .filter(topictagrelation_set__tag_id=tag.pk) topics = paginate( topics, per_page=20, page_number=self.request.GET.get('page', 1) ) ctx.update({ 'tag': tag, 'topics': topics, }) return ctx