Esempio n. 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()
Esempio n. 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')
Esempio n. 3
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()
Esempio n. 4
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()