Esempio n. 1
0
    def generate_template_values(self, page_path):
        """
			generate_template_values

			Generates a dictionary of template values required by the pages
			served from this request handler.

		"""

        # --------------------------------------------------------------------
        # Generate Template Values
        # --------------------------------------------------------------------
        template_values = BaseRequestHandler.generate_template_values(self, page_path)

        # 10 most recently created rides
        OneDay = datetime.timedelta(days=1)
        Yesterday = datetime.datetime.now() - OneDay

        rides = db.GqlQuery(
            "SELECT * FROM Ride \
							WHERE date > :1 \
							ORDER BY date, created DESC LIMIT 10",
            Yesterday,
        )

        # --------------------------------------------------------------------
        # Store Template Values
        # --------------------------------------------------------------------

        template_values["rides"] = list(rides)

        return template_values
Esempio n. 2
0
	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
Esempio n. 3
0
	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