diff --git a/webnotes/core/doctype/profile/profile.py b/webnotes/core/doctype/profile/profile.py index 4b1216aa53..3fac8626fc 100644 --- a/webnotes/core/doctype/profile/profile.py +++ b/webnotes/core/doctype/profile/profile.py @@ -43,7 +43,7 @@ class DocType: pass # email server not set, don't send email self.doc.new_password = "" - + self.update_gravatar() def check_enable_disable(self): # do not allow disabling administrator/guest @@ -106,6 +106,15 @@ class DocType: # owner is always name webnotes.conn.set(self.doc, 'owner', self.doc.name) webnotes.clear_cache(user=self.doc.name) + + def update_gravatar(self): + import md5 + if not self.doc.user_image: + if self.doc.fb_username: + self.doc.user_image = "https://graph.facebook.com/" + self.doc.fb_username + "/picture" + else: + self.doc.user_image = "https://secure.gravatar.com/avatar/" + md5.md5(self.doc.name).hexdigest() \ + + "?d=retro" def reset_password(self): from webnotes.utils import random_string, get_url diff --git a/webnotes/hooks.txt b/webnotes/hooks.txt index 02c550237b..1a57c2e015 100644 --- a/webnotes/hooks.txt +++ b/webnotes/hooks.txt @@ -31,6 +31,7 @@ scheduler_event = all:webnotes.utils.email_lib.bulk.flush scheduler_event = daily:webnotes.utils.email_lib.bulk.clear_outbox scheduler_event = daily:webnotes.core.doctype.notification_count.notification_count.delete_event_notification_count scheduler_event = daily:webnotes.core.doctype.event.event.send_event_digest +scheduler_event = hourly:webnotes.templates.generator.website_group.clear_event_cache on_session_creation = webnotes.auth.notify_administrator_login diff --git a/webnotes/templates/base.html b/webnotes/templates/base.html index 2014fa00e7..49a4ec9e40 100644 --- a/webnotes/templates/base.html +++ b/webnotes/templates/base.html @@ -60,7 +60,12 @@
diff --git a/webnotes/templates/generators/website_group.py b/webnotes/templates/generators/website_group.py index 1e3d65cc68..e99d584a88 100644 --- a/webnotes/templates/generators/website_group.py +++ b/webnotes/templates/generators/website_group.py @@ -17,7 +17,6 @@ def get_context(context): raise webnotes.PermissionError group_context = get_group_context(group, view, bean) - group_context["access"] = get_access(group) group_context.update(context) return group_context @@ -122,3 +121,7 @@ def clear_cache(page_name=None, website_group=None): for group in website_groups: for view in get_views(group.group_type): cache.delete_value("website_group_context:{}:{}".format(group.page_name, view)) + +def clear_event_cache(): + for group in webnotes.conn.sql_list("""select name from `tabWebsite Group` where group_type='Event'"""): + clear_unit_views(website_group=group) diff --git a/webnotes/webutils.py b/webnotes/webutils.py index 0de86d7755..d2cde07ff7 100644 --- a/webnotes/webutils.py +++ b/webnotes/webutils.py @@ -91,13 +91,24 @@ def get_context(page_name): if can_cache(): context = webnotes.cache().get_value(cache_key) + access = get_access(page_name) if not context: - sitemap_options = get_sitemap_options(page_name) - context = build_context(sitemap_options) + context = get_sitemap_options(page_name) + + # permission may be required for rendering + context["access"] = access + + context = build_context(context) + if can_cache(context.no_cache): + del context["access"] webnotes.cache().set_value(cache_key, context) + context["access"] = access context.update(context.data or {}) + + # TODO private pages + return context def get_sitemap_options(page_name): @@ -137,8 +148,8 @@ def build_sitemap_options(page_name): where lft < %s and rgt > %s order by lft asc""", (sitemap_options.lft, sitemap_options.rgt), as_dict=True) sitemap_options.children = webnotes.conn.sql("""select * from `tabWebsite Sitemap` - where parent_website_sitemap=%s""", (sitemap_options.page_name,), as_dict=True) - + where parent_website_sitemap=%s and public_read=1""", (sitemap_options.page_name,), as_dict=True) + # determine templates to be used if not sitemap_options.base_template_path: sitemap_options.base_template_path = "templates/base.html"