Exemplo n.º 1
0
	def clean_destination_address(self):
		destination_address = self.clean_data['destination_address']

		if not GoogleMaps.is_valid_address(destination_address):
			raise forms.ValidationError("Please enter a valid address.")

		return destination_address
Exemplo n.º 2
0
	def get_destination(self):
		destination_address = self.clean_data['destination_address']

		if GoogleMaps.is_valid_address(destination_address):
			return Location.get_by_address(destination_address, create=True)
		else:
			return None
Exemplo n.º 3
0
	def get_source(self):
		source_address = self.clean_data['source_address']

		if GoogleMaps.is_valid_address(source_address):
			return Location.get_by_address(source_address, create=True)
		else:
			return None
Exemplo n.º 4
0
	def clean_source_address(self):
		source_address = self.clean_data['source_address']

		if not GoogleMaps.is_valid_address(source_address):
			raise forms.ValidationError("Please enter a valid address.")

		return source_address
Exemplo n.º 5
0
	def get(self):
		## --------------------------------------------------------------------
		# Retrive Session Info and Request Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		# Request Values
		max_results = self.get_request_parameter('maxresults', converter=int, default=20)

		# Get Datastore Values
		rides = Ride.all() #TODO this will need to be > now(), i.e. only future instances

		# --------------------------------------------------------------------
		# Generate Template Values
		# --------------------------------------------------------------------
		template_values = super(BrowseRidePageHandler, self
			).generate_template_values(self.request.url)

		template_values['rides'] = list(rides)
		template_values['key'] = GoogleMaps.get_key()
		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "browse_rides.html")
		self.response.out.write(template.render(page_path, template_values))
Exemplo n.º 6
0
	def clean_destination_address(self):
		destination_address = self.clean_data['destination_address']

		if not GoogleMaps.is_valid_address(destination_address):
			raise forms.ValidationError("Google Maps was not able to locate your 'To' address.")

		return destination_address
Exemplo n.º 7
0
	def clean_source_address(self):
		source_address = self.clean_data['source_address']

		if not GoogleMaps.is_valid_address(source_address):
			raise forms.ValidationError("Google Maps was not able to locate your 'From' address.")

		return source_address
Exemplo n.º 8
0
	def post(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and GET Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return


		# Request Values
		riderequest_id = self.get_request_parameter('id', converter=int, default=None)

		# Datastore Values
		riderequest = RideRequest.get_by_id(riderequest_id)



		# --------------------------------------------------------------------
		# Validate Request
		# --------------------------------------------------------------------
		# if the target ride does not exist in the datastore, then redirect
		# the user back to the home page.
		if riderequest is None:
			self.error(404)
			return

		# --------------------------------------------------------------------
		# Generate and Store Template Values
		# --------------------------------------------------------------------
		template_values = super(ViewRideRequestPageHandler, self
			).generate_template_values(self.request.url)

		template_values['riderequest'] = riderequest
		template_values['googlemaps_key'] = GoogleMaps.get_key()
		template_values['message_list'] = list(riderequest.riderequestmessages.order('created'))

		#if user is cancelling the riderequest
		if self.request.POST.has_key('do_cancel_request') and (current_user == riderequest.owner):
			riderequest.delete() #delete the riderequest
			self.redirect("/browse_riderequests") # redirect to the browse riderequest page
			return

		#if user is posting a message
		if self.request.POST.has_key('do_post_message') and self.request.POST['do_post_message']:
			message = RideRequestMessage(author=current_user, riderequest=riderequest, title=escape(self.request.POST['message_title']), text=escape(self.request.POST['message_body']))
			message.put()

		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "riderequest_view.html")
		self.response.out.write(template.render(page_path, template_values))
Exemplo n.º 9
0
	def get_by_address(address, create):
		location = Location.all().filter('address=', address).get()

		# add the location to the database if it dosen't already exist
		if location is None and create:
			location = Location(
				address = address,
				geo_point = GoogleMaps.get_geo_point(address)
			)
		location.put()

		return location
Exemplo n.º 10
0
	def post(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and GET Data
		# --------------------------------------------------------------------
		# Request Values
		current_value = self.get_request_parameter('current_value', converter=str, default=None)

		# --------------------------------------------------------------------
		# Validate Request
		# --------------------------------------------------------------------
		if current_value is None:
			self.error(400)
			return
			
		# strip any numbers from the front of the test

		# --------------------------------------------------------------------
		# Generate and Store Template Values
		# --------------------------------------------------------------------
		template_values = super(LocationCompleterRequestHandler, self
			).generate_template_values(self.request.url)
		
		
		fetch_url = WISES_FETCH_URL + '?address=' + urllib.quote_plus(current_value) 
		
		closest_locations = []
		
		try:
			content = urlfetch.fetch(fetch_url).content
			query_content = simplejson.loads(content)
			
			if "results" in query_content:
				results = query_content['results']
				closest_locations = map(lambda x: x['full_address'], results)
				closest_locations = filter(lambda x: GoogleMaps.is_valid_address(x), closest_locations)
			
		except:
			self.error(500)
			return
		
		template_values['closest_locations'] = closest_locations

		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "location-completer.html")
		self.response.out.write(template.render(page_path, template_values))
