more fixes
This commit is contained in:
parent
7c8ebaa820
commit
438efbd965
5 changed files with 42 additions and 13 deletions
|
|
@ -293,6 +293,9 @@ class Bean:
|
|||
def has_permission(self, permtype):
|
||||
return frappe.has_permission(self.doc.doctype, permtype, self.doc)
|
||||
|
||||
def update_value(self, field, value):
|
||||
frappe.conn.set(self.doc, field, value)
|
||||
|
||||
def save(self, check_links=1, ignore_permissions=None):
|
||||
if ignore_permissions:
|
||||
self.ignore_permissions = ignore_permissions
|
||||
|
|
|
|||
|
|
@ -879,7 +879,7 @@ frappe.ui.form.ControlLink = frappe.ui.form.ControlData.extend({
|
|||
me.$input.trigger("change");
|
||||
}
|
||||
}
|
||||
}).data('uiAutocomplete')._renderItem = function(ul, d) {
|
||||
}).data('ui-autocomplete')._renderItem = function(ul, d) {
|
||||
var html = "";
|
||||
if(keys(d).length > 1) {
|
||||
d.info = $.map(d, function(val, key) { return ["value", "label"].indexOf(key)!==-1 ? null : val }).join(", ") || "";
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -33,8 +33,13 @@ class DocType:
|
|||
if self.doc.condition_field:
|
||||
condition = " where ifnull(%s, 0)=1" % self.doc.condition_field
|
||||
|
||||
for name in frappe.conn.sql_list("""select name from `tab%s` %s""" \
|
||||
% (self.doc.ref_doctype, condition)):
|
||||
for name in frappe.conn.sql_list("""select name from `tab{doctype}`
|
||||
{condition} order by {sort_field} {sort_order}""".format(
|
||||
doctype = self.doc.ref_doctype,
|
||||
condition = condition,
|
||||
sort_field = self.doc.sort_field or "name",
|
||||
sort_order = self.doc.sort_order or "asc"
|
||||
)):
|
||||
frappe.bean(self.doc.ref_doctype, name).run_method("on_update")
|
||||
|
||||
def rebuild_website_sitemap_config():
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class WebsiteGenerator(DocListController):
|
|||
opts = frappe._dict({
|
||||
"page_or_generator": "Generator",
|
||||
"ref_doctype":self.doc.doctype,
|
||||
"idx": self.doc.idx,
|
||||
"docname": self.doc.name,
|
||||
"page_name": page_name,
|
||||
"link_name": self._website_config.name,
|
||||
|
|
@ -78,9 +79,12 @@ class WebsiteGenerator(DocListController):
|
|||
self.update_permissions(opts)
|
||||
|
||||
if existing_site_map:
|
||||
update_sitemap(existing_site_map, opts)
|
||||
idx = update_sitemap(existing_site_map, opts)
|
||||
else:
|
||||
add_to_sitemap(opts)
|
||||
idx = add_to_sitemap(opts)
|
||||
|
||||
if idx and self.doc.idx != idx:
|
||||
self.update_value("idx", idx)
|
||||
|
||||
def update_permissions(self, opts):
|
||||
if self.meta.get_field("public_read"):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue