(request, topic=None, tag="", cutoff=None, ordering=None)
return posts
Post listing. Filters, orders and paginates posts based on GET parameters.
Post listing. Filters, orders and paginates posts based on GET parameters.
Post listing . Filters orders and paginates posts based on GET parameters .
def post_list(request, topic=None, tag="", cutoff=None, ordering=None):
    """
    Post listing. Filters, orders and paginates posts based on GET parameters.
    """

    # Parse the GET parameters for filtering information
    page = request.GET.get('page', 1)
    order = request.GET.get("order", ordering) or 'rank'
    topic = topic or request.GET.get("type", LATEST) or LATEST
    limit = request.GET.get("limit", "all") or "all"

    if tag:
        # Get all open top level posts.
        posts = Post.objects.filter(is_toplevel=True, status=Post.OPEN, tags__name__iexact=tag)
        cache_key = ''
    else:
        # Get posts available to users.
        posts = get_posts(request=request, topic=topic)
        # Create the cache key only with latest topic
        cache_key = f"{LATEST}-{order}-{limit}" if topic is LATEST else ''

    posts = apply_sort(posts, limit=limit, order=order)

    # Institute a cutoff
    if cutoff:
        posts = posts[:cutoff]

    # Filter for any empty strings
    paginator = CachedPaginator(cache_key=cache_key, object_list=posts, per_page=settings.POSTS_PER_PAGE)

    # Apply the post paging.
    posts = paginator.get_page(page)

    return posts
def post_list ( request , topic = None , tag = "" , cutoff = None , ordering = None ) : # Parse the GET parameters for filtering information page = request . GET . get ( 'page' , 1 ) order = request . GET . get ( "order" , ordering ) or 'rank' topic = topic or request . GET . get ( "type" , LATEST ) or LATEST limit = request . GET . get ( "limit" , "all" ) or "all" if tag : # Get all open top level posts. posts = Post . objects . filter ( is_toplevel = True , status = Post . OPEN , tags__name__iexact = tag ) cache_key = '' else : # Get posts available to users. posts = get_posts ( request = request , topic = topic ) # Create the cache key only with latest topic cache_key = f"{LATEST}-{order}-{limit}" if topic is LATEST else '' posts = apply_sort ( posts , limit = limit , order = order ) # Institute a cutoff if cutoff : posts = posts [ : cutoff ] # Filter for any empty strings paginator = CachedPaginator ( cache_key = cache_key , object_list = posts , per_page = settings . POSTS_PER_PAGE ) # Apply the post paging. posts = paginator . get_page ( page ) return posts