@@ -18,6 +18,8 @@ web_include_css = assets/css/webnotes-web.css | |||||
web_include_js = website_script.js | web_include_js = website_script.js | ||||
web_include_css = style_settings.css | web_include_css = style_settings.css | ||||
website_clear_cache = webnotes.templates.generators.website_group.clear_cache | |||||
website_group_handler:Forum = webnotes.templates.website_group.forum | website_group_handler:Forum = webnotes.templates.website_group.forum | ||||
website_group_handler:Events = webnotes.templates.website_group.events | website_group_handler:Events = webnotes.templates.website_group.events | ||||
website_group_handler:Tasks = webnotes.templates.website_group.tasks | website_group_handler:Tasks = webnotes.templates.website_group.tasks | ||||
@@ -3,6 +3,7 @@ | |||||
import webnotes | import webnotes | ||||
from webnotes.webutils import get_access, render_blocks, can_cache | from webnotes.webutils import get_access, render_blocks, can_cache | ||||
from webnotes.templates.website_group.post import clear_post_cache | |||||
doctype = "Website Group" | doctype = "Website Group" | ||||
no_cache = 1 | no_cache = 1 | ||||
@@ -101,3 +102,23 @@ def has_access(group, view): | |||||
return access.get("write") | return access.get("write") | ||||
else: | else: | ||||
return access.get("read") | return access.get("read") | ||||
def clear_cache(page_name=None, website_group=None): | |||||
if page_name or website_group: | |||||
filters = {"page_name": page_name} if page_name else website_group | |||||
website_group = webnotes.conn.get_value("Website Group", filters, | |||||
["page_name", "group_type"], as_dict=True) | |||||
if not website_group: | |||||
return | |||||
website_groups = [website_group] | |||||
else: | |||||
clear_post_cache() | |||||
website_groups = webnotes.conn.sql("""select page_name, group_type from `tabWebsite Group`""", as_dict=True) | |||||
cache = webnotes.cache() | |||||
for group in website_groups: | |||||
for view in get_views(group.group_type): | |||||
cache.delete_value("website_group_context:{}:{}".format(group.page_name, view)) |
@@ -8,6 +8,6 @@ | |||||
{% block content %} | {% block content %} | ||||
<div class="error-content"> | <div class="error-content"> | ||||
<pre>%(error)s</pre> | |||||
<pre>{{ error }}</pre> | |||||
</div> | </div> | ||||
{% endblock %} | {% endblock %} |
@@ -9,4 +9,7 @@ no_cache = 1 | |||||
no_sitemap = 1 | no_sitemap = 1 | ||||
def get_context(context): | def get_context(context): | ||||
return render_blocks(context) | |||||
error_context = {"error": webnotes.get_traceback()} | |||||
error_context.update(context) | |||||
return render_blocks(error_context) |
@@ -9,15 +9,19 @@ def get_post_context(group_context): | |||||
post = webnotes.doc("Post", webnotes.form_dict.name) | post = webnotes.doc("Post", webnotes.form_dict.name) | ||||
if post.parent_post: | if post.parent_post: | ||||
raise webnotes.PermissionError | raise webnotes.PermissionError | ||||
def _get_post_context(): | |||||
fullname = get_fullname(post.owner) | |||||
return { | |||||
"title": "{} by {}".format(post.title, fullname), | |||||
# "group_title": group_context.get("unit_title") + " by {}".format(fullname), | |||||
"parent_post_html": get_parent_post_html(post, group_context.get("view")), | |||||
"post_list_html": get_child_posts_html(post, group_context.get("view")), | |||||
"parent_post": post.name | |||||
} | |||||
fullname = get_fullname(post.owner) | |||||
return { | |||||
"title": "{} by {}".format(post.title, fullname), | |||||
# "group_title": group_context.get("unit_title") + " by {}".format(fullname), | |||||
"parent_post_html": get_parent_post_html(post, group_context.get("view")), | |||||
"post_list_html": get_child_posts_html(post, group_context.get("view")), | |||||
"parent_post": post.name | |||||
} | |||||
cache_key = "website_group_post:".format(post.name) | |||||
return webnotes.cache().get_value(cache_key, lambda: _get_post_context()) | |||||
def get_parent_post_html(post, view): | def get_parent_post_html(post, view): | ||||
profile = webnotes.bean("Profile", post.owner).doc | profile = webnotes.bean("Profile", post.owner).doc | ||||
@@ -38,4 +42,11 @@ def get_child_posts_html(post, view): | |||||
"posts": posts, | "posts": posts, | ||||
"parent_post": post.name, | "parent_post": post.name, | ||||
"view": view | "view": view | ||||
}) | |||||
}) | |||||
def clear_post_cache(post=None): | |||||
cache = webnotes.cache() | |||||
posts = [post] if post else webnotes.conn.sql_list("select name from `tabPost`") | |||||
for post in posts: | |||||
cache.delete_value("website_group_post:{}".format(post)) |
@@ -4,7 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import webnotes | import webnotes | ||||
from webnotes.webutils import WebsiteGenerator, cleanup_page_name, delete_page_cache | |||||
from webnotes.webutils import WebsiteGenerator, cleanup_page_name, clear_cache | |||||
from webnotes import _ | from webnotes import _ | ||||
from webnotes.utils import today | from webnotes.utils import today | ||||
@@ -29,11 +29,11 @@ class DocType(WebsiteGenerator): | |||||
def on_update(self): | def on_update(self): | ||||
WebsiteGenerator.on_update(self) | WebsiteGenerator.on_update(self) | ||||
delete_page_cache("writers") | |||||
clear_cache("writers") | |||||
def clear_blog_cache(): | def clear_blog_cache(): | ||||
for blog in webnotes.conn.sql_list("""select page_name from | for blog in webnotes.conn.sql_list("""select page_name from | ||||
`tabBlog Post` where ifnull(published,0)=1"""): | `tabBlog Post` where ifnull(published,0)=1"""): | ||||
delete_page_cache(blog) | |||||
clear_cache(blog) | |||||
delete_page_cache("writers") | |||||
clear_cache("writers") |
@@ -12,10 +12,8 @@ from webnotes.utils.email_lib import sendmail | |||||
from webnotes.utils.file_manager import save_file | from webnotes.utils.file_manager import save_file | ||||
from webnotes.webutils import get_access | from webnotes.webutils import get_access | ||||
# TODO move these functions to framework | |||||
# from aapkamanch.post import clear_post_cache | |||||
# from aapkamanch.unit import clear_unit_views | |||||
from webnotes.templates.generators.website_group import clear_cache | |||||
from webnotes.templates.website_group.post import clear_post_cache | |||||
class DocType: | class DocType: | ||||
def __init__(self, d, dl): | def __init__(self, d, dl): | ||||
@@ -44,8 +42,8 @@ class DocType: | |||||
self.doc.event_datetime = None | self.doc.event_datetime = None | ||||
def on_update(self): | def on_update(self): | ||||
# clear_unit_views(self.doc.website_group) | |||||
# clear_post_cache(self.doc.parent_post or self.doc.name) | |||||
clear_cache(website_group=self.doc.website_group) | |||||
clear_post_cache(self.doc.parent_post or self.doc.name) | |||||
if self.doc.assigned_to and self.doc.assigned_to != self.assigned_to \ | if self.doc.assigned_to and self.doc.assigned_to != self.assigned_to \ | ||||
and webnotes.session.user != self.doc.assigned_to: | and webnotes.session.user != self.doc.assigned_to: | ||||
@@ -181,7 +179,7 @@ def process_picture(post, picture_name, picture): | |||||
file_data = save_file(picture_name, picture, "Post", post.doc.name, decode=True) | file_data = save_file(picture_name, picture, "Post", post.doc.name, decode=True) | ||||
post.doc.picture_url = file_data.file_name or file_data.file_url | post.doc.picture_url = file_data.file_name or file_data.file_url | ||||
webnotes.conn.set_value("Post", post.doc.name, "picture_url", post.doc.picture_url) | webnotes.conn.set_value("Post", post.doc.name, "picture_url", post.doc.picture_url) | ||||
# clear_unit_views(post.doc.website_group) | |||||
clear_cache(website_group=post.doc.website_group) | |||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def suggest_user(group, term): | def suggest_user(group, term): | ||||
@@ -52,14 +52,14 @@ class DocType(DocTypeNestedSet): | |||||
self.doc.public_read = self.doc.public_write = 0 | self.doc.public_read = self.doc.public_write = 0 | ||||
def on_trash(self): | def on_trash(self): | ||||
from webnotes.webutils import delete_page_cache | |||||
from webnotes.webutils import clear_cache | |||||
# remove website sitemap permissions | # remove website sitemap permissions | ||||
to_remove = webnotes.conn.sql_list("""select name from `tabWebsite Sitemap Permission` | to_remove = webnotes.conn.sql_list("""select name from `tabWebsite Sitemap Permission` | ||||
where website_sitemap=%s""", (self.doc.name,)) | where website_sitemap=%s""", (self.doc.name,)) | ||||
webnotes.delete_doc("Website Sitemap Permission", to_remove, ignore_permissions=True) | webnotes.delete_doc("Website Sitemap Permission", to_remove, ignore_permissions=True) | ||||
delete_page_cache(self.doc.name) | |||||
clear_cache(self.doc.name) | |||||
def add_to_sitemap(options): | def add_to_sitemap(options): | ||||
bean = webnotes.new_bean("Website Sitemap") | bean = webnotes.new_bean("Website Sitemap") | ||||
@@ -68,9 +68,11 @@ def _get_access(sitemap_page, profile): | |||||
return { "read": read, "write": write, "admin": admin, "private_read": private_read } | return { "read": read, "write": write, "admin": admin, "private_read": private_read } | ||||
def clear_permissions(profiles): | |||||
def clear_permissions(profiles=None): | |||||
if isinstance(profiles, basestring): | if isinstance(profiles, basestring): | ||||
profiles = [profiles] | profiles = [profiles] | ||||
elif profiles is None: | |||||
profiles = webnotes.conn.sql_list("""select name from `tabProfile`""") | |||||
cache = webnotes.cache() | cache = webnotes.cache() | ||||
for profile in profiles: | for profile in profiles: | ||||
@@ -13,8 +13,10 @@ from urllib import quote | |||||
import mimetypes | import mimetypes | ||||
from webnotes.website.doctype.website_sitemap.website_sitemap import add_to_sitemap, update_sitemap, remove_sitemap | from webnotes.website.doctype.website_sitemap.website_sitemap import add_to_sitemap, update_sitemap, remove_sitemap | ||||
# frequently used imports (used by other modules) | |||||
from webnotes.website.doctype.website_sitemap_permission.website_sitemap_permission \ | from webnotes.website.doctype.website_sitemap_permission.website_sitemap_permission \ | ||||
import get_access | |||||
import get_access, clear_permissions | |||||
class PageNotFoundError(Exception): pass | class PageNotFoundError(Exception): pass | ||||
@@ -27,7 +29,6 @@ def render(page_name): | |||||
except Exception: | except Exception: | ||||
page_name = "error" | page_name = "error" | ||||
data = render_page(page_name) | data = render_page(page_name) | ||||
data = insert_traceback(data) | |||||
data = set_content_type(data, page_name) | data = set_content_type(data, page_name) | ||||
webnotes._response.data = data | webnotes._response.data = data | ||||
@@ -46,7 +47,9 @@ def render_page(page_name): | |||||
out = out.get("data") | out = out.get("data") | ||||
if out: | if out: | ||||
webnotes._response.headers[b"From Cache"] = True | |||||
if hasattr(webnotes, "_response"): | |||||
webnotes._response.headers[b"From Cache"] = True | |||||
return out | return out | ||||
return build(page_name) | return build(page_name) | ||||
@@ -238,15 +241,6 @@ def scrub_page_name(page_name): | |||||
return page_name | return page_name | ||||
def insert_traceback(data): | |||||
traceback = webnotes.get_traceback() | |||||
if isinstance(data, dict): | |||||
data["content"] = data["content"] % {"error": traceback} | |||||
else: | |||||
data = data % {"error": traceback} | |||||
return data | |||||
def set_content_type(data, page_name): | def set_content_type(data, page_name): | ||||
if isinstance(data, dict): | if isinstance(data, dict): | ||||
webnotes._response.headers[b"Content-Type"] = b"application/json; charset: utf-8" | webnotes._response.headers[b"Content-Type"] = b"application/json; charset: utf-8" | ||||
@@ -262,23 +256,27 @@ def set_content_type(data, page_name): | |||||
return data | return data | ||||
def clear_cache(page_name=None): | def clear_cache(page_name=None): | ||||
cache = webnotes.cache() | |||||
if page_name: | if page_name: | ||||
delete_page_cache(page_name) | delete_page_cache(page_name) | ||||
else: | else: | ||||
cache = webnotes.cache() | |||||
for p in webnotes.conn.sql_list("""select name from `tabWebsite Sitemap`"""): | for p in webnotes.conn.sql_list("""select name from `tabWebsite Sitemap`"""): | ||||
if p is not None: | if p is not None: | ||||
cache.delete_value("page:" + p) | |||||
cache.delete_value("home_page") | |||||
cache.delete_value("page:index") | |||||
cache.delete_value("website_sitemap") | |||||
cache.delete_value("website_sitemap_config") | |||||
delete_page_cache(p) | |||||
cache.delete_value("home_page") | |||||
clear_permissions() | |||||
for method in webnotes.get_hooks("website_clear_cache"): | |||||
webnotes.get_attr(method)(page_name) | |||||
def delete_page_cache(page_name): | def delete_page_cache(page_name): | ||||
if page_name: | |||||
cache = webnotes.cache() | |||||
cache.delete_value("page:" + page_name) | |||||
cache.delete_value("website_sitemap") | |||||
cache = webnotes.cache() | |||||
cache.delete_value("page:" + page_name) | |||||
cache.delete_value("page_context:" + page_name) | |||||
cache.delete_value("sitemap_options:" + page_name) | |||||
def is_signup_enabled(): | def is_signup_enabled(): | ||||
if getattr(webnotes.local, "is_signup_enabled", None) is None: | if getattr(webnotes.local, "is_signup_enabled", None) is None: | ||||