Browse Source

minor

version-14
Rushabh Mehta 11 years ago
parent
commit
bc9f78f72f
2 changed files with 28 additions and 14 deletions
  1. +3
    -2
      webnotes/website/doctype/post/post.py
  2. +25
    -12
      webnotes/website/doctype/web_page/web_page.py

+ 3
- 2
webnotes/website/doctype/post/post.py View File

@@ -9,8 +9,6 @@ import webnotes
from webnotes.utils import get_fullname
from webnotes.utils.email_lib.bulk import send
from webnotes.utils.email_lib import sendmail
from webnotes.templates.generators.website_group import clear_cache
from webnotes.templates.website_group.post import clear_post_cache

class DocType:
def __init__(self, d, dl):
@@ -39,6 +37,9 @@ class DocType:
self.doc.event_datetime = None
def on_update(self):
from webnotes.templates.website_group.post import clear_post_cache
from webnotes.templates.generators.website_group import clear_cache

clear_cache(website_group=self.doc.website_group)
clear_post_cache(self.doc.parent_post or self.doc.name)



+ 25
- 12
webnotes/website/doctype/web_page/web_page.py View File

@@ -2,7 +2,7 @@
# MIT License. See license.txt

from __future__ import unicode_literals
import webnotes, os
import webnotes, os, time
from webnotes.webutils import WebsiteGenerator
from webnotes import _
from webnotes.utils import cint
@@ -35,8 +35,14 @@ class DocType(WebsiteGenerator):
if self.doclist.get({"parentfield": "toc"}):
from webnotes.webutils import clear_cache
clear_cache()
def sync_statics():
while True:
_sync_statics()
webnotes.conn.commit()
time.sleep(2)

def _sync_statics():
synced = []
to_insert = []
@@ -56,8 +62,9 @@ def sync_statics():
page = webnotes.bean("Web Page", sitemap.doc.docname)
title, content = get_static_content(fpath)
page.doc.main_section = content
if title:
page.doc.title = title
if not title:
title = page_name.replace("-", " ").replace("_", " ").title()
page.doc.title = title
page.save()

sitemap = webnotes.bean("Website Sitemap", url)
@@ -88,6 +95,7 @@ def sync_statics():
for basepath, folders, files in os.walk(statics_path):
# index file first!
index = []
has_index = False
if "index.txt" in files:
with open(os.path.join(basepath, "index.txt"), "r") as indexfile:
index = indexfile.read().splitlines()
@@ -96,11 +104,15 @@ def sync_statics():
page_name = fname.rsplit(".", 1)[0]
if page_name=="index" and fname!="index.txt":
sync_file(fname, os.path.join(basepath, fname), statics_path)
has_index = True
break
if not has_index:
continue
# other files
for fname in files:
page_name = fname.rsplit(".", 1)[0]
page_name = fname.rsplit(".", 1)[0]
if page_name!="index":
sync_file(fname, os.path.join(basepath, fname), statics_path,
index.index(page_name) if page_name in index else 0)
@@ -132,14 +144,15 @@ def get_static_content(fpath):
content = unicode(contentfile.read(), 'utf-8')

if fpath.endswith(".md"):
lines = content.splitlines()
first_line = lines[0].strip()
if content:
lines = content.splitlines()
first_line = lines[0].strip()

if first_line.startswith("# "):
title = first_line[2:]
content = "\n".join(lines[1:])
if first_line.startswith("# "):
title = first_line[2:]
content = "\n".join(lines[1:])

content = markdown(content)
content = markdown(content)
content = unicode(content.encode("utf-8"), 'utf-8')


Loading…
Cancel
Save