Browse Source

fixed sitemap patch

version-14
Rushabh Mehta 11 years ago
parent
commit
e660fde74e
4 changed files with 50 additions and 25 deletions
  1. +3
    -1
      frappe/cli.py
  2. +1
    -1
      frappe/modules/__init__.py
  3. +11
    -1
      frappe/patches/4_0/set_website_sitemap_idx.py
  4. +35
    -22
      frappe/website/doctype/website_sitemap_config/website_sitemap_config.py

+ 3
- 1
frappe/cli.py View File

@@ -466,9 +466,11 @@ def reset_perms():
@cmd
def execute(method):
frappe.connect()
frappe.get_attr(method)()
ret = frappe.get_attr(method)()
frappe.conn.commit()
frappe.destroy()
if ret:
print ret

# scheduler
@cmd


+ 1
- 1
frappe/modules/__init__.py View File

@@ -32,7 +32,7 @@ def get_doc_path(module, doctype, name):

def reload_doc(module, dt=None, dn=None, force=True):
from frappe.modules.import_file import import_files
return import_files(module, dt, dn, force=force)
return import_files(scrub(module), scrub(dt), scrub(dn), force=force)

def export_doc(doctype, name, module=None):
"""write out a doc"""


+ 11
- 1
frappe/patches/4_0/set_website_sitemap_idx.py View File

@@ -1,7 +1,17 @@
import frappe

def execute():
frappe.reload_doc("website", "doctype", "blog_post")
from frappe.website.doctype.website_sitemap_config.website_sitemap_config import \
get_pages_and_generators, get_template_controller


for app in frappe.get_installed_apps():
pages, generators = get_pages_and_generators(app)
for g in generators:
doctype = frappe.get_attr(get_template_controller(app, g[2], g[3]) + ".doctype")
module = frappe.conn.get_value("DocType", doctype, "module")
frappe.reload_doc(module, "doctype", doctype)
frappe.conn.sql("""update `tabWebsite Sitemap` set idx=null""")
for doctype in ["Blog Category", "Blog Post", "Web Page", "Website Group"]:
frappe.conn.sql("""update `tab{}` set idx=null""".format(doctype))


+ 35
- 22
frappe/website/doctype/website_sitemap_config/website_sitemap_config.py View File

@@ -60,48 +60,51 @@ def rebuild_website_sitemap_config():
rebuild_tree("Website Sitemap", "parent_website_sitemap")
frappe.conn.commit()


def build_website_sitemap_config(app):
config = {"pages": {}, "generators":{}}
basepath = frappe.get_pymodule_path(app)
pages, generators = get_pages_and_generators(app)
for args in pages:
add_website_sitemap_config(*args)

for args in generators:
add_website_sitemap_config(*args)
frappe.conn.commit()

def get_pages_and_generators(app):
pages = []
generators = []
app_path = frappe.get_app_path(app)

for config_type in ("pages", "generators"):
path = os.path.join(basepath, "templates", config_type)
path = os.path.join(app_path, "templates", config_type)
if os.path.exists(path):
for fname in os.listdir(path):
fname = frappe.utils.cstr(fname)
if fname.split(".")[-1] in ("html", "xml", "js", "css"):
if config_type=="pages":
pages.append(["Page", app, path, fname, basepath])
pages.append(["Page", app, path, fname, app_path])
else:
generators.append(["Generator", app, path, fname, basepath])

for args in pages:
add_website_sitemap_config(*args)

for args in generators:
add_website_sitemap_config(*args)
frappe.conn.commit()

def add_website_sitemap_config(page_or_generator, app, path, fname, basepath):
generators.append(["Generator", app, path, fname, app_path])
return pages, generators
def add_website_sitemap_config(page_or_generator, app, path, fname, app_path):
name = fname[:-5] if fname.endswith(".html") else fname
wsc = frappe._dict({
"doctype": "Website Sitemap Config",
"page_or_generator": page_or_generator,
"link_name": name,
"template_path": os.path.relpath(os.path.join(path, fname), basepath),
"template_path": os.path.relpath(os.path.join(path, fname), app_path),
})
controller_name = fname.split(".")[0].replace("-", "_") + ".py"
controller_path = os.path.join(path, controller_name)
if os.path.exists(controller_path):
wsc.controller = app + "." + os.path.relpath(controller_path[:-3], basepath).replace(os.path.sep, ".")

wsc.controller = get_template_controller(app, path, fname)
if wsc.controller:
# verbose print wsc.controller
module = frappe.get_module(wsc.controller)
@@ -123,3 +126,13 @@ def add_website_sitemap_config(page_or_generator, app, path, fname, basepath):
frappe.bean(wsc).insert()
return name
def get_template_controller(app, path, fname):
controller = None
controller_name = fname.split(".")[0].replace("-", "_") + ".py"
controller_path = os.path.join(path, controller_name)
if os.path.exists(controller_path):
controller = app + "." + os.path.relpath(controller_path[:-3], frappe.get_app_path(app)).replace(os.path.sep, ".")
return controller

Loading…
Cancel
Save