コード例 #1
0
	def post(self):
		# --------------------------------------------------------------------
		# Retrive and Validate Request
		# --------------------------------------------------------------------
		# Default Values
		current_user = RoadMateUser.get_current_user()

		# --------------------------------------------------------------------
		# Validate Sesson
		# --------------------------------------------------------------------
		# if the current users in not logged in, then we redirect them through
		# a login page.
		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return
		target_user = None

		# --------------------------------------------------------------------
		# Retrieve user from GET Data, return the user
		# --------------------------------------------------------------------
		target_user_id = self.get_request_parameter('user', converter=int, default=None)
		target_user = RoadMateUser.get_by_id(target_user_id)

		# --------------------------------------------------------------------
		# Validate the user and POST Data
		# --------------------------------------------------------------------
		# if the target user does not exist in the datastore, then redirect
		# the user back to an error page.
		if target_user is None:
			self.error(404)
			return

		# if the user is trying to edit someone elses profile page,
		# then present them with an error page (403: Forbidden).
		if target_user != current_user:
			logging.error("User '%s' attempted to modify the profile of"\
				" user '%s'. Redirecting to error page." %
				(current_user.user.email, target_user.user.email))
			self.error(403)
			return

		# --------------------------------------------------------------------
		# Set the changed attribute and save the entity
		# --------------------------------------------------------------------

		if self.request.POST.has_key('editorId') and self.request.POST.has_key('value'):
			 # input text must not be "None" (the default NULL representation)
			 # and must not try to set a private attribute (which all start with '_')
			if not self.request.POST['value'] == "" and not self.request.POST['value'] == "None" and not self.request.POST['editorId'].startswith('_'):
				setattr(target_user, self.request.POST['editorId'], self.request.POST['value'])# update that attribute
				target_user.save() # save the record
				self.response.out.write(escape(getattr(target_user, self.request.POST['editorId']))) # print that value to the page
			else: # input text is "None" or empty string, return "None"
				self.response.out.write("None")
		else: # values are missing
			self.error(403)
コード例 #2
0
ファイル: ride.py プロジェクト: SassaAbdellah/roadmate
	def get(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and Request Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		# --------------------------------------------------------------------
		# Validate Session and Request
		# --------------------------------------------------------------------
		# if the current users in not logged in, then we redirect them through
		# a login page.
		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return

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

		# because this page requires the user to be logged in, if they logout
		# we redirect them back to the home page.
		template_values['logout_url'] = users.create_logout_url("/")
		template_values['owner'] = current_user

		template_values['ride_form'] = RideForm()

		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "ride_create.html")
		self.response.out.write(template.render(page_path, template_values))
コード例 #3
0
	def generate_template_values(self, page_url):
		"""	Generates a dictionary of template values required by the pages
			served from this request handler.

			Parameters:
				page_url - The URL of the page requesting the template values.

		"""

		# --------------------------------------------------------------------
		# Generate Template Values
		# --------------------------------------------------------------------
		current_user = RoadMateUser.get_current_user()

		isLoggedIn = False
		if current_user:
			isLoggedIn = True

		login_url = users.create_login_url(page_url)
		logout_url = users.create_logout_url(page_url)


		# --------------------------------------------------------------------
		# Store Template Values
		# --------------------------------------------------------------------
		template_values = {}

		template_values['current_user'] = current_user
		template_values['isLoggedIn'] = isLoggedIn
		template_values['login_url'] = login_url
		template_values['logout_url'] = logout_url
		template_values['page_url'] = page_url

		return template_values
コード例 #4
0
ファイル: myrides.py プロジェクト: SassaAbdellah/roadmate
	def get(self):
		## --------------------------------------------------------------------
		# Retrive Session Info and Request Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

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

		# because this page requires the user to be logged in, if they logout
		# we redirect them back to the home page.
		template_values['logout_url'] = users.create_logout_url('/')

		template_values['my_rides'] = current_user.rides.filter('date >=', datetime.date.today()) # only future rides or rides that occur today
		template_values['my_past_rides'] = current_user.rides.filter('date <', datetime.date.today()) # only rides that occurred yesterday or earlier
		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__),
			'myrides.html')

		self.response.out.write(template.render(page_path, template_values))
コード例 #5
0
ファイル: browse.py プロジェクト: SassaAbdellah/roadmate
	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
		riderequests = RideRequest.all() #TODO this will need to be > now(), i.e. only future instances

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

		template_values['riderequests'] = list(riderequests)
		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "browse_riderequests.html")
		self.response.out.write(template.render(page_path, template_values))