Exemplo n.º 11
0
	def get(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and GET Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		# Request Values
		riderequest_id = self.get_request_parameter('id', converter=int, default=None)

		# Datastore Values
		riderequest = RideRequest.get_by_id(riderequest_id)

		# --------------------------------------------------------------------
		# Validate Request
		# --------------------------------------------------------------------
		# if the target ride does not exist in the datastore, then redirect
		# the user back to the home page.
		if riderequest is None:
			self.error(404)
			return

		# --------------------------------------------------------------------
		# Generate and Store Template Values
		# --------------------------------------------------------------------
		template_values = super(ViewRideRequestPageHandler, self
			).generate_template_values(self.request.url)

		template_values['riderequest'] = riderequest
		template_values['googlemaps_key'] = GoogleMaps.get_key()
		template_values['message_list'] = list(riderequest.riderequestmessages.order('created'))


		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "riderequest_view.html")
		self.response.out.write(template.render(page_path, template_values))
Exemplo n.º 12
0
	def post(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and GET Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return


		# Request Values
		ride_id = self.get_request_parameter('id', converter=int, default=None)

		# Datastore Values
		ride = Ride.get_by_id(ride_id)
		# --------------------------------------------------------------------
		# Validate Request
		# --------------------------------------------------------------------
		# if the target ride does not exist in the datastore, then redirect
		# the user back to the home page.
		if ride is None:
			self.error(404)
			return


		# --------------------------------------------------------------------
		# Generate and Store Template Values
		# --------------------------------------------------------------------
		template_values = super(ViewRidePageHandler, self
			).generate_template_values(self.request.url)

		template_values['ride'] = ride
		template_values['lat_lng_src'] = ride.source.get_lat_loc()
		template_values['lat_lng_des'] = ride.destination.get_lat_loc()
		template_values['googlemaps_key'] = GoogleMaps.get_key()
		template_values['google_calendar_key'] = GoogleCalendar.get_key()
		template_values['has_passengers'] = (ride.count_seats() - ride.count_emptyseats()) > 0 # has some passengers
		template_values['message_list'] = list(ride.ridemessages.order('created')) # the list of comments
		template_values['has_occurred'] =  (ride.date < ride.date.today()) # is in the past
		template_values['is_full'] = (ride.count_emptyseats() == 0) # no empty seats
		template_values['enable_feedback_on_driver'] =  template_values['has_occurred'] & ride.is_passenger(current_user) # ride is in the past and current user has been passenger
		template_values['enable_feedback_on_passengers'] = template_values['has_occurred'] & (current_user == ride.owner) # ride is in the past and current user was owner
		template_values['enable_edit_controls'] = (not template_values['has_occurred']) & (current_user == ride.owner) # ride is in the future and current user is owner
		template_values['enable_passenger_withdraw'] = (not template_values['has_occurred']) & ride.is_passenger(current_user) # ride is in the future and current user is passenger


		# --------------------------------------------------------------------
		# Control the display of the form element
		# and handle the new request
		# --------------------------------------------------------------------

		# if driver is cancelling their ride
		if current_user == ride.owner and self.request.POST.has_key('do_cancel_ride'):
			for seat in ride.seats:
				if seat.passenger:
					# notify the passengers
					mail.send_mail(sender="*****@*****.**",
		              to=seat.passenger.user.email(),
		              subject="RoadMate - Ride Cancelled",
		              body=generate_cancelledride_email_body(ride))

			ride.delete()
			self.redirect("/") # redirect to the main page
			return


		# if passenger is withdrawing
		if ride.is_passenger(current_user) and self.request.POST.has_key('do_withdraw'):
			passenger_seat = ride.seats.filter('passenger = ', user).get() # find the passenger's seat
			self.redirect("/ride?id=%s" % ride.key().id()) # redirect back to the view page
			# notify the driver
			mail.send_mail(sender="*****@*****.**",
		              to=ride.owner.user.email(),
		              subject="RoadMate - Passenger has withdrawn",
		              body=generate_withdrawpassenger_email_body(ride))
			#disassociate the seat from the user
			passenger_seat.passenger = None
			passenger_seat.accepted = None
			passenger_seat.save()

			return

		#if user has already placed a request on this ride ~~appears in get and post
		if ride.passengerrequests.filter('owner = ', current_user).get():
			template_values['requestable'] = False #turn off the request button
		else:
			template_values['requestable'] = True #turn on the request button


		#if user is placing a passenger request
		if self.request.POST.has_key('do_request_ride') and self.request.POST['do_request_ride']:
			prq = PassengerRequest(owner=current_user, ride=ride) #create a new passenger request
			prq.put()
			template_values['requestable'] = False #turn off the request button


		#if user is posting a message
		#TODO make this more secure! clean the title and body text and validate max/min length!

		if self.request.POST.has_key('do_post_message') and self.request.POST['do_post_message']:
			message = RideMessage(author=current_user, ride=ride, title=self.request.POST['message_title'], text=self.request.POST['message_body'])
			message.put()

		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "ride_view.html")
		self.response.out.write(template.render(page_path, template_values))
