def connect_people(request): up = request.user.userprofile inviter_id, event_id = parse_request(request, ['inviterId', 'eventId']) inviter = UserProfile.objects.get(id=inviter_id) ur_related, related_created = UserRelations.objects.get_or_create( relating_user=up, related_user=inviter, state=UserRelations.STATE_CONNECTED) ur_relating, relating_created = UserRelations.objects.get_or_create( related_user=up, relating_user=inviter, state=UserRelations.STATE_CONNECTED) ur_related.meta_data['event_ids'] = list( set(ur_related.meta_data.get('event_ids', []) + [event_id])) ur_relating.meta_data['event_ids'] = list( set(ur_relating.meta_data.get('event_ids', []) + [event_id])) ur_related.save() ur_relating.save() return JsonResponse({ 'status': CONNECT_PEOPLE_RESPONSE_SUCCESS if related_created else CONNECT_PEOPLE_RESPONSE_ALREADY_CONNECTED, 'inviterName': inviter.user.first_name })
def add_swipe_action(request): event_id, action, lat, lng = parse_request( request, ['eventId', 'action', 'lat', 'lng']) UserSwipeAction.objects.create(user=request.user.userprofile, event_id=event_id, action=action, action_time=timezone.now(), lat=lat, lng=lng) return HttpResponse()
def sign_in_with_facebook(request): fb_user_id, access_token = parse_request(request, ['userId', 'accessToken']) up = request.user.userprofile logger.debug('up: ' + up.user.username + ', fb_user_id: ' + str(fb_user_id) + ', access_token: ' + str(access_token)) up.fb_id = fb_user_id up.fb_access_token = access_token up.save() update_user_fb_data(up) up_json = up_to_json(up, request) return JsonResponse(up_json)
def update_user_profile(request): lang_code, categories_ids = parse_request(request, ['langCode'], lists=['categoriesIds']) up = UserProfile.objects.get(user=request.user) if categories_ids: up.preferred_categories.clear() up.preferred_categories.add(*categories_ids) if lang_code: up.preferred_language = lang_code up.save() up_json = up_to_json(up, request) return JsonResponse(up_json)
def sign_in(request): username, device_info, lang_code, categories_ids = parse_request( request, ['username', 'deviceInfo', 'langCode'], ['categoriesIds']) device_info = json.loads(device_info) user, created = User.objects.get_or_create(username=username) up, up_created = UserProfile.objects.get_or_create(user=user) if up_created: up.preferred_language = lang_code up.save() print('user created: username - ' + up.user.username) else: print('user signed in: username - ' + up.user.username) user = authenticate(username=username) login(request, user) if categories_ids: up.preferred_categories.clear() up.preferred_categories.add(*categories_ids) update_device_info(up, device_info) up_json = up_to_json(up, request) return JsonResponse(up_json)
def get_events(request): top_event_id, user_lng, user_lat = parse_request( request, ['topEventId', 'lng', 'lat']) up = request.user.userprofile ref_location = Point(float(user_lng), float(user_lat), srid=4326) valid = Q(title__isnull=False, enabled=True) # , start_time__gte=timezone.now()) events = Event.objects.filter(id__gte=318).filter(valid).filter( categories__in=up.preferred_categories.values_list( 'id', flat=True)).annotate(distance=Distance( 'venue__location', ref_location)).order_by('distance') if top_event_id and top_event_id != '-1': top_event = Event.objects.filter(id=top_event_id).annotate( distance=Distance('venue__location', ref_location)) events = events.exclude(id=top_event_id)[:EVENTS_PAGE_SIZE - 1] events = list(top_event) + list(events) else: events = events[:EVENTS_PAGE_SIZE] events_json = _events_to_json(request, events, up) return JsonResponse(events_json, safe=False)
def add_user_message(request): up = request.user.userprofile type, name, email, phone, text, lat, lng = parse_request( request, ['type', 'name', 'email', 'phone', 'text', 'lng', 'lat']) um = UserMessage.objects.create(user=up, type=type, name=name, email=email, phone=phone, text=text, lat=lat, lng=lng) email = EmailMessage( 'New User Message Received (' + UserMessage.MESSAGE_TYPE_CHOICES.get(int(um.type)) + '):', _format_user_message_email(um), '*****@*****.**', ['*****@*****.**'], ) email.send() return HttpResponse()
def get_user_selected_events(request): page, user_lng, user_lat, categories_ids = parse_request( request, ['page', 'lng', 'lat'], ['categoriesIds']) page = int(page) up = request.user.userprofile swipe_right_actions = UserSwipeAction.objects.filter( user=request.user.userprofile, action=UserSwipeAction.ACTION_RIGHT) selected_events_ids = swipe_right_actions.values_list('event', flat=True) ref_location = Point(float(user_lng), float(user_lat), srid=4326) selected_events = Event.objects.filter(id__in=selected_events_ids).filter( id__gte=318) if categories_ids: selected_events = selected_events.filter(categories__in=categories_ids) selected_events = selected_events.annotate(distance=Distance( 'venue__location', ref_location)).order_by('distance') if categories_ids: selected_events = selected_events.filter(categories_ids) events_json = _events_to_json( request, selected_events[page * USER_EVENTS_PAGE_SIZE:(page + 1) * USER_EVENTS_PAGE_SIZE], up) return JsonResponse(events_json, safe=False)