コード例 #6
0
ファイル: profile.py プロジェクト: SassaAbdellah/roadmate
    def get(self):
        ## --------------------------------------------------------------------
        # Retrive Session Info and Request Data
        # --------------------------------------------------------------------
        # Session Values
        current_user = RoadMateUser.get_current_user()

        # Request Values
        target_user_id = self.get_request_parameter("user", converter=int, default=None)

        # Datastore Values
        target_user = None
        if target_user_id > 0:
            target_user = RoadMateUser.get_by_id(target_user_id)

            # --------------------------------------------------------------------
            # Validate Session and Request
            # --------------------------------------------------------------------
        if target_user is None:
            if current_user is None:
                self.redirect(users.create_login_url(self.request.url))
                return
            else:
                # if a target user has not be specified, but the user is
                # logged in, then redirect them to their profile page.
                logging.info("No target user specified. Redirecting to" " current user's profile page.")

                self.redirect("/profile?user=%s" % current_user.key().id())
                return
                # --------------------------------------------------------------------
                # Generate Template Values
                # --------------------------------------------------------------------
        template_values = super(ProfilePageHandler, self).generate_template_values(self.request.url)

        # because this page requires the user to be logged in, if they logout
        # we redirect them back to the home page.
        template_values["logout_url"] = users.create_logout_url("/")

        template_values["my_rides"] = list(target_user.rides)
        template_values["target_user"] = target_user  # only used if not current user

        # --------------------------------------------------------------------
        # Render and Serve Template
        # --------------------------------------------------------------------
        page_path = os.path.join(os.path.dirname(__file__), "profile.html")
        self.response.out.write(template.render(page_path, template_values))
コード例 #7
0
ファイル: riderequest.py プロジェクト: SassaAbdellah/roadmate
	def post(self):

		# --------------------------------------------------------------------
		# Retrive Session Info
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

		# --------------------------------------------------------------------
		# Validate Sesson
		# --------------------------------------------------------------------
		# if the current users in not logged in, then we redirect them through
		# a login page.
		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return

		# --------------------------------------------------------------------
		# Retrive POST Data
		# i.e. form has been submitted, do sth with the values
		# --------------------------------------------------------------------

		riderequest_data = { 'owner':current_user }

		riderequest_form = RideRequestForm(
			data=self.request.POST,
			initial=riderequest_data
		) #set a form for that instance

		# --------------------------------------------------------------------
		# Validate POST Data
		# --------------------------------------------------------------------
		# if there are errors in the form, then re-serve the page with the
		# error values highlighted.
		if not riderequest_form.is_valid():
			# ----------------------------------------------------------------
			# Generate Template Values
			# ----------------------------------------------------------------
			template_values = BaseRequestHandler.generate_template_values(self,
				self.request.url)


			# because this page requires the user to be logged in, if they
			# logout we redirect them back to the home page.
			template_values['logout_url'] = users.create_logout_url("/")
			template_values['owner'] = current_user

			template_values['riderequest_form'] = riderequest_form

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

		riderequest = riderequest_form.save() #else, the form is valid, so save it
		self.redirect("/riderequest?id=%s" % riderequest.key().id()) # redirect to the view page
コード例 #8
0
ファイル: riderequest.py プロジェクト: SassaAbdellah/roadmate
	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))
コード例 #9
0
ファイル: feedback.py プロジェクト: SassaAbdellah/roadmate
	def get(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and GET Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

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

		# Datastore Values
		target_user = RoadMateUser.get_by_id(target_user_id)

		# --------------------------------------------------------------------
		# Validate Request
		# --------------------------------------------------------------------
		# if the target ride does not exist in the datastore, then redirect
		# the user back to the home page.
		if target_user is None:
			self.error(404)
			return
		# --------------------------------------------------------------------
		# Generate and Store Template Values
		# --------------------------------------------------------------------
		template_values = super(ViewFeedbackPageHandler, self
			).generate_template_values(self.request.url)

		template_values['target_user'] = target_user
		template_values['feedback_list'] = list(target_user.feedback_received)
		template_values['count_positive'] = target_user.feedback_received.filter('value=', 1).count()
		template_values['count_neutral'] = target_user.feedback_received.filter('value=', 0).count()
		template_values['count_negative'] = target_user.feedback_received.filter('value=', -1).count()

		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__), "feedback.html")
		self.response.out.write(template.render(page_path, template_values))
