def get(self, page_id=None, **kwargs): """Return a page to edit or an empty form to create""" template = 'admin/page/new.html' context = { 'form': self.form, } # render edit if page_id is not None: page = Page.get_by_id(page_id) if page: self.form = PageForm(obj=page) context.update({ 'form': self.form }) template = 'admin/page/edit.html' else: return redirect('admin/page/') # render new return self.render_response(template, **context)
def get(self, page_id=None, **kwargs): """Return a page to edit or an empty form to create""" template = 'admin/page/new.html' context = { 'form': self.form, } # render edit if page_id is not None: page = Page.get_by_id(page_id) if page: self.form = PageForm(obj=page) context.update({'form': self.form}) template = 'admin/page/edit.html' else: return redirect('admin/page/') # render new return self.render_response(template, **context)
def post(self, page_id=None, **kwargs): """Handle submitted form data""" # validate form if self.form.validate(): title = self.form.title.data content = self.form.content.data live = self.form.live.data language = self.form.language.data # saving edited if page_id: page = Page.get_by_id(page_id) page.title = title page.content = content page.live = live page.language = language # creating new else: page = Page(title=title, content=content, live=live, language=language) if page.put(): return redirect('admin/page') return self.get(**kwargs)