コード例 #1
0
ファイル: views.py プロジェクト: kumaran-5555/Phoenix
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)}))
コード例 #2
0
ファイル: views.py プロジェクト: kumaran-5555/Phoenix
def logout(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, ''))

    Helpers.delete_seller_session(request)

    return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.Success, 'logged out'))
コード例 #3
0
ファイル: views.py プロジェクト: kumaran-5555/Phoenix
def delete_offerings(request):

    if request.method != 'POST':
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.NotPostRequest, ''))

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

    categoryIdList = request.POST.get('categoryIdList', False)
    productIdList = request.POST.get('productIdList', False)
    brandIdList = request.POST.get('brandIdList', False)
    seller = request.session['sellerId']


    if not categoryIdList and not productIdList and not brandIdList:
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidOfferingParams, ''))

    catIdList = []
    cContents = categoryIdList.split(',')

    for c in cContents :
        try:
            catIdList.append(int(c))
        except ValueError:
            return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidCategoryIdList, categoryIdList))

    prodIdList = []
    pContents = productIdList.split(',')

    for p in pContents:
        try:
            prodIdList.append(int(p))
        except ValueError:
            return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidProductIdList, productIdList))


    branIdList = []
    bContents = brandIdList.split(',')

    for p in bContents:
        try:
            branIdList.append(int(p))
        except ValueError:
            return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidBrandIdList, brandIdList))




    for c in catIdList :
        # validate existence

        try:
            row = Product.models.CategoryTaxonomy.objects.get(id=c)
        except ObjectDoesNotExist:
            return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidCategoryIdList, c))

        # if categoryId exists, delete
        sentinel = Bargain.models.MessageRouter.objects.filter(sellerId = seller.id, productSelectionId = c, productSelectionType = Helpers.Constants.SelectionType.Category).delete()
        


    for p in prodIdList :
        try:
            row = Product.models.Products.objects.get(id=p)
        except ObjectDoesNotExist:
            return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidProductIdList, p))

        # if categoryId already exists, skip
        sentinel = Bargain.models.MessageRouter.objects.filter(sellerId = seller.id, productSelectionId = p, productSelectionType = Helpers.Constants.SelectionType.Product).delete()

    for b in branIdList:
        try:
            row = Product.models.ProductBrands.objects.get(id=b)
        except ObjectDoesNotExist:
            return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidBrandIdList, b))


        # if categoryId already exists, skip
        sentinel = Bargain.models.MessageRouter.objects.filter(sellerId = seller.id, productSelectionId = b, productSelectionType = Helpers.Constants.SelectionType.Brand).delete()
       

    return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.Success, 'Deleted!'))
コード例 #4
0
ファイル: views.py プロジェクト: kumaran-5555/Phoenix
def reply(request):
    if request.method != 'POST':
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.NotPostRequest, ''))

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


    seller = request.session['sellerId']
    
    messageId = request.POST.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}))

    message = request.POST.get('message', False)

    if not message or not Helpers.validateMessage(message):
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidBargainMessage, message))
    

    toId = request.POST.get('toId', False)

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

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

    try:
        messageObj = Bargain.models.MessageBox.objects.get(id=messageId)

    except ObjectDoesNotExist:
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InactiveMessage, {'messageId': messageId}))



    if messageObj.userId != toId:
        return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.InvalidToid, {'messageId': toId}))

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


    

    shortMessage = Helpers.shortenMessage(message)

    # update message details
    messageObj.numOfResponses += 1
    messageObj.recentResponse = shortMessage


    messageObj.save()


    # create threads
    Bargain.models.MessageBoxThreads.objects.create(messageId = messageObj, fromId = seller.id, toId = toId, message=message)

    Bargain.models.NotificationsQueue.objects.create(appId=messageObj.userAppId, shortMessage=shortMessage)
 

    return HttpResponse(Helpers.create_json_output(Helpers.StatusCodes.Success, 'Replied!'))