コード例 #10
0
ファイル: mybookings.py プロジェクト: SassaAbdellah/roadmate
	def get(self):
		## --------------------------------------------------------------------
		# Retrive Session Info and Request Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

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

		# because this page requires the user to be logged in, if they logout
		# we redirect them back to the home page.
		template_values['logout_url'] = users.create_logout_url('/')

		# sort out the rides into current and past
		# GQL doesn't have the ability to join tables (seat to ride) and query on the result
		# so need to sort the seats into current/past lists by iteration
		seats = current_user.myseats
		current_seats = []
		past_seats = []
		for seat in seats:
			if seat.ride.date >= datetime.date.today():
				current_seats.append(seat)
			else:
			    past_seats.append(seat)
		# now create the template values for these output lists
		template_values['current_seats'] = current_seats
		template_values['past_seats'] = past_seats

		# --------------------------------------------------------------------
		# Render and Serve Template
		# --------------------------------------------------------------------
		page_path = os.path.join(os.path.dirname(__file__),
			'mybookings.html')

		self.response.out.write(template.render(page_path, template_values))
コード例 #11
0
ファイル: riderequest.py プロジェクト: SassaAbdellah/roadmate
	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))
コード例 #12
0
ファイル: ride.py プロジェクト: SassaAbdellah/roadmate
	def post(self):
		# --------------------------------------------------------------------
		# Retrive Session Info
		# --------------------------------------------------------------------
		# Session Values
		rq_id = self.get_request_parameter('rq', converter=int, default=None) #if created with a ride request
		current_user = RoadMateUser.get_current_user()

		# --------------------------------------------------------------------
		# Validate Sesson
		# --------------------------------------------------------------------
		# if the current users in not logged in, then we redirect them through
		# a login page.
		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return

		# --------------------------------------------------------------------
		# Retrive POST Data
		# i.e. form has been submitted, do sth with the values
		# --------------------------------------------------------------------

		ride_data = { 'owner':current_user }

		ride_form = RideForm(
			data=self.request.POST,
			initial=ride_data
		) #set a form for that instance

		# --------------------------------------------------------------------
		# Validate POST Data
		# --------------------------------------------------------------------
		# if there are errors in the form, then re-serve the page with the
		# error values highlighted.
		if not ride_form.is_valid():
			# ----------------------------------------------------------------
			# Generate Template Values
			# ----------------------------------------------------------------
			template_values = BaseRequestHandler.generate_template_values(self,
				self.request.url)


			# because this page requires the user to be logged in, if they
			# logout we redirect them back to the home page.
			template_values['logout_url'] = users.create_logout_url("/")
			template_values['owner'] = current_user

			template_values['ride_form'] = ride_form

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

		ride = ride_form.save() #else, the form is valid, so save it
		if rq_id:
			request = RideRequest.get_by_id(rq_id)
			#notification if created by ride request
			mail.send_mail(sender="*****@*****.**",
		              to=request.owner.user.email(),
		              subject="RoadMate - Ride Request Accepted",
		              body=generate_fromriderequest_email_body(ride))

		ride.create_seats(ride_form.clean_data.get('number_of_seats')) # create its seats



		self.redirect("/ride?id=%s" % ride.key().id()) # redirect to the view page
コード例 #13
0
ファイル: ride.py プロジェクト: SassaAbdellah/roadmate
	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))
コード例 #14
0
ファイル: ride.py プロジェクト: SassaAbdellah/roadmate
	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))
