def get_suggestions(request): result = check_input(request, ["page", "userId"]) if result['result'] == "Error": return JsonResponse(result) try: items = Recommendations.get_page(request['userId'], request['page']) number_of_pages = Recommendations.get_number_of_pages( request['userId']) except Exception as e: print e return JsonResponse({ 'result': 'Error', 'message': 'error during getting list' }) if items: request = { 'result': 'Success', 'data': { 'items': items, "numberOfPages": number_of_pages } } elif items == []: request = {'result': 'Error', 'message': 'page out of range'} else: request = {'result': 'Error', 'message': 'error during getting list'} return JsonResponse(request)
def make_list(request): result = check_input(request, ["userId"], ["filter"]) if result['result'] == "Error": return JsonResponse(result) if 'filter' in request: result = check_input(request['filter'], [], ["minPrice", "maxPrice"]) if result['result'] == "Error": return JsonResponse(result) min_price = None max_price = None if 'filter' in request: if 'minPrice' in request['filter']: min_price = request['filter']['minPrice'] if 'maxPrice' in request['filter']: max_price = request['filter']['maxPrice'] try: Recommendations.generate_list(request['userId'], min_price, max_price) number_of_pages = Recommendations.get_number_of_pages( request['userId']) except Exception as e: print e return JsonResponse({ 'result': 'error', 'message': 'error while making list' }) return JsonResponse({ 'result': 'Success', 'data': { 'numberOfPages': number_of_pages } })
def rate_item(request): result = check_input(request, ["userId", "itemId", "rating"]) if result['result'] == "Error": return JsonResponse(result) try: Recommendations.rate_and_remove(request['userId'], request['itemId'], request['rating']) number_of_pages = Recommendations.get_number_of_pages(request['userId']) except Exception as e: print e return JsonResponse({"result": "Error", "message": "error during rating item"}) return JsonResponse({"result": "Success", 'data': {'numberOfPages': number_of_pages}})
def get_suggestions(request): result = check_input(request, ["page", "userId"]) if result['result'] == "Error": return JsonResponse(result) try: items = Recommendations.get_page(request['userId'], request['page']) number_of_pages = Recommendations.get_number_of_pages(request['userId']) except Exception as e: print e return JsonResponse({'result': 'Error', 'message': 'error during getting list'}) if items: request = {'result': 'Success', 'data': {'items': items, "numberOfPages": number_of_pages}} elif items == []: request = {'result': 'Error', 'message': 'page out of range'} else: request = {'result': 'Error', 'message': 'error during getting list'} return JsonResponse(request)
def rate_item(request): result = check_input(request, ["userId", "itemId", "rating"]) if result['result'] == "Error": return JsonResponse(result) try: Recommendations.rate_and_remove(request['userId'], request['itemId'], request['rating']) number_of_pages = Recommendations.get_number_of_pages( request['userId']) except Exception as e: print e return JsonResponse({ "result": "Error", "message": "error during rating item" }) return JsonResponse({ "result": "Success", 'data': { 'numberOfPages': number_of_pages } })
def make_list(request): result = check_input(request, ["userId"], ["filter"]) if result['result'] == "Error": return JsonResponse(result) if 'filter' in request: result = check_input(request['filter'], [], ["minPrice", "maxPrice"]) if result['result'] == "Error": return JsonResponse(result) min_price = None max_price = None if 'filter' in request: if 'minPrice' in request['filter']: min_price = request['filter']['minPrice'] if 'maxPrice' in request['filter']: max_price = request['filter']['maxPrice'] try: Recommendations.generate_list(request['userId'], min_price, max_price) number_of_pages = Recommendations.get_number_of_pages(request['userId']) except Exception as e: print e return JsonResponse({'result': 'error', 'message': 'error while making list'}) return JsonResponse({'result': 'Success', 'data': {'numberOfPages': number_of_pages}})