def create_hotspot(user, latitude, longitude, address, description, time, invite_list, user_latitude=None, user_longitude=None): beacon = Beacon(creator=user, description=description, time=time, private=False, longitude=longitude, latitude=latitude, address=address) beacon.save() creatorIsGoing = BeaconFollow(user=user, beacon=beacon, state=BEACON_FOLLOW_STATUS.GOING) if user_latitude: distance = distance_between_two_points(latitude, longitude, user_latitude, user_longitude) dt = abs(datetime.now() - time).total_seconds() if distance < 0.2 and dt < 60 * 15: creatorIsGoing.state = BEACON_FOLLOW_STATUS.HERE creatorIsGoing.save() user_list, contact_list = parse_json_into_users_and_contact_lists( user, invite_list) numberOfFriends = len(user_list) + len(contact_list) if numberOfFriends > 0: send_sms_invites(user, beacon, user_list, contact_list) chat_message1, avatar_url1 = set_hotspot_message(user) chat_message2, avatar_url2 = invite_friends_message( user, numberOfFriends) create_hotspot_message_in_chat(beacon, chat_message1, user, None, avatar_url1) create_hotspot_message_in_chat(beacon, chat_message2, user, None, avatar_url2) else: chat_message, avatar_url = set_hotspot_message(user) create_hotspot_message_in_chat(beacon, chat_message, user, None, avatar_url) hotspot_with_extra_properties = add_extra_hotspot_properties(beacon) scheduler.enqueue_at(beacon.time, send_push_to_wakeup_users, user_list) scheduler.enqueue_at(beacon.time + timedelta(hours=1), send_push_to_wakeup_users, user_list) scheduler.enqueue_at(beacon.time + timedelta(hours=2), send_push_to_wakeup_users, user_list) if (beacon.time - datetime.now()).total_seconds() > 60 * 60 * 2: scheduler.enqueue_at(beacon.time - timedelta(minutes=15), send_reminder, beacon) return hotspot_with_extra_properties
def get_list_with_user_hotspot(user): hotspot_list = [] hotspot = get_user_hotspot(user) if not is_hotspot_expired(hotspot): updatedHotspot = add_extra_hotspot_properties(hotspot) hotspot_list.append(updatedHotspot) return hotspot_list
def change_hotspot(user, request_data): if not ('beacon_id' in request_data): return False beacon = Beacon.objects.get(pk=request_data['beacon_id']) if 'cancelled' in request_data: changed_beacon = cancel_hotspot(user, beacon) else: changed_beacon = update_hotspot(user, beacon, request_data) hotspot_with_extra_properties = add_extra_hotspot_properties( changed_beacon) return hotspot_with_extra_properties
def get_hotspot_list(user): hotspot_list = [] yesterday = datetime.now() - timedelta(days=1) hotspot_invites = BeaconFollow.objects.filter( user=user, beacon__cancelled=False, beacon__time__gte=yesterday).select_related('beacon') for follow in hotspot_invites: hotspot = follow.beacon if not is_hotspot_expired(hotspot): updated_hotspot = add_extra_hotspot_properties(hotspot) hotspot_list.append(updated_hotspot) return hotspot_list
def get(self, request, format=None): response = {} auth_token = request.auth if str(auth_token) == settings.MOBILE_VIEW_TOKEN: status_id = int(request.QUERY_PARAMS['deal_status_id']) # status_id = simple_int_hash(status_id) deal_status = DealStatus.objects.select_related( 'deal', 'beacon').get(pk=status_id) beacon = add_extra_hotspot_properties(deal_status.beacon) response['beacon'] = BeaconWithDealStatusSerializer(beacon).data response['contact_deal_status'] = DealStatusSerializer( deal_status).data return Response(response, status=status.HTTP_200_OK)
def post(self, request, format=None): response = {} user = Token.objects.get(key=request.auth).user isDeal = bool(int(request.DATA['is_deal'])) if isDeal: deal, beacon = check_in_for_deal(user, request.DATA) beacon = add_extra_hotspot_properties(beacon) beacon.deal = deal serializer = BeaconWithDealStatusSerializer(beacon) response['beacon'] = serializer.data else: response['beacon'] = check_in_for_happy_hour(user, request.DATA) return Response(response, status=status.HTTP_200_OK)
def post(self, request, format=None): response = {} user = Token.objects.get(key=request.auth).user print str(request.DATA) deal, beacon, tab, tab_items = check_in_for_venue(user, request.DATA) beacon = add_extra_hotspot_properties(beacon) beacon.deal = deal serializer = BeaconWithDealStatusSerializer(beacon) response['beacon'] = serializer.data if tab: response['tab_items'] = TabItemSerializer(tab_items, many=True).data response['tab'] = TabSerializer(tab).data return Response(response, status=status.HTTP_200_OK)
def post(self, request, format=None): response = {} user = Token.objects.get(key=request.auth).user invite_list = request.DATA.getlist('invite_list[]') deal_id = request.DATA['deal_id'] timestamp = float(request.DATA['time']) image_url = get_image_url(request.DATA) print "Timestamp: " + str(timestamp) custom_message = request.DATA.get('custom_message') deal, beacon = apply_for_deal(user, deal_id, timestamp, invite_list, custom_message, image_url) beacon = add_extra_hotspot_properties(beacon) beacon.deal = deal serializer = BeaconWithDealStatusSerializer(beacon) response['beacon'] = serializer.data return Response(response, status=status.HTTP_200_OK)
def get_hotspot(beacon_id): beacon = Beacon.objects.get(pk=beacon_id) hotspotWithExtraProperties = add_extra_hotspot_properties(beacon) return hotspotWithExtraProperties