def update_current_position(request): # print request.POST # <QueryDict: {u'lat': [u'37.7082051'], u'lng': [u'-122.4433762']}> # print request.POST['lat'] # print request.POST['lng'] user = request.user current_position = Location() current_position.lat = request.POST['lat'] current_position.lng = request.POST['lng'] current_position.save() print "current position: " print current_position.lat print current_position.lng print "=================" user.current_position = current_position user.save() msg = "Updated current position" if user.is_valet: print 'updated valet position' return Response(msg, template_name='maps/valet/index.html') else: print 'updated customer position' return Response(msg, template_name='maps/user/index.html')
def valet_drops_vehicle_at_new_location(request): if request.method == "POST": dropoff_location = Location() dropoff_location.lat = request.POST['lat'] dropoff_location.lng = request.POST['lng'] dropoff_location.full_address = request.POST['address'] dropoff_location.save() if 'repark_id' in request.session: repark = Repark.objects.get(id=request.session["repark_id"]) repark.dropoff_location = dropoff_location repark.dropped_off_at = local_time_now repark.save() serializer = ReparkSerializer(repark) # what to do if the request is a Dropoff if 'dropoff_id' in request.session: dropoff = Dropoff.objects.get(id=request.session["dropoff_id"]) dropoff.dropoff_location = dropoff_location dropoff.dropped_off_at = local_time_now dropoff.save() serializer = DropoffSerializer(dropoff) data = serializer.data return Response(data, template_name='maps/valet/index.html')
def zapis(): hovno = find() print hovno for h in hovno: location = Location() location.name = h[0] location.lat = h[1] location.lng = h[2] location.address = h[3] location.category = '4d4b7105d754a06374d81259' location.save() print "Created"
def valet_accepts_request(request): if request.method == "POST": valet = request.user valet_starting_position = Location() valet_starting_position.lat = request.POST['lat'] valet_starting_position.lng = request.POST['lng'] valet_starting_position.save() # have to take into account if the request is a Dropoff if request.POST['repark_id']: repark = Repark.objects.get(id=request.POST['repark_id']) repark.reparked_by = valet repark.in_progress = True repark.valet_start_pos = valet_starting_position repark.save() # set a 'repark_id' session for the valet request.session["repark_id"] = repark.id serializer = ReparkSerializer(repark) if request.POST['dropoff_id']: dropoff = Dropoff.objects.get(id=request.POST['dropoff_id']) customer = dropoff.requested_by # grab the last repark request's dropoff location latest_repark_request = customer.orders_repark_customer_related.latest('completed_at') dropoff.reparked_by = valet dropoff.in_progress = True dropoff.valet_start_pos = valet_starting_position # valet picks up car at user's last repark request's dropoff_location dropoff.pickup_location = latest_repark_request.dropoff_location dropoff.save() request.session["dropoff_id"] = dropoff.id serializer = DropoffSerializer(dropoff) # if request.POST['scheduled_repark_id']: # scheduled_repark = ScheduledRepark.objects.get(id=request.POST['scheduled_repark_id']) # scheduled_repark.reparked_by = valet # scheduled_repark.save() # add this object to a queue here??? data = serializer.data return Response(data, template_name='maps/valet/index.html')
def customer_submits_valet_request(request, format=None): customer = request.user request.session['customer_id'] = customer.id if request.method == "POST": form = OrderForm(request.POST) if form.is_valid(): print request.POST # users current position location = Location() location.lat = request.POST['lat'] location.lng = request.POST['lng'] location.full_address = request.POST['address'] location.save() if request.POST['is_repark']: # create Repark instancee repark = Repark() repark.requested_by = customer repark.pickup_location = location repark.requested_at = local_time_now repark.save() request.session["repark_id"] = repark.id serializer = ReparkSerializer(repark) if request.POST['is_dropoff']: # retrieve latest request last_request = customer.orders_repark_customer_related.latest('completed_at') # create Dropoff instance dropoff = Dropoff() dropoff.requested_by = customer # vehicle pickup location is the last request's dropoff location dropoff.pickup_location = last_request.dropoff_location # vehicle dropoff location is location of user's current position dropoff.dropoff_location = location dropoff.requested_at = local_time_now dropoff.save() request.session["dropoff_id"] = dropoff.id serializer = DropoffSerializer(dropoff) if request.POST['is_scheduled_repark']: scheduled_repark = ScheduledRepark() scheduled_repark.requested_by = customer scheduled_repark.pickup_location = location scheduled_repark.scheduled_start_date = request.POST['scheduled_start_date'] scheduled_repark.scheduled_end_date = request.POST['scheduled_end_date'] scheduled_repark.time_limit = request.POST['time_limit'] scheduled_repark.requested_at = local_time_now """ Calculate the expiration time based on when user requested repark """ parking_exp_time = local_time_now + datetime.timedelta(hours=int(scheduled_repark.time_limit)) scheduled_repark.parking_exp_time = parking_exp_time scheduled_repark.save() request.session["scheduled_repark_id"] = scheduled_repark.id serializer = ScheduledReparkSerializer(scheduled_repark) # send repark to celery task queue # eta should be 30 to 45 mins before parking_exp_time # tasks.query_valets.apply_async((scheduled_repark.id,), link=tasks.match_valet_with_repark.s(scheduled_repark.id)) tasks.match_valet_with_repark.apply_async(scheduled_repark.id, countdown=60) data = serializer.data print(data) return Response(data, template_name='maps/user/index.html')
def customer_submits_valet_request(request, format=None): customer = request.user request.session['customer_id'] = customer.id if request.method == "POST": print request.POST # users current position location = Location() location.lat = request.POST['lat'] location.lng = request.POST['lng'] try: location.full_address = request.POST['full_address'] except: pass location.save() if request.POST['is_repark']: # create Repark instance repark = Repark() repark.requested_by = customer repark.requested_at = local_time_now repark.pickup_location = location repark.save() request.session["repark_id"] = repark.id serializer = ReparkSerializer(repark) if request.POST['is_dropoff']: # retrieve latest request last_request = customer.orders_repark_customer_related.latest('completed_at') # create Dropoff instance dropoff = Dropoff() dropoff.requested_by = customer dropoff.requested_at = local_time_now # vehicle pickup location is the last request's dropoff location dropoff.pickup_location = last_request.dropoff_location # vehicle dropoff location is location of user's current position dropoff.dropoff_location = location dropoff.save() request.session["dropoff_id"] = dropoff.id serializer = DropoffSerializer(dropoff) if request.POST['is_scheduled_repark']: scheduled_repark = ScheduledRepark() scheduled_repark.requested_by = customer scheduled_repark.requested_at = local_time_now scheduled_repark.pickup_location = location scheduled_repark.scheduled_start_date = request.POST['scheduled_start_date'] scheduled_repark.scheduled_end_date = request.POST['scheduled_end_date'] scheduled_repark.time_limit = request.POST['time_limit'] """ Calculate the expiration time based on when user requested repark """ # parking_exp_time = local_time_now + request.POST['time_limit'] # scheduled_repark.parking_exp_time = parking_exp_time scheduled_repark.save() request.session["scheduled_repark_id"] = scheduled_repark.id serializer = ScheduledRepark(scheduled_repark) data = serializer.data print(data) return Response(data, template_name='maps/user/index.html')