def post(self, slug=None): f = page_form() data = self.get_arguments() is_edit = data.has_key('ori_slug') _ = self._ try: attachments = self.get_argument('attachments', None) if attachments: data['attachments'] = parse_attachments(data['attachments'], is_edit) if f.validates(tornado.web._O(data)): page = Page.one({'type': 'Page', 'slug': data['ori_slug']}) \ if is_edit else Page() page.save(data, user=self.current_user) if attachments: page['attachments'] = move_attachments(self.settings.upload_path, data['attachments']) page.update_html() page.save() self.set_flash(_("Page has been saved.")) self.redirect(page.get_url()) return page = Page() raise Exception(_("Invalid form data.")) except Exception, e: if attachments: page['attachments'] = data['attachments'] f.note = f.note if f.note else e self.render("page-edit", f=f, page=page, user=self.current_user)
def post(self, slug=None): f = page_form() data = self.get_arguments() is_edit = data.has_key('ori_slug') _ = self._ try: attachments = self.get_argument('attachments', None) if attachments: data['attachments'] = parse_attachments( data['attachments'], is_edit) if f.validates(tornado.web._O(data)): page = Page.one({'type': 'Page', 'slug': data['ori_slug']}) \ if is_edit else Page() page.save(data, user=self.current_user) if attachments: page['attachments'] = move_attachments( self.settings.upload_path, data['attachments']) page.update_html() page.save() self.set_flash(_("Page has been saved.")) self.redirect(page.get_url()) return page = Page() raise Exception(_("Invalid form data.")) except Exception, e: if attachments: page['attachments'] = data['attachments'] f.note = f.note if f.note else e self.render("page-edit", f=f, page=page, user=self.current_user)
def get(self, slug=None): f = page_form() if slug: try: page = Page.one({'type': 'Page', 'slug': slug}) page.check_edit_permission(self.get_current_user()) page.formify() f.fill(page) except EditDisallowedError: self.set_flash(self._("You are not allowed to edit that page.")) self.redirect(page.get_url()) return except: raise tornado.web.HTTPError(404) else: page = Page() self.render("page-edit", f=f, page=page, user=self.current_user)
def get(self, slug=None): f = page_form() if slug: try: page = Page.one({'type': 'Page', 'slug': slug}) page.check_edit_permission(self.get_current_user()) page.formify() f.fill(page) except EditDisallowedError: self.set_flash( self._("You are not allowed to edit that page.")) self.redirect(page.get_url()) return except: raise tornado.web.HTTPError(404) else: page = Page() self.render("page-edit", f=f, page=page, user=self.current_user)
def admin_page_edit(page_id=None): if request.method=='GET': if page_id == 'new': pageForm = forms.page_form() template_data = { 'form' : pageForm, 'page_id' : 'new' } else: try: page = models.Page.objects().get(id=page_id) if page: pageForm = forms.page_form(obj=page) template_data = { 'form' : pageForm, 'page_id' : page_id } except: return 'uhoh couldn\'t find it.' return render_template('admin/page_entry.html',**template_data) elif request.method=='POST': pageForm = forms.page_form(request.form) if pageForm.validate() and page_id == 'new': # create new page page = models.Page() pageForm.populate_obj(page) page.save() return redirect('/admin/page/' + str(page.id)) elif pageForm.validate(): # get the page page = models.Page.objects().get(id=page_id) if page: pageForm.populate_obj(page) page.save() template_data = { 'form' : pageForm, 'page_id' : page.id } return render_template('admin/page_entry.html', **template_data) else: return "Valid form but unable to find page" else: template_data = { 'form' : pageForm, 'page_id' : request.form.get('page_id') } return render_template('admin/page_entry.html', **template_data)