Пример #1
0
def all_buying_posts(request, num_items, sorting):
    """
    This view returns JSON data for all postings for buying
    """
    postings = Posting.objects.all().filter(is_selling=False).filter(is_open=True)  # List of posts that are for buying
    postings = sort_posts(request, sorting, postings)
    response_list = return_posts(request, num_items, postings)
    return HttpResponse(json.dumps(response_list), content_type="application/json")
Пример #2
0
def hashtag_buying_posts(request, hashtag_id, num_items, sorting):
    """
    This view gets all buying posts under the hashtag identified by hashtag_id
    """
    try:
        hashtag = Hashtag.objects.get(pk=hashtag_id)
    except Hashtag.DoesNotExist:
        raise Http404
    else:
        hashtag_post_list = hashtag.posting_set.all().filter(is_selling=False).filter(is_open=True)
        hashtag_post_list = sort_posts(request, sorting, hashtag_post_list)
        response_list = return_posts(request, num_items, hashtag_post_list)
        return HttpResponse(json.dumps(response_list), content_type="application/json")
Пример #3
0
def category_selling_posts(request, category_id, num_items, sorting):
    """
    This view gets all selling posts under the category identified by category_id
    """
    try:
        category = Category.objects.get(pk=category_id)
    except Category.DoesNotExist:
        raise Http404
    else:
        category_post_list = category.posting_set.all().filter(is_selling=True).filter(is_open=True)
        category_post_list = sort_posts(request, sorting, category_post_list)
        response_list = return_posts(request, num_items, category_post_list)
        return HttpResponse(json.dumps(response_list), content_type="application/json")
Пример #4
0
def my_responded_posts(request, num_items, sorting):
    """
    This view returns JSON data for all postings that the logged user 
    has responded to.
    """
    # Get the currently-signed-in user
    user = request.user

    #If the user is authenticated, then display categories
    if user.is_authenticated():
        my_responded_list = user.responder.all().order_by('-date_posted') #List of posts I've responded to
        my_responded_list = sort_posts(request, sorting, my_responded_list)
        response_list = return_posts(request, num_items, my_responded_list)
        return HttpResponse(json.dumps(response_list), content_type="application/json")
Пример #5
0
def my_locked_posts(request, num_items, sorting):
    """
    This view returns JSON data for all postings created by the current user 
    that was responded to. Ordered by date.
    """
    # Get the currently-signed-in user
    user = request.user

    #If the user is authenticated, then display categories
    if user.is_authenticated():
        my_author_list = user.author.all().filter(is_open=False) #List of posts I've authored that have been responded to
        my_author_list = sort_posts(request, sorting, my_author_list)
        response_list = return_posts(request, num_items, my_author_list)
        return HttpResponse(json.dumps(response_list), content_type="application/json")