Beispiel #1
0
	def on_update(self, page_name=None):
		self.setup_generator()
		if self._website_config.condition_field:
			if not self.doc.fields.get(self._website_config.condition_field):
				# condition field failed, return
				remove_page(self.doc.fields.get(self._website_config.page_name_field))
				return

		if not page_name:
			new_page_name = cleanup_page_name(self.get_page_title() \
				if hasattr(self, "get_page_title") else (self.doc.title or self.doc.name))
			self.check_if_page_name_is_unique(new_page_name)
	
			remove_page(self.doc.page_name)

			if self.doc.fields.get(self._website_config.page_name_field)!=new_page_name: 
				webnotes.conn.set(self.doc, self._website_config.page_name_field, new_page_name)
				
			page_name = new_page_name

		add_to_sitemap(webnotes._dict({
			"ref_doctype":self.doc.doctype, 
			"docname": self.doc.name, 
			"page_name": page_name,
			"link_name": self._website_config.name,
			"lastmod": webnotes.utils.get_datetime(self.doc.modified).strftime("%Y-%m-%d")
		}))
	def after_insert(self):
		if self.doc.page_or_generator == "Page":
			lastmod = datetime.datetime.fromtimestamp(float(self.doc.fields.lastmod)).strftime("%Y-%m-%d")
			add_to_sitemap(self.doc.fields.copy().update({"lastmod": lastmod}))
		else:
			condition = ""
			if self.doc.condition_field:
				condition = " where ifnull(%s, 0)=1" % self.doc.condition_field
			
			for name in webnotes.conn.sql_list("""select name from `tab%s` %s""" \
				% (self.doc.ref_doctype, condition)):
				webnotes.bean(self.doc.ref_doctype, name).run_method("on_update")
    def after_insert(self):
        if self.doc.page_or_generator == "Page":
            lastmod = datetime.datetime.fromtimestamp(
                float(self.doc.fields.lastmod)).strftime("%Y-%m-%d")
            add_to_sitemap(self.doc.fields.copy().update({"lastmod": lastmod}))
        else:
            condition = ""
            if self.doc.condition_field:
                condition = " where ifnull(%s, 0)=1" % self.doc.condition_field

            for name in webnotes.conn.sql_list("""select name from `tab%s` %s""" \
             % (self.doc.ref_doctype, condition)):
                webnotes.bean(self.doc.ref_doctype,
                              name).run_method("on_update")