def get(self): error_list = [] profile = get_profile() template_values = make_user_links(self.request.uri) key = self.request.get('key') # below test is a bit of a hack because an empty key is returned as the string 'None' sometimes if key and (key != 'None'): b_key = ndb.Key(urlsafe=key) bike = b_key.get() template_values['submitValue'] = 'Update' if bike: if b_key.parent() != profile.key: error_list.append('Attempt to edit bike not owned by user') else: error_list.append('Bike not found') else: key = None bike = Bike() template_values['submitValue'] = 'Create' if len(error_list) > 0: logging.info('%s' % error_list) self.redirect('user/errorPage') else: template = jinjaEnvironment.get_template('template/bikeentry.html') template_values['menu'] = make_menu(page='user/bikeentry') bike_form = BikeForm(obj=bike) bike_form.bikeType.choices = [(bikeType.key.urlsafe(), bikeType.name) for bikeType in BikeType.query().fetch()] bike_form.bikeType.data = (bike.bikeType.urlsafe() if bike.bikeType else 0) template_values['form'] = bike_form template_values['key'] = key self.response.out.write(template.render(template_values))
def get(self): profile = get_profile() template_values = make_user_links(self.request.uri) error_list = [] key = self.request.get('key') if key and (key != 'None'): r_key = ndb.Key(urlsafe=key) bike_ride = r_key.get() template_values['submitValue'] = 'Update' if bike_ride: if r_key.parent() != profile.key: error_list.append('Attempt to edit bikeRide not owned by user') else: error_list.append('bikeRide not found') else: key = None bike_ride = BikeRide() template_values['submitValue'] = 'Create' if len(error_list) > 0: logging.info('%s' % error_list) self.redirect('/user/errorPage') else: bike_ride_form = BikeRideForm(obj=bike_ride) bike_ride_form.bike.choices = [(bike.key.urlsafe(), bike.brand + ' ' + bike.model) for bike in Bike.query(ancestor=profile.key).fetch()] bike_ride_form.bike.data = (bike_ride.bike.urlsafe() if bike_ride.bike else 0) bike_ride_form.rideType.choices = [(rideType.key.urlsafe(), rideType.name) for rideType in RideType.query().fetch()] bike_ride_form.rideType.data = (bike_ride.rideType.urlsafe() if bike_ride.rideType else 0) template_values['form'] = bike_ride_form template = jinjaEnvironment.get_template('template/rideentry.html') template_values['menu'] = make_menu(page='user/rideentry') template_values['key'] = key self.response.out.write(template.render(template_values))
def get(self): profile = get_profile() template = jinjaEnvironment.get_template('template/rideroverview.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_menu(page='user/rideroverview') template_values['rides'] = BikeRide.query(ancestor=profile.key).order(-BikeRide.date).fetch(20) self.response.out.write(template.render(template_values))
def get(self): profile = get_profile() template = jinjaEnvironment.get_template('template/bikeoverview.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_menu(page='user/bikeoverview') template_values['bikes'] = Bike.query(ancestor=profile.key).fetch() template_values['biketypes'] = BikeType.query().fetch() self.response.out.write(template.render(template_values))
def post(self): error_list = [] profile = get_profile() key = self.request.get('key') if key and (key != 'None'): r_key = ndb.Key(urlsafe=key) bike_ride = r_key.get() if bike_ride: if r_key.parent() != profile.key: error_list.append('Attempt to edit bikeRide not owned by user') else: error_list.append('bikeRide not found') else: bike_ride = BikeRide(parent=profile.key) if len(error_list) > 0: logging.info('%s' % error_list) self.redirect('/user/errorPage') else: form_data = BikeRideForm(self.request.POST, bike_ride) form_data.bike.choices = [(bike.key.urlsafe(), bike.brand) for bike in Bike.query().fetch()] form_data.rideType.choices = [(rideType.key.urlsafe(), rideType.name) for rideType in RideType.query().fetch()] logging.info("data from bikeride form is: %s", form_data) logging.info("data from the bikeride request is: %s", self.request) if form_data.validate(): form_data.bike.data = ndb.Key(urlsafe=form_data.bike.data) form_data.rideType.data = ndb.Key(urlsafe=form_data.rideType.data) form_data.populate_obj(bike_ride) bike_ride.put() self.redirect('/user/rideroverview') else: template = jinjaEnvironment.get_template('template/rideentry.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_menu(page='user/rideentry') template_values['submitValue'] = 'Fix' template_values['form'] = form_data template_values['key'] = key self.response.out.write(template.render(template_values))
def post(self): error_list = [] profile = get_profile() key = self.request.get('key') if key and (key != 'None'): b_key = ndb.Key(urlsafe=key) bike = b_key.get() if bike: if b_key.parent() != profile.key: error_list.append('Attempt to edit bike not owned by user') else: error_list.append('Bike not found') else: bike = Bike(parent=profile.key) if len(error_list) > 0: logging.info('%s' % error_list) self.redirect('user/errorPage') else: form_data = BikeForm(self.request.POST, bike) form_data.bikeType.choices = [(bikeType.key.urlsafe(), bikeType.name) for bikeType in BikeType.query().fetch()] logging.info('%s' % form_data.bikeType.data) if form_data.validate(): # Save and redirect to bike overview page form_data.bikeType.data = ndb.Key( urlsafe=form_data.bikeType.data) # translate urlsafe key string to actual key form_data.populate_obj(bike) bike.put() self.redirect('/user/bikeoverview') else: # back to form for editing template = jinjaEnvironment.get_template('template/bikeentry.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_menu(page='user/bikeentry') template_values['submitValue'] = 'Fix' template_values['form'] = form_data template_values['key'] = key self.response.out.write(template.render(template_values))
def get(self): template = jinjaEnvironment.get_template('template/under_construction.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_menu() template_values['message'] = 'Requested page not found' self.response.out.write(template.render(template_values))
def get(self): template = jinjaEnvironment.get_template('template/welcome.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_menu('') self.response.out.write(template.render(template_values))