<commit_before># Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import cint
from frappe.utils.nestedset import DocTypeNestedSet

sitemap_fields = ("page_name", "ref_doctype", "docname", "page_or_generator", "idx",
	"lastmod", "parent_website_sitemap", "public_read", "public_write", "page_title")

class DocType(DocTypeNestedSet):
	def __init__(self, d, dl):
		self.doc, self.doclist = d, dl
		self.nsm_parent_field = "parent_website_sitemap"
		
	def autoname(self):
		self.doc.name = self.get_url()

	def get_url(self):
		url = self.doc.page_name
		if self.doc.parent_website_sitemap:
			url = self.doc.parent_website_sitemap + "/" + url
			
		return url
		
	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()
		if not self.doc.is_new():
			self.renumber_if_moved()
		self.set_idx()

	def renumber_if_moved(self):
		if self.doc.old_parent != self.doc.parent_website_sitemap:
			frappe.conn.sql("""update `tabWebsite Sitemap` set idx=idx-1 
				where parent_website_sitemap=%s and idx>%s""", (self.doc.old_parent, self.doc.idx))
			frappe.conn.sql("""update `tab{0}` set idx=idx-1 
				where parent_website_sitemap=%s and idx>%s""".format(self.doc.ref_doctype), 
					(self.doc.old_parent, self.doc.idx))
			self.doc.idx = None
	
	def set_idx(self):
		if self.doc.idx==None:
			self.doc.idx = int(frappe.conn.sql("""select ifnull(max(ifnull(idx, -1)), -1) 
				from `tabWebsite Sitemap`
				where ifnull(parent_website_sitemap, '')=%s and name!=%s""", 
					(self.doc.parent_website_sitemap or '',
					self.doc.name))[0][0]) + 1
			
		else:
			if self.doc.parent_website_sitemap:
				self.doc.idx = cint(self.doc.idx)
				previous_idx = frappe.conn.sql("""select max(idx) 
						from `tab{}` where ifnull(parent_website_sitemap, '')=%s 
						and ifnull(idx, -1) < %s""".format(self.doc.ref_doctype), 
						(self.doc.parent_website_sitemap, self.doc.idx))[0][0]
					<commit_msg>fix to sitemap<commit_after># Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import cint
from frappe.utils.nestedset import DocTypeNestedSet

sitemap_fields = ("page_name", "ref_doctype", "docname", "page_or_generator", "idx",
	"lastmod", "parent_website_sitemap", "public_read", "public_write", "page_title")

class DocType(DocTypeNestedSet):
	def __init__(self, d, dl):
		self.doc, self.doclist = d, dl
		self.nsm_parent_field = "parent_website_sitemap"
		
	def autoname(self):
		self.doc.name = self.get_url()

	def get_url(self):
		url = self.doc.page_name
		if self.doc.parent_website_sitemap:
			url = self.doc.parent_website_sitemap + "/" + url
			
		return url
		
	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()
		if not self.doc.is_new():
			self.renumber_if_moved()
		self.set_idx()

	def renumber_if_moved(self):
		current_parent = frappe.conn.get_value("Website Sitemap", self.doc.name, "parent_website_sitemap")
		if current_parent and current_parent != self.doc.parent_website_sitemap:
			# move-up
			
			# sitemap
			frappe.conn.sql("""update `tabWebsite Sitemap` set idx=idx-1 
				where parent_website_sitemap=%s and idx>%s""", (current_parent, self.doc.idx))
				
			# source table
			frappe.conn.sql("""update `tab{0}` set idx=idx-1 
				where parent_website_sitemap=%s and idx>%s""".format(self.doc.ref_doctype), 
					(current_parent, self.doc.idx))
			self.doc.idx = None
	
	def set_idx(self):
		if self.doc.idx==None:
			self.doc.idx = int(frappe.conn.sql("""select ifnull(max(ifnull(idx, -1)), -1) 
				from `tabWebsite Sitemap`
				where ifnull(parent_website_sitemap, '')=%s and name!=%s""", 
					(self.doc.parent_website_sitemap or '',
					self.doc.name))[0][0]) + 1
			
		else:
			if self.doc.parent_website_sitemap:
				self.doc.idx = cint(self.doc.idx)
				previous_idx = frappe.conn.sql("""select max(idx) 
						from `tab{}` where ifnull(parent_website_sitemap, '')=%s 
						and ifnull(idx, -1) < %s""".format(self.doc.ref_doctype), 
						(self.doc.parent_website_sitemap, self.doc.idx))[0][0]
					
{'fraction_non_alphanumeric': 0.14298622091709962, 'fraction_numerical': 0.00677659814772984, 'mean_word_length': 4.265160523186682, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1560920', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1694, 'n_words': 315}