def get(self,item_id=None): from auth.models import User if 'page' in request.endpoint: from page.models import Page page = Page.get_by_id(item_id) if not 'content' in request.endpoint: self._form = model_form(Page,Page.session,base_class=Form,exclude=['added_by','date_added']) self._context['obj'] = page else: from page.forms import EditContentForm self._form = EditContentForm self._form_obj = page elif 'block' in request.endpoint: from page.models import Block block = Block.get_by_id(item_id) if not 'content' in request.endpoint: self._form = model_form(Block,Block.session,base_class=Form,exclude=['templates','pages']) self._context['obj'] = block else: from page.forms import EditContentForm self._form = EditContentForm self._form_obj = block else: from admin.forms import TemplateBodyFieldForm from wtforms import FormField from page.models import Template template = Template.get_by_id(item_id) form = model_form(Template,Template.session,base_class=Form,exclude=['pages','blocks','filename','body']) class TemplateForm(form): body = FormField(TemplateBodyFieldForm,separator='_') self._form = TemplateForm self._context['obj'] = template self._form_obj = template return self.render()
def post(self): if 'content' in request.endpoint: session['content'] = request.form['content'][:] return self.redirect('admin.add_block') else: content = session.pop('content',None) from page.models import Block from ext import db AddBlockForm = model_form(Block,db.session,base_class=Form) self._form = AddBlockForm(request.form) block = Block() self._form.populate_obj(block) if 'content' in session: block.content = content block.save() flash('Successfully created cms block: {}'.format(block.name)) return self.redirect('admin.blocks') return self.render()
def get(self, item_id=None): from auth.models import User from ext import db if 'page' in request.endpoint: from page.models import Page page = Page.get_by_id(item_id) if not 'content' in request.endpoint: self._form = model_form(Page, db.session, base_class=Form, exclude=['added_by', 'date_added']) self._context['obj'] = page else: from page.forms import EditContentForm self._form = EditContentForm self._form_obj = page elif 'block' in request.endpoint: from page.models import Block block = Block.get_by_id(item_id) if not 'content' in request.endpoint: self._form = model_form(Block, db.session, base_class=Form, exclude=['templates', 'pages']) self._context['obj'] = block else: from page.forms import EditContentForm self._form = EditContentForm self._form_obj = block else: from admin.forms import TemplateBodyFieldForm from wtforms import FormField from page.models import Template template = Template.get_by_id(item_id) form = model_form(Template, db.session, base_class=Form, exclude=['pages', 'blocks', 'filename', 'body']) class TemplateForm(form): body = FormField(TemplateBodyFieldForm, separator='_') self._form = TemplateForm self._context['obj'] = template self._form_obj = template return self.render()