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): template = jinjaEnvironment.get_template('template/adminwelcome.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_admin_menu(page='admin') template_values['bikeTypes'] = BikeType.query().fetch() template_values['rideTypes'] = RideType.query().fetch() 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'): 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))