Esempio n. 1
0
def view_details(request):
    if request.method != 'GET':
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.NotGetRequest, ''))


    if not Helpers.validate_user_session(request):
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidUserSession, ''))

    userId = request.session.get('userId').id

    messageId = request.GET.get('messageId', False)

    if not messageId:
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidMessageId, {'messageId': messageId}))


    try:
        messageId = int(messageId)
    except valueError:
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidMessageId, {'messageId': messageId}))



    # we already have head message, only has to retrive response

    messages = Bargain.models.MessageBoxThreads.objects.filter(Q(messageId=messageId) & (Q(toId=userId) | Q(fromId=userId))).order_by('timestamp').reverse()

    return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.Success, { 'messages': Helpers.jsonizeDjangoObject(messages)}))
Esempio n. 2
0
def seller_view_details(request):
    if request.method != 'GET':
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.NotGetRequest, ''))


    if not Helpers.validate_seller_session(request):
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidSellerSession, ''))

    sellerId = request.session['sellerId'].id

   

    skip = request.GET.get('skip', False)

    if not skip:
        skip = 0

    else:
        try:
            skip = int(skip)
        except ValueError:
            skip = 0



    # we already have head message, only has to retrive response

    messages = Bargain.models.MessageBoxThreads.objects.filter((Q(toId=sellerId) | Q(fromId=sellerId))).order_by('timestamp').reverse()[skip:skip+20]

    return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.Success, { 'messages': Helpers.jsonizeDjangoObject(messages)}))
Esempio n. 3
0
def view_summary(request):
    if request.method != 'GET':
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.NotGetRequest, ''))


    if not Helpers.validate_user_session(request):
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidUserSession, ''))

    userId = request.session.get('userId').id

    messages = Bargain.models.MessageBox.objects.filter(userId=userId).order_by('recentResponseTimestamp').reverse()


    skip = request.GET.get('skip', False)

    if not skip:
        skip = 0

    else:
        try:
            skip = int(skip)
        except ValueError:
            skip = 0

    return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.Success, {'messages' : Helpers.jsonizeDjangoObject(messages[skip: skip + Helpers.Constants.numMesssagesToReturn])}))