(request, topic="")
return posts
Generates a post list on a topic.
Generates a post list on a topic.
Generates a post list on a topic .
def get_posts(request, topic=""):
    """
    Generates a post list on a topic.
    """

    user = request.user
    # Topics are case insensitive.
    topic = topic or LATEST
    topic = topic.lower()

    # Detect known post types.
    post_type = POST_TYPE.get(topic)

    # Get all open top level posts.
    posts = Post.objects.filter(is_toplevel=True, status=Post.OPEN)

    # Pass the above query when asking for latest
    if topic == LATEST:
        pass
    # Filter for various post types.
    elif post_type is not None:
        posts = posts.filter(type=post_type)

    elif topic == SHOW_SPAM and (user.is_authenticated and user.profile.is_moderator):
        posts = get_spam(request)

    elif topic == OPEN:
        posts = posts.filter(type=Post.QUESTION, answer_count=0)

    elif topic == BOOKMARKS and user.is_authenticated:
        posts = Post.objects.filter(votes__author=user, votes__type=Vote.BOOKMARK)

    elif topic == FOLLOWING and user.is_authenticated:
        posts = posts.filter(subs__user=user).exclude(subs__type=Subscription.NO_MESSAGES)

    elif topic == MYPOSTS and user.is_authenticated:
        # Show users all of their posts ( deleted, spam, or quarantined )
        posts = Post.objects.filter(author=user)

    elif topic == MYVOTES and user.is_authenticated:
        posts = posts.filter(votes__post__author=user)

    elif topic == MYTAGS and user.is_authenticated:
        tags = map(lambda t: t.lower(), user.profile.my_tags.split(","))
        posts = posts.filter(tags__name__in=tags).distinct()

    else:
        posts = Post.objects.none()

    return posts
def get_posts ( request , topic = "" ) : user = request . user # Topics are case insensitive. topic = topic or LATEST topic = topic . lower ( ) # Detect known post types. post_type = POST_TYPE . get ( topic ) # Get all open top level posts. posts = Post . objects . filter ( is_toplevel = True , status = Post . OPEN ) # Pass the above query when asking for latest if topic == LATEST : pass # Filter for various post types. elif post_type is not None : posts = posts . filter ( type = post_type ) elif topic == SHOW_SPAM and ( user . is_authenticated and user . profile . is_moderator ) : posts = get_spam ( request ) elif topic == OPEN : posts = posts . filter ( type = Post . QUESTION , answer_count = 0 ) elif topic == BOOKMARKS and user . is_authenticated : posts = Post . objects . filter ( votes__author = user , votes__type = Vote . BOOKMARK ) elif topic == FOLLOWING and user . is_authenticated : posts = posts . filter ( subs__user = user ) . exclude ( subs__type = Subscription . NO_MESSAGES ) elif topic == MYPOSTS and user . is_authenticated : # Show users all of their posts ( deleted, spam, or quarantined ) posts = Post . objects . filter ( author = user ) elif topic == MYVOTES and user . is_authenticated : posts = posts . filter ( votes__post__author = user ) elif topic == MYTAGS and user . is_authenticated : tags = map ( lambda t : t . lower ( ) , user . profile . my_tags . split ( "," ) ) posts = posts . filter ( tags__name__in = tags ) . distinct ( ) else : posts = Post . objects . none ( ) return posts