|
|
@@ -6,7 +6,7 @@ import frappe |
|
|
|
from frappe import _ |
|
|
|
from frappe.utils.nestedset import DocTypeNestedSet |
|
|
|
|
|
|
|
sitemap_fields = ("page_name", "ref_doctype", "docname", "page_or_generator", |
|
|
|
sitemap_fields = ("page_name", "ref_doctype", "docname", "page_or_generator", "idx", |
|
|
|
"lastmod", "parent_website_sitemap", "public_read", "public_write", "page_title") |
|
|
|
|
|
|
|
class DocType(DocTypeNestedSet): |
|
|
@@ -18,22 +18,35 @@ class DocType(DocTypeNestedSet): |
|
|
|
self.doc.name = self.get_url() |
|
|
|
|
|
|
|
def get_url(self): |
|
|
|
parent_website_sitemap = self.get_parent_website_sitemap() |
|
|
|
url = self.doc.page_name |
|
|
|
if parent_website_sitemap: |
|
|
|
url = parent_website_sitemap + "/" + url |
|
|
|
if self.doc.parent_website_sitemap: |
|
|
|
url = self.doc.parent_website_sitemap + "/" + url |
|
|
|
|
|
|
|
return url |
|
|
|
|
|
|
|
def get_parent_website_sitemap(self): |
|
|
|
return self.doc.parent_website_sitemap |
|
|
|
|
|
|
|
|
|
|
|
def validate(self): |
|
|
|
if self.get_url() != self.doc.name: |
|
|
|
self.rename() |
|
|
|
self.check_if_page_name_is_unique() |
|
|
|
self.make_private_if_parent_is_private() |
|
|
|
self.set_idx() |
|
|
|
|
|
|
|
def set_idx(self): |
|
|
|
if self.doc.idx==None: |
|
|
|
self.doc.idx = int(frappe.conn.sql("""select max(idx) from `tabWebsite Sitemap` |
|
|
|
where parent_website_sitemap=%s and name!=%s""", (self.doc.parent_website_sitemap, |
|
|
|
self.doc.name))[0][0] or 0) + 1 |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
if self.doc.idx != 0: |
|
|
|
if not frappe.conn.get_value("Website Sitemap", { |
|
|
|
"idx": self.doc.idx -1, |
|
|
|
"parent_website_sitemap":self.doc.parent_website_sitemap |
|
|
|
}): |
|
|
|
frappe.throw("{}: {}".format( |
|
|
|
_("Sitemap Ordering Error. Index missing"), self.doc.idx-1)) |
|
|
|
|
|
|
|
def rename(self): |
|
|
|
from frappe.website.render import clear_cache |
|
|
|
self.old_name = self.doc.name |
|
|
@@ -107,6 +120,8 @@ def add_to_sitemap(options): |
|
|
|
|
|
|
|
bean.insert(ignore_permissions=True) |
|
|
|
|
|
|
|
return bean.doc.idx |
|
|
|
|
|
|
|
def update_sitemap(website_sitemap, options): |
|
|
|
bean = frappe.bean("Website Sitemap", website_sitemap) |
|
|
|
|
|
|
@@ -118,6 +133,8 @@ def update_sitemap(website_sitemap, options): |
|
|
|
|
|
|
|
bean.doc.website_sitemap_config = options.link_name |
|
|
|
bean.save(ignore_permissions=True) |
|
|
|
|
|
|
|
return bean.doc.idx |
|
|
|
|
|
|
|
def remove_sitemap(page_name=None, ref_doctype=None, docname=None): |
|
|
|
if page_name: |
|
|
|