Exemplo n.º 13
0
	def get(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and GET Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		# Request Values
		ride_id = self.get_request_parameter('id', converter=int, default=-1) # ride
		prq_id = self.get_request_parameter('prq_id', converter=int, default=None) # passenger request (accept)
		action = self.get_request_parameter('action', converter=str, default=None)
		seat_id = self.get_request_parameter('seat_id', converter=int, default=None) # seat (remove passenger)

		# Datastore Values
		ride = Ride.get_by_id(ride_id)

		# --------------------------------------------------------------------
		# Validate Request
		# --------------------------------------------------------------------
		# if the target ride does not exist in the datastore, then redirect
		# the user back to the home page.
		if ride is None:
			self.error(404)
			return

		# --------------------------------------------------------------------
		# Handle approving and removing passengers and seats
		# --------------------------------------------------------------------
		if current_user == ride.owner:
		   	# Approve a passenger request
			if prq_id and action == 'APRV':
				prq = PassengerRequest.get_by_id(prq_id) #only proceed if there is a valid passengerrequest
				if prq and (ride.count_emptyseats() > 0):
					empty_seat = ride.seats.filter('passenger = ', None).get() #retrieve the empty seats on this ride
					empty_seat.assign(prq) #assign the seat: this method of Seat handles setting the "assigned time"
					prq.delete() #delete the passenger request
					# notify the approved passenger
					mail.send_mail(sender="*****@*****.**",
		              to=prq.owner.user.email(),
		              subject="RoadMate - Your passenger request has been approved",
		              body=generate_approvepassenger_email_body(ride))

		   	# Remove a passenger from the seat
			if seat_id and action == 'RM':
				seat = Seat.get_by_id(seat_id) #only proceed if there is a valid seat
				if seat:
					# notify the removed passenger
					mail.send_mail(sender="*****@*****.**",
		              to=seat.passenger.user.email(),
		              subject="RoadMate - Removed from ride",
		              body=generate_removedpassenger_email_body(ride))
					#disassociate the seat from the user
					seat.passenger = None
					seat.accepted = None
					seat.save()



		# --------------------------------------------------------------------
		# Generate and Store Template Values
		# --------------------------------------------------------------------
		template_values = super(ViewRidePageHandler, self
			).generate_template_values(self.request.url)

		template_values['ride'] = ride
		template_values['lat_lng_src'] = ride.source.get_lat_loc()
		template_values['lat_lng_des'] = ride.destination.get_lat_loc()
		template_values['googlemaps_key'] = GoogleMaps.get_key()
		template_values['google_calendar_key'] = GoogleCalendar.get_key()
		template_values['has_passengers'] = (ride.count_seats() - ride.count_emptyseats()) > 0 # has some passengers
		template_values['message_list'] = list(ride.ridemessages.order('created')) # the list of comments
		template_values['has_occurred'] =  (ride.date < ride.date.today()) # is in the past
		template_values['is_full'] = (ride.count_emptyseats() == 0) # no empty seats
		template_values['enable_feedback_on_driver'] =  template_values['has_occurred'] & ride.is_passenger(current_user) # ride is in the past and current user has been passenger
		template_values['enable_feedback_on_passengers'] = template_values['has_occurred'] & (current_user == ride.owner) # ride is in the past and current user was owner
		template_values['enable_edit_controls'] = (not template_values['has_occurred']) & (current_user == ride.owner) # ride is in the future and current user is owner
		template_values['enable_passenger_withdraw'] = (not template_values['has_occurred']) & ride.is_passenger(current_user) # ride is in the future and current user is passenger
		

		# --------------------------------------------------------------------
		# Control the display of the form element
		# --------------------------------------------------------------------
		#if user has already placed a request on this ride ~~appears in get and post
		if ride.passengerrequests.filter('owner = ', current_user).get():
			template_values['requestable'] = False #turn off the request button
		else:
			template_values['requestable'] = True #turn on the request button



		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "ride_view.html")
		self.response.out.write(template.render(page_path, template_values))