def post(self): request_id = self.request.get('_id') try: ride_type = RideType.get_by_id(int(request_id)) except ValueError: ride_type = RideType() request_id = None form_data = RideTypeForm(self.request.POST, ride_type) if form_data.validate(): # Save and redirect to admin home page form_data.populate_obj(ride_type) ride_type.put() self.redirect('/admin') else: # back to form for editing template = jinjaEnvironment.get_template( 'template/ridetypeentry.html') template_values = make_user_links(self.request.uri) template_values['menu'] = make_admin_menu( page='admin/ridetypeentry') template_values['submitValue'] = 'Fix' template_values['form'] = form_data template_values['id'] = request_id 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): 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): path = os.path.join(os.path.dirname(__file__), 'template/adminwelcome.html') template_values = makeUserLinks(self.request.uri) template_values['menu'] = makeAdminMenu(page='admin') template_values['bikeTypes'] = BikeType.all() template_values['rideTypes'] = RideType.all() self.response.out.write(template.render(path, template_values))
def get(self): template_values = make_user_links(self.request.uri) request_id = self.request.get('id') try: ride_type = RideType.get_by_id(int(request_id)) template_values['submitValue'] = 'Update' except ValueError: ride_type = RideType() request_id = None template_values['submitValue'] = 'Create' template = jinjaEnvironment.get_template('template/ridetypeentry.html') template_values['menu'] = make_admin_menu(page='admin/ridetypeentry') template_values['form'] = RideTypeForm(obj=ride_type) template_values['id'] = request_id self.response.out.write(template.render(template_values))
def get(self): template_values = makeUserLinks(self.request.uri) try: id = int(self.request.get('id')) rideType = RideType.get(db.Key.from_path('RideType', id)) template_values['submitValue'] = 'Update' except ValueError: rideType = None id = None template_values['submitValue'] = 'Create' path = os.path.join(os.path.dirname(__file__), 'template/ridetypeentry.html') template_values['menu'] = makeAdminMenu(page='admin/ridetypeentry') template_values['form'] = RideTypeForm(instance=rideType) template_values['id'] = id self.response.out.write(template.render(path, template_values))
def load_ridetypes(): """Load ride types from u.ridetype into database.""" print "Ride Types" RideType.query.delete() for row in open("seed_data/u.ridetype"): row = row.rstrip() ride_service, ride_type = row.split("|") ridetype = RideType(ride_service=ride_service, ride_type=ride_type) db.session.add(ridetype) db.session.commit()
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): try: id = int(self.request.get('_id')) rideType = RideType.get(db.Key.from_path('RideType', id)) except ValueError: rideType = None id = None data = RideTypeForm(data=self.request.POST, instance=rideType) if data.is_valid(): # Save and redirect to admin home page entity = data.save(commit=False) entity.put() self.redirect('/admin') else: # back to form for editing path = os.path.join(os.path.dirname(__file__), 'template/ridetypeentry.html') template_values = makeUserLinks(self.request.uri) template_values['menu'] = makeAdminMenu(page='admin/ridetypeentry') template_values['submitValue'] = 'Fix' template_values['form'] = data template_values['id'] = id self.response.out.write(template.render(path, template_values))