コード例 #15
0
ファイル: feedback.py プロジェクト: SassaAbdellah/roadmate
	def post(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and Request Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

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

  		# Retrieve the instances
  		ride = Ride.get_by_id(ride_id)
   		target_user = RoadMateUser.get_by_id(target_user_id)
   		feedback_form = FeedbackForm()
		target_user_role = '' # empty by default


		# --------------------------------------------------------------------
		# Validate Session and Request
		# --------------------------------------------------------------------
		# if the current users in not logged in, then we redirect them through
		# a login page.
  		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return
		# if the target user is not valid then error
		if target_user is None or ride is None:
			self.error(403) # forbidden
			return
		#if the current user has already placed feedback on the recipient for this ride
		if ride.feedbackmessages.filter('author =', current_user).filter('recipient =', target_user).count() >= 1:
			self.redirect("/feedback?id=%s" % target_user.key().id()) # redirect to the recipient's feedback page
			return


		# if the target user is not the driver, and the current user is not a passenger
		# or vice versa, then error
		if ride.is_passenger(current_user) and (target_user == ride.owner):
			target_user_role = 'passenger'
		elif ride.is_passenger(target_user) and (current_user == ride.owner):
			target_user_role = 'driver'
		else: # then the relationship is not valid
			self.error(403) # forbidden
			return


## not working
##		# --------------------------------------------------------------------
##		# Retrive POST Data
##		# and create a new instance of the form to validate the data
##		# --------------------------------------------------------------------
##		feedback_data = { 'author': current_user, 'ride':ride, 'recipient':target_user, 'role': target_user_role}
##
##		feedback_form = FeedbackForm(
##			data=self.request.POST,
##			initial=feedback_data
##		) # create the form to validate
##		print(feedback_form['ride'].data)
##
##		# --------------------------------------------------------------------
##		# Validate POST Data
##		# --------------------------------------------------------------------
##		# if there are errors in the form, then re-serve the page with the
##		# error values highlighted.
##		if not feedback_form.is_valid():
##			# ----------------------------------------------------------------
##			# Generate Template Values
##			# ----------------------------------------------------------------
##			template_values = BaseRequestHandler.generate_template_values(self,
##				self.request.url)
##
##			# because this page requires the user to be logged in, if they
##			# logout we redirect them back to the home page.
##			template_values['logout_url'] = users.create_logout_url("/")
##
##			# --------------------------------------------------------------------
##			# Set up the page 'passenger' or 'driver' display
##			# --------------------------------------------------------------------
##			target_user_role = 'driver' # by default
##			if ride.is_passenger(target_user):
##				target_user_role = 'passenger'
##
##			# --------------------------------------------------------------------
##			# Generate Template Values
##			# --------------------------------------------------------------------
##			template_values = super(CreateFeedbackPageHandler, self
##				).generate_template_values(self.request.url)
##
##			# because this page requires the user to be logged in, if they logout
##			# we redirect them back to the home page.
##			template_values['logout_url'] = users.create_logout_url("/")
##			template_values['owner'] = current_user
##			template_values['target_user'] = target_user
##			template_values['ride'] = ride
##			template_values['feedback_form'] = feedback_form
##			template_values['target_user_role'] = target_user_role
##
##			# ----------------------------------------------------------------
##			# Render and Serve Template
##			# ----------------------------------------------------------------
##			print(feedback_form.errors)
##			page_path = os.path.join(os.path.dirname(__file__), "feedback_create.html")
##			self.response.out.write(template.render(page_path, template_values))
##			return

		feedback_message = FeedbackMessage(
						 ride=ride,
						 author=current_user,
						 recipient=target_user,
						 role=target_user_role,
				   		 value=int(self.request.POST['value']),
				   		 text=escape(self.request.POST['text'])
						 ) # not validated

		feedback_message.put() # save the new Message
		self.redirect("/feedback?id=%s" % target_user.key().id()) # redirect to the recipient's profile page or feedback page
コード例 #16
0
ファイル: feedback.py プロジェクト: SassaAbdellah/roadmate
	def get(self):
		# --------------------------------------------------------------------
		# Retrive Session Info and Request Data
		# --------------------------------------------------------------------
		# Session Values
		current_user = RoadMateUser.get_current_user()

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

  		# Retrieve the instances
  		ride = Ride.get_by_id(ride_id)
   		target_user = RoadMateUser.get_by_id(target_user_id)
	  	feedback_form = FeedbackForm()
		target_user_role = '' # empty by default


		# --------------------------------------------------------------------
		# Validate Session and Request
		# --------------------------------------------------------------------
		# if the current users in not logged in, then we redirect them through
		# a login page.
  		if current_user is None:
			self.redirect(users.create_login_url(self.request.url))
			return
		# if the target user is not valid then error
		if target_user is None or ride is None:
			self.error(403) # forbidden
			return

		# if the target user is not the driver, and the current user is not a passenger
		# or vice versa, then error
		if ride.is_passenger(current_user) and (target_user == ride.owner):
			target_user_role = 'driver'
		elif ride.is_passenger(target_user) and (current_user == ride.owner):
			target_user_role = 'passenger'
		else: # then the relationship is not valid
			self.error(403) # forbidden
			return

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

		# because this page requires the user to be logged in, if they logout
		# we redirect them back to the home page.
		template_values['logout_url'] = users.create_logout_url("/")
		template_values['owner'] = current_user
		template_values['target_user'] = target_user
		template_values['ride'] = ride
		template_values['feedback_form'] = feedback_form
		template_values['target_user_role'] = target_user_role

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