Permalink
Browse files

use new preview model for templates

  • Loading branch information...
syegulalp committed Sep 2, 2017
1 parent 208ca3e commit 038d3610312ef28ddd3b7406136b3048a291125c
Showing with 9 additions and 41 deletions.
  1. +4 −0 mercury/core/models/__init__.py
  2. +5 −41 mercury/core/ui/template.py
@@ -2314,6 +2314,10 @@ class Template(BaseModel, DateMod):
default_type = CharField(max_length=32, default=None, null=True)
template_ref = TextField(null=True)
def delete_preview(self):
for n in self.fileinfos:
n.clear_preview()
def delete_instance(self, *a, **ka):
# eventually we shouldn't need these once we have all the proper
# ID refs set up
@@ -336,7 +336,7 @@ def template_edit_save(template_id):
message_list=(e,))
else:
template_preview_delete(tpl)
tpl.delete_preview()
status = Status(
type='success',
message="Template <b>{}</b> saved successfully. {}".format(tpl.for_display,
@@ -480,52 +480,16 @@ def template_preview_core(template_id):
end - start,
tpl_output)
preview = template.preview_path(fi)
preview_file_path, preview_url = fi.make_preview()
from core.cms.queue import write_file
write_file(tpl_output,
preview['path'], # blog_path,
preview['file'] # file_path)
)
import settings
if settings.DESKTOP_MODE:
url = settings.BASE_URL_ROOT + '/' + preview['subpath'] + '/' + preview['file'] + '?_={}'.format(
template.blog.id)
else:
url = template.blog.url + '/' + preview['subpath'] + '/' + preview['file']
from core.cms import queue
queue.write_file(tpl_output, template.blog.path, preview_file_path)
return ("{}?_={}".format(
url,
preview_url,
template.modified_date.microsecond
))
def template_preview_delete(tpl):
'''
Deletes a template preview.
Typically invoked after a page is edited, saved, or published.
'''
try:
preview = tpl.preview_path()
except:
return None
if preview is None:
return None
import os
try:
return os.remove(os.path.join(preview['path'], preview['file']))
except OSError as e:
from core.error import not_found
if not_found(e) is False:
raise e
except Exception as e:
raise e
def template_edit_output(tags):
return template('edit/template',

0 comments on commit 038d361

Please sign in to comment.