Example #1
0
def post_count_box(post, context='', topic=''):
    "Displays the count box for a post row"
    topic = Tag.fixcase(topic)
    topic = topic.split('+')
    if LATEST in topic:
        topic.remove(LATEST)
    return dict(post=post, context=context, topic=topic)
Example #2
0
    def get_queryset(self):
        self.topic = self.kwargs.get("topic", "")

        # Catch expired sessions accessing user related information
        if self.topic in AUTH_TOPIC and self.request.user.is_anonymous():
            messages.warning(self.request, "Session expired")
            self.topic = None

        query = None
        user = self.request.user

        if not self.topic:
            self.topic = LATEST

        topic = Tag.fixcase(self.topic)

        if self.group:
            query = self.group.posts.all()
        else:
            if topic == LATEST:
                query = Post.objects.top_level(user)
            elif topic == MYPOSTS:
                # Get the posts that the user wrote.
                query = Post.objects.my_posts(target=user, user=user)
            elif topic == MYTAGS:
                # Get the posts that the user wrote.
                messages.success(self.request,
                                 'Posts matching the <b><i class="fa fa-tag"></i> My Tags</b> setting in your user profile')
                query = Post.objects.tag_search(user.profile.my_tags, user)
            elif topic == UNANSWERED:
                # Get unanswered posts.
                query = Post.objects.top_level(user).filter(type=Post.QUESTION, reply_count=0)
            elif topic == FOLLOWING:
                # Get that posts that a user follows.
                messages.success(self.request, 'Threads that will produce notifications.')
                query = Post.objects.top_level(user).filter(subs__user=user)
            elif topic == BOOKMARKS:
                # Get that posts that a user bookmarked.
                query = Post.objects.my_bookmarks(user)
            elif topic in POST_TYPES:
                # A post type.
                query = Post.objects.top_level(user).filter(type=POST_TYPES[topic])
            else:
                messages.info(self.request,
                              "Showing: <code>%s</code> &bull; <a href='/'>reset</a>" % topic)
                query = Post.objects.tag_search(topic, user)

        query = apply_sort(self.request, query)

        if not self.topic:
            query = query[:settings.SITE_LATEST_POST_LIMIT]
        return query