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))
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 # -------------------------------------------------------------------- # Retrieve user from GET Data, return the user # -------------------------------------------------------------------- # Request Values riderequest_id = self.get_request_parameter('id', converter=int, default=None) # Datastore Values riderequest = RideRequest.get_by_id(riderequest_id) # -------------------------------------------------------------------- # Validate the user and POST Data # -------------------------------------------------------------------- # if the entity does not exist in the datastore, then redirect # the user back to an error page. if riderequest is None: self.error(404) return # if the user is trying to edit an entity not belonging to them # then present them with an error page (403: Forbidden). if riderequest.owner != current_user: logging.error("User '%s' attempted to edit a riderequest '%s' which does not belong to them"\ "Redirecting to error page." % (current_user.user.email, riderequest.key.id)) 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'] == "None" and not self.request.POST['editorId'].startswith('_'): setattr(riderequest, self.request.POST['editorId'], self.request.POST['value'])# update that attribute riderequest.save() # save the record self.response.out.write(escape(getattr(riderequest, self.request.POST['editorId']))) # print that value to the page else: # input text is "None", return the same self.response.out.write("None") else: # values are missing self.error(403)
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))
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))
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