@@ -188,6 +188,8 @@ def setup_utilities(parser): | |||
help="Clear website cache") | |||
parser.add_argument("--build_sitemap", default=False, action="store_true", | |||
help="Build Website Sitemap") | |||
parser.add_argument("--sync_statics", default=False, action="store_true", | |||
help="Sync files from templates/statics to Web Pages") | |||
parser.add_argument("--clear_cache", default=False, action="store_true", | |||
help="Clear cache, doctype cache and defaults") | |||
parser.add_argument("--reset_perms", default=False, action="store_true", | |||
@@ -441,6 +443,14 @@ def build_sitemap(): | |||
rebuild_config() | |||
webnotes.destroy() | |||
@cmd | |||
def sync_statics(): | |||
from webnotes.website.doctype.web_page import web_page | |||
webnotes.connect() | |||
web_page.sync_statics() | |||
webnotes.conn.commit() | |||
webnotes.destroy() | |||
@cmd | |||
def reset_perms(): | |||
webnotes.connect() | |||
@@ -17,7 +17,7 @@ def sync_all(force=0): | |||
webnotes.clear_cache() | |||
def sync_for(app_name, force=0, sync_everything = False, verbose=False): | |||
for module_name in webnotes.local.app_modules[app_name]: | |||
for module_name in webnotes.local.app_modules.get(app_name) or []: | |||
folder = os.path.dirname(webnotes.get_module(app_name + "." + module_name).__file__) | |||
walk_and_sync(folder, force, sync_everything, verbose=verbose) | |||
@@ -2,9 +2,10 @@ | |||
# MIT License. See license.txt | |||
from __future__ import unicode_literals | |||
import webnotes | |||
import webnotes, os | |||
from webnotes.webutils import WebsiteGenerator | |||
from webnotes import _ | |||
from markdown2 import markdown | |||
class DocType(WebsiteGenerator): | |||
def autoname(self): | |||
@@ -37,3 +38,66 @@ class DocType(WebsiteGenerator): | |||
if self.doclist.get({"parentfield": "toc"}): | |||
from webnotes.webutils import clear_cache | |||
clear_cache() | |||
def sync_statics(): | |||
synced = [] | |||
for app in webnotes.get_installed_apps(): | |||
statics_path = webnotes.get_app_path(app, "templates", "statics") | |||
if os.path.exists(webnotes.get_app_path(app, "templates", "statics")): | |||
for basepath, folders, files in os.walk(statics_path): | |||
for fname in files: | |||
fpath = os.path.join(basepath, fname) | |||
url = os.path.relpath(fpath, statics_path).rsplit(".", 1)[0] | |||
if fname.rsplit(".", 1)[0]=="index": | |||
url = os.path.dirname(url) | |||
parent_website_sitemap = os.path.dirname(url) | |||
page_name = os.path.basename(url) | |||
try: | |||
sitemap = webnotes.bean("Website Sitemap", url) | |||
if str(os.path.getmtime(fpath))!=sitemap.doc.static_file_timestamp: | |||
page = webnotes.bean("Web Page", sitemap.doc.docname) | |||
page.doc.main_section = get_static_content(fpath) | |||
page.save() | |||
sitemap = webnotes.bean("Website Sitemap", url) | |||
sitemap.doc.static_file_timestamp = os.path.getmtime(fpath) | |||
sitemap.save() | |||
except webnotes.DoesNotExistError: | |||
page = webnotes.bean({ | |||
"doctype":"Web Page", | |||
"title": page_name.replace("-", " ").replace("_", " ").title(), | |||
"page_name": page_name, | |||
"main_section": get_static_content(fpath), | |||
"published": 1, | |||
"parent_website_sitemap": parent_website_sitemap | |||
}).insert() | |||
# update timestamp | |||
sitemap = webnotes.bean("Website Sitemap", {"ref_doctype": "Web Page", | |||
"docname": page.doc.name}) | |||
sitemap.doc.static_file_timestamp = os.path.getmtime(fpath) | |||
sitemap.save() | |||
synced.append(url) | |||
# delete not synced | |||
webnotes.delete_doc("Web Page", webnotes.conn.sql_list("""select docname from `tabWebsite Sitemap` | |||
where ifnull(static_file_timestamp,'')!='' | |||
and name not in ({}) """.format(', '.join(["%s"]*len(synced))), tuple(synced))) | |||
def get_static_content(fpath): | |||
with open(fpath, "r") as contentfile: | |||
content = contentfile.read() | |||
if fpath.endswith(".md"): | |||
content = markdown(content) | |||
return content | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2013-03-28 10:35:30", | |||
"docstatus": 0, | |||
"modified": "2014-02-10 16:17:48", | |||
"modified": "2014-02-10 18:07:28", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -138,6 +138,12 @@ | |||
"label": "Text Align", | |||
"options": "Left\nCenter\nRight" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "custom_javascript", | |||
"fieldtype": "Section Break", | |||
"label": "Custom Javascript" | |||
}, | |||
{ | |||
"description": "Add code as <script>", | |||
"doctype": "DocField", | |||
@@ -153,6 +159,12 @@ | |||
"label": "Javascript", | |||
"options": "Javascript" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "custom_css", | |||
"fieldtype": "Section Break", | |||
"label": "Custom CSS" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "insert_style", | |||
@@ -167,6 +179,12 @@ | |||
"label": "CSS", | |||
"options": "CSS" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "table_of_contents", | |||
"fieldtype": "Section Break", | |||
"label": "Table of Contents" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "show_title", | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2013-11-18 15:38:40", | |||
"docstatus": 0, | |||
"modified": "2014-01-30 16:50:49", | |||
"modified": "2014-02-10 18:10:11", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -137,6 +137,12 @@ | |||
"fieldtype": "Check", | |||
"label": "Anyone Can Write" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "static_file_timestamp", | |||
"fieldtype": "Data", | |||
"label": "Static File Timestamp" | |||
}, | |||
{ | |||
"doctype": "DocPerm" | |||
} |