Просмотр исходного кода

Merge pull request #16559 from frappe/sitemap-publish-condition

fix: sitemap condition
version-14
mergify[bot] 3 лет назад
committed by GitHub
Родитель
Сommit
fcb86d7f96
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
1 измененных файлов: 24 добавлений и 16 удалений
  1. +24
    -16
      frappe/www/sitemap.py

+ 24
- 16
frappe/www/sitemap.py Просмотреть файл

@@ -1,11 +1,11 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE # License: MIT. See LICENSE


from urllib.parse import quote from urllib.parse import quote


import frappe import frappe
from frappe.model.document import get_controller from frappe.model.document import get_controller
from frappe.utils import get_datetime, get_url, nowdate
from frappe.utils import get_url, nowdate
from frappe.website.router import get_pages from frappe.website.router import get_pages


no_cache = 1 no_cache = 1
@@ -14,13 +14,8 @@ base_template_path = "www/sitemap.xml"


def get_context(context): def get_context(context):
"""generate the sitemap XML""" """generate the sitemap XML"""

# the site might be accessible from multiple host_names
# for e.g gadgets.erpnext.com and gadgetsinternational.com
# so it should be picked from the request
host = frappe.utils.get_host_name_from_request()

links = [] links = []

for route, page in get_pages().items(): for route, page in get_pages().items():
if page.sitemap: if page.sitemap:
links.append({"loc": get_url(quote(page.name.encode("utf-8"))), "lastmod": nowdate()}) links.append({"loc": get_url(quote(page.name.encode("utf-8"))), "lastmod": nowdate()})
@@ -29,7 +24,7 @@ def get_context(context):
links.append( links.append(
{ {
"loc": get_url(quote((route or "").encode("utf-8"))), "loc": get_url(quote((route or "").encode("utf-8"))),
"lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d"),
"lastmod": f"{data['modified']:%Y-%m-%d}",
} }
) )


@@ -41,24 +36,37 @@ def get_public_pages_from_doctypes():


def get_sitemap_routes(): def get_sitemap_routes():
routes = {} routes = {}
doctypes_with_web_view = [
d.name for d in frappe.db.get_all("DocType", {"has_web_view": 1, "allow_guest_to_view": 1})
]
doctypes_with_web_view = frappe.get_all(
"DocType",
filters={"has_web_view": True, "allow_guest_to_view": True},
pluck="name",
)


for doctype in doctypes_with_web_view: for doctype in doctypes_with_web_view:
controller = get_controller(doctype) controller = get_controller(doctype)
meta = frappe.get_meta(doctype) meta = frappe.get_meta(doctype)
condition_field = meta.is_published_field or controller.website.condition_field condition_field = meta.is_published_field or controller.website.condition_field


try:
res = frappe.db.get_all(doctype, ["route", "name", "modified"], {condition_field: 1})
for r in res:
routes[r.route] = {"doctype": doctype, "name": r.name, "modified": r.modified}
if not condition_field:
continue


try:
res = frappe.get_all(
doctype,
fields=["route", "name", "modified"],
filters={condition_field: True},
)
except Exception as e: except Exception as e:
if not frappe.db.is_missing_column(e): if not frappe.db.is_missing_column(e):
raise e raise e


for r in res:
routes[r.route] = {
"doctype": doctype,
"name": r.name,
"modified": r.modified,
}

return routes return routes


return frappe.cache().get_value("sitemap_routes", get_sitemap_routes) return frappe.cache().get_value("sitemap_routes", get_sitemap_routes)

Загрузка…
Отмена
Сохранить