Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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')