瀏覽代碼

[cleanup] rename functions in website and router for cleaner meaning

version-14
Rushabh Mehta 9 年之前
父節點
當前提交
6824df7ac9
共有 5 個檔案被更改,包括 31 行新增31 行删除
  1. +2
    -2
      frappe/templates/pages/sitemap.py
  2. +2
    -2
      frappe/website/context.py
  3. +23
    -23
      frappe/website/router.py
  4. +1
    -1
      frappe/website/utils.py
  5. +3
    -3
      frappe/website/website_generator.py

+ 2
- 2
frappe/templates/pages/sitemap.py 查看文件

@@ -6,7 +6,7 @@ from __future__ import unicode_literals
import urllib
import frappe
from frappe.utils import get_request_site_address, get_datetime, nowdate
from frappe.website.router import get_pages, get_generator_routes
from frappe.website.router import get_pages, get_page_context_from_doctypes

no_cache = 1
no_sitemap = 1
@@ -23,7 +23,7 @@ def get_context(context):
"lastmod": nowdate()
})

for route, data in get_generator_routes().iteritems():
for route, data in get_page_context_from_doctypes().iteritems():
links.append({
"loc": urllib.basejoin(host, urllib.quote((route or "").encode("utf-8"))),
"lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d")


+ 2
- 2
frappe/website/context.py 查看文件

@@ -5,10 +5,10 @@ from __future__ import unicode_literals
import frappe

from frappe.website.doctype.website_settings.website_settings import get_website_settings
from frappe.website.router import get_route_info
from frappe.website.router import get_page_context

def get_context(path, args=None):
context = get_route_info(path)
context = get_page_context(path)

if args:
context.update(args)


+ 23
- 23
frappe/website/router.py 查看文件

@@ -7,23 +7,21 @@ import frappe, os
from frappe.website.utils import can_cache, delete_page_cache
from frappe.model.document import get_controller

def get_route_info(path):
sitemap_options = None
cache_key = "sitemap_options:{0}:{1}".format(path, frappe.local.lang)

def get_page_context(path):
page_context = None
if can_cache():
sitemap_options_cache = frappe.cache().hget("sitemap_options", path) or {}
sitemap_options = sitemap_options_cache.get(frappe.local.lang, None)
page_context_cache = frappe.cache().hget("page_context", path) or {}
page_context = page_context_cache.get(frappe.local.lang, None)

if not sitemap_options:
sitemap_options = build_route(path)
if can_cache(sitemap_options.no_cache):
sitemap_options_cache[frappe.local.lang] = sitemap_options
frappe.cache().hset("sitemap_options", path, sitemap_options_cache)
if not page_context:
page_context = make_page_context(path)
if can_cache(page_context.no_cache):
page_context_cache[frappe.local.lang] = page_context
frappe.cache().hset("page_context", path, page_context_cache)

return sitemap_options
return page_context

def build_route(path):
def make_page_context(path):
context = resolve_route(path)
if not context:
raise frappe.DoesNotExistError
@@ -41,20 +39,22 @@ def resolve_route(path):
The only exceptions are `/about` and `/contact` these will be searched in Web Pages
first before checking the standard pages."""
if path not in ("about", "contact"):
route = get_page_route(path)
if route: return route
return get_generator_route(path)
context = get_page_context_from_template(path)
if context:
return context
return get_page_context_from_doctype(path)
else:
route = get_generator_route(path)
if route: return route
return get_page_route(path)
context = get_page_context_from_doctype(path)
if context:
return context
return get_page_context_from_template(path)

def get_page_route(path):
def get_page_context_from_template(path):
found = filter(lambda p: p.page_name==path, get_pages())
return found[0] if found else None

def get_generator_route(path):
generator_routes = get_generator_routes()
def get_page_context_from_doctype(path):
generator_routes = get_page_context_from_doctypes()
if path in generator_routes:
route = generator_routes[path]
return frappe.get_doc(route.get("doctype"), route.get("name")).get_route_context()
@@ -62,7 +62,7 @@ def get_generator_route(path):
def clear_sitemap():
delete_page_cache("*")

def get_generator_routes():
def get_page_context_from_doctypes():
routes = frappe.cache().get_value("website_generator_routes")
if not routes:
routes = {}


+ 1
- 1
frappe/website/utils.py 查看文件

@@ -6,7 +6,7 @@ import frappe, re, os

def delete_page_cache(path):
cache = frappe.cache()
groups = ("website_page", "sitemap_options")
groups = ("website_page", "page_context")
if path:
for name in groups:
cache.hdel(name, path)


+ 3
- 3
frappe/website/website_generator.py 查看文件

@@ -9,7 +9,7 @@ from frappe.model.naming import append_number_if_name_exists
from frappe.website.utils import cleanup_page_name, get_home_page
from frappe.website.render import clear_cache
from frappe.modules import get_module_name
from frappe.website.router import get_page_route, get_route_info
from frappe.website.router import get_page_context_from_template, get_page_context

class WebsiteGenerator(Document):
website = frappe._dict(
@@ -151,7 +151,7 @@ class WebsiteGenerator(Document):

# if no parent and not home page, then parent is home page
if not _parent_val and me.get_route() != home_page:
# parents.append(frappe._dict(name=home_page, title=get_route_info(home_page).title))
# parents.append(frappe._dict(name=home_page, title=get_page_context(home_page).title))
break

elif _parent_val:
@@ -178,7 +178,7 @@ class WebsiteGenerator(Document):
else:
# parent route is a page e.g. "blog"
if me.get("parent_website_route"):
page_route = get_page_route(me.parent_website_route)
page_route = get_page_context_from_template(me.parent_website_route)
if page_route:
parents.append(frappe._dict(name = page_route.name,
title=page_route.page_title))


Loading…
取消
儲存