Пример #1
0
 def post(self):
     from page.models import Template
     from auth.models import User
     from ext import db
     self._form = model_form(Template,db.session,base_class=Form,exclude=['blocks','pages','body'])(request.form)
     if self._form.validate():
         template = Template()
         self._form.populate_obj(template)
         template.save()
         filename = template.filename
         if template.body is not None:
             body = template.body[:]
         else:
             body = ''
         from settings import BaseConfig
         import os
         templatedir = os.path.join(BaseConfig.ROOT_PATH,'templates')
         os.system('touch {}'.format(os.path.join(templatedir,filename)))
         fp = open(os.path.join(templatedir,filename),'w')
         fp.write(body+'\n')
         fp.close()
         flash('you have created a new template named: {}'.format(template.name))
         return self.redirect('admin.templates')
     else:
         flash('You need to give the template a name')
     return self.render()
Пример #2
0
 def post(self,item_id=None):
     from page.models import Template
     if self._form().validate():
         template = Template(name=self._form().name.data,body=self._form().body.data)
         template.save()
         self.flash("created new template")
     return self.redirect('admin.index')
Пример #3
0
 def post(self):
     from page.models import Template
     from auth.models import User
     from ext import db
     self._form = model_form(Template,db.session,base_class=Form,exclude=['blocks','pages','body'])(request.form)
     if self._form.validate():
         template = Template()
         self._form.populate_obj(template)
         template.save()
         filename = template.filename
         if template.body is not None:
             body = template.body[:]
         else:
             body = ''
         from settings import BaseConfig
         import os
         templatedir = os.path.join(BaseConfig.ROOT_PATH,'templates')
         os.system('touch {}'.format(os.path.join(templatedir,filename)))
         fp = open(os.path.join(templatedir,filename),'w')
         fp.write(body+'\n')
         fp.close()
         flash('you have created a new template named: {}'.format(template.name))
         return self.redirect('admin.templates')
     else:
         flash('You need to give the template a name')
     return self.render()
Пример #4
0
    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()
Пример #5
0
 def check_templates():
     from page.models import Template
     from auth.models import User
     from app import app
     from blog.models import Article
     from .utils import fix_unicode
     templates = Template.query.all()
     template_dir = app.config['ROOT_PATH'] + '/' + 'templates'
     if not os.path.exists(template_dir):
         os.mkdir(template_dir)
     names = [t.name for t in templates]
     for t in os.listdir(template_dir):
         if not t in names:
             temp = Template()
             temp.name = t
             temp.location = os.path.join(template_dir,t)
             temp.save()
Пример #6
0
    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()
Пример #7
0
 def check_templates():
     from ..page.models import Template
     from ..auth.models import User
     from flask import current_app
     templates = Template.query.all()
     template_dir = current_app.config['ROOT_PATH'] + '/' + 'templates'
     if not os.path.exists(template_dir):
         os.mkdir(template_dir)
     names = [t.name for t in templates]
     for t in os.listdir(template_dir):
         if not t in names:
             temp = Template()
             temp.name = t
             temp.filename = os.path.join(template_dir,t)
             temp.body = open(os.path.join(template_dir,t),'r').read()
             temp.save()
Пример #8
0
 def check_templates():
     from page.models import Template
     from auth.models import User
     from app import app
     from blog.models import Article
     from .utils import fix_unicode
     templates = Template.query.all()
     template_dir = app.config['ROOT_PATH'] + '/' + 'templates'
     if not os.path.exists(template_dir):
         os.mkdir(template_dir)
     names = [t.name for t in templates]
     for t in os.listdir(template_dir):
         if not t in names:
             temp = Template()
             temp.name = t
             temp.location = os.path.join(template_dir, t)
             temp.save()