def post(self, request, format=None): response = {} default_deal, recurring_deal = add_deal(request.DATA) response['default_deal'] = DealSerializer(default_deal, many=True).data response['recurring_deal'] = DealSerializer(recurring_deal, many=True).data return Response(response, status=status.HTTP_200_OK)
def post(self, request, format=None): response = {} response[ 'merchant_token'], default_deal, recurring_deal = login_merchant_user( request.DATA) if default_deal is not None: response['default_deal'] = DealSerializer(default_deal).data response['recurring_deal'] = DealSerializer(recurring_deal).data else: response['message'] = "Your email or password is incorrect" return Response(response, status=status.HTTP_200_OK)
def get(self, request, format=None): response = {} auth_token = request.auth token = Token.objects.get(key=auth_token) latitude = float(request.QUERY_PARAMS['latitude']) longitude = float(request.QUERY_PARAMS['longitude']) unlocked_deals, locked_deals = get_nearby_rewards( token.user, latitude, longitude) response['unlocked_deals'] = DealSerializer(unlocked_deals, many=True).data response['locked_deals'] = DealSerializer(locked_deals, many=True).data return Response(response, status=status.HTTP_200_OK)
def get(self, request, format=None): response = {} auth_token = request.auth if Token.objects.filter(key=auth_token).exists(): token = Token.objects.get(key=auth_token) default_deal, recurring_deal = get_merchant_deals( token.user.profile.deal_place) response['default_deal'] = DealSerializer(default_deal, many=True).data response['recurring_deal'] = DealSerializer(recurring_deal, many=True).data return Response(response, status=status.HTTP_200_OK) else: return Response(response, status=status.HTTP_401_UNAUTHORIZED)
def post(self, request, format=None): response = {} data = request.DATA auth_token = request.auth token = Token.objects.get(key=auth_token) deal_id = int(data['deal_id']) region_state = data['region_state'] region_type = data['region_type'] print "Deal ID for Region State: " + str(deal_id) if Deal.objects.filter(pk=deal_id).exists(): deal = Deal.objects.get(pk=deal_id) show_notification = deal.active #get region states in last day past_states = RegionState.objects.filter( user=token.user, place=deal.place, showed_notification=True, date_created__gte=datetime.now() - timedelta(hours=12)) if past_states.exists(): show_notification = False deal_hours = deal_hours_for_datetime(deal, datetime.now()) if not deal_hours: show_notification = False region_state = RegionState.objects.create( user=token.user, place=deal.place, region_state=region_state, region_type=region_type, showed_notification=show_notification) response['deals'] = DealSerializer(deal).data response['show_notification'] = show_notification return Response(response, status=status.HTTP_200_OK)
def get(self, request, format=None): response = {} auth_token = request.auth token = Token.objects.get(key=auth_token) latitude = float(request.QUERY_PARAMS['latitude']) longitude = float(request.QUERY_PARAMS['longitude']) if 'radius' in request.QUERY_PARAMS: radius = float(request.QUERY_PARAMS['radius']) if radius > 1.6: radius = 1.6 else: radius = 1.6 print "Radius: " + str(radius) set_location(token.user, latitude, longitude) t0 = time.time() deals = nearby_deals(token.user, latitude, longitude, radius) print "DEALS: " + str(deals) t1 = time.time() happy_hours = nearby_happy_hours(token.user, latitude, longitude, radius) print "HAPPY HOURS: " + str(happy_hours) t2 = time.time() print "Nearby Deals: " + str(t1 - t0) print "Nearby Happy Hours: " + str(t2 - t1) # unlocked_deals, locked_deals = get_nearby_rewards(token.user, latitude, longitude) response['deals'] = DealSerializer(deals, many=True).data response['happy_hours'] = HappyHourSerializer(happy_hours, many=True).data response[ 'number_of_reward_items'] = token.user.profile.number_of_reward_items # response['unlocked_rewards'] = DealSerializer(unlocked_deals, many=True).data # response['locked_rewards'] = DealSerializer(locked_deals, many=True).data return Response(response, status=status.HTTP_200_OK)
def delete(self, request, format=None): response = {} default_deal, recurring_deal = deactivate_deal(request.DATA) response['default_deal'] = DealSerializer(default_deal).data response['recurring_deal'] = DealSerializer(recurring_deal).data return Response(response, status=status.HTTP_200_OK)
def get(self, request, format=None): response = {} deal_id = int(request.QUERY_PARAMS['deal_id']) deal = Deal.objects.get(pk=deal_id) response['deals'] = DealSerializer(deal).data return Response(response, status=status.HTTP_200_OK)