示例#1
0
    def post(self):
        try:
            id = int(self.request.get('_id'))
            bike = Bike.get(db.Key.from_path('Bike', id))
        except ValueError:
            bike = None
            id = None
        data = BikeForm(data=self.request.POST, instance=bike)

        if data.is_valid():
            # Save and redirect to admin home page
            entity = data.save(commit=False)
            entity.bikeRider = users.get_current_user()
            entity.put()
            self.redirect('/user/bikeoverview')
        else:
            # back to form for editing
            path = os.path.join(os.path.dirname(__file__),
                                'template/bikeentry.html')
            template_values = makeUserLinks(self.request.uri)
            template_values['menu'] = makeMenu(page='user/bikeentry')
            template_values['submitValue'] = 'Fix'
            template_values['form'] = data
            template_values['id'] = id
            self.response.out.write(template.render(path, template_values))
示例#2
0
    def get(self):
        template_values = makeUserLinks(self.request.uri)
        try:
            id = int(self.request.get('id'))
            bike = Bike.get(db.Key.from_path('Bike', id))
            template_values['submitValue'] = 'Update'
        except ValueError:
            id = None
            bike = None
            template_values['submitValue'] = 'Create'

        path = os.path.join(os.path.dirname(__file__),
                            'template/bikeentry.html')
        template_values['menu'] = makeMenu(page='user/bikeentry')
        template_values['form'] = BikeForm(instance=bike)
        template_values['id'] = id
        self.response.out.write(template.render(path, template_values))