ソースを参照

added feature to sync static files

version-14
Rushabh Mehta 11年前
コミット
1d64ba81be
5個のファイルの変更102行の追加4行の削除
  1. +10
    -0
      webnotes/cli.py
  2. +1
    -1
      webnotes/model/sync.py
  3. +65
    -1
      webnotes/website/doctype/web_page/web_page.py
  4. +19
    -1
      webnotes/website/doctype/web_page/web_page.txt
  5. +7
    -1
      webnotes/website/doctype/website_sitemap/website_sitemap.txt

+ 10
- 0
webnotes/cli.py ファイルの表示

@@ -188,6 +188,8 @@ def setup_utilities(parser):
help="Clear website cache") help="Clear website cache")
parser.add_argument("--build_sitemap", default=False, action="store_true", parser.add_argument("--build_sitemap", default=False, action="store_true",
help="Build Website Sitemap") 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", parser.add_argument("--clear_cache", default=False, action="store_true",
help="Clear cache, doctype cache and defaults") help="Clear cache, doctype cache and defaults")
parser.add_argument("--reset_perms", default=False, action="store_true", parser.add_argument("--reset_perms", default=False, action="store_true",
@@ -441,6 +443,14 @@ def build_sitemap():
rebuild_config() rebuild_config()
webnotes.destroy() 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 @cmd
def reset_perms(): def reset_perms():
webnotes.connect() webnotes.connect()


+ 1
- 1
webnotes/model/sync.py ファイルの表示

@@ -17,7 +17,7 @@ def sync_all(force=0):
webnotes.clear_cache() webnotes.clear_cache()


def sync_for(app_name, force=0, sync_everything = False, verbose=False): 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__) folder = os.path.dirname(webnotes.get_module(app_name + "." + module_name).__file__)
walk_and_sync(folder, force, sync_everything, verbose=verbose) walk_and_sync(folder, force, sync_everything, verbose=verbose)




+ 65
- 1
webnotes/website/doctype/web_page/web_page.py ファイルの表示

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


from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes
import webnotes, os
from webnotes.webutils import WebsiteGenerator from webnotes.webutils import WebsiteGenerator
from webnotes import _ from webnotes import _
from markdown2 import markdown


class DocType(WebsiteGenerator): class DocType(WebsiteGenerator):
def autoname(self): def autoname(self):
@@ -37,3 +38,66 @@ class DocType(WebsiteGenerator):
if self.doclist.get({"parentfield": "toc"}): if self.doclist.get({"parentfield": "toc"}):
from webnotes.webutils import clear_cache from webnotes.webutils import clear_cache
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

+ 19
- 1
webnotes/website/doctype/web_page/web_page.txt ファイルの表示

@@ -2,7 +2,7 @@
{ {
"creation": "2013-03-28 10:35:30", "creation": "2013-03-28 10:35:30",
"docstatus": 0, "docstatus": 0,
"modified": "2014-02-10 16:17:48",
"modified": "2014-02-10 18:07:28",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@@ -138,6 +138,12 @@
"label": "Text Align", "label": "Text Align",
"options": "Left\nCenter\nRight" "options": "Left\nCenter\nRight"
}, },
{
"doctype": "DocField",
"fieldname": "custom_javascript",
"fieldtype": "Section Break",
"label": "Custom Javascript"
},
{ {
"description": "Add code as <script>", "description": "Add code as <script>",
"doctype": "DocField", "doctype": "DocField",
@@ -153,6 +159,12 @@
"label": "Javascript", "label": "Javascript",
"options": "Javascript" "options": "Javascript"
}, },
{
"doctype": "DocField",
"fieldname": "custom_css",
"fieldtype": "Section Break",
"label": "Custom CSS"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "insert_style", "fieldname": "insert_style",
@@ -167,6 +179,12 @@
"label": "CSS", "label": "CSS",
"options": "CSS" "options": "CSS"
}, },
{
"doctype": "DocField",
"fieldname": "table_of_contents",
"fieldtype": "Section Break",
"label": "Table of Contents"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "show_title", "fieldname": "show_title",


+ 7
- 1
webnotes/website/doctype/website_sitemap/website_sitemap.txt ファイルの表示

@@ -2,7 +2,7 @@
{ {
"creation": "2013-11-18 15:38:40", "creation": "2013-11-18 15:38:40",
"docstatus": 0, "docstatus": 0,
"modified": "2014-01-30 16:50:49",
"modified": "2014-02-10 18:10:11",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@@ -137,6 +137,12 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "Anyone Can Write" "label": "Anyone Can Write"
}, },
{
"doctype": "DocField",
"fieldname": "static_file_timestamp",
"fieldtype": "Data",
"label": "Static File Timestamp"
},
{ {
"doctype": "DocPerm" "doctype": "DocPerm"
} }

読み込み中…
キャンセル
保存