@@ -25,4 +25,5 @@ recursive-include frappe *.csv | |||||
recursive-include frappe *.ico | recursive-include frappe *.ico | ||||
recursive-include frappe *.less | recursive-include frappe *.less | ||||
recursive-include frappe *.txt | recursive-include frappe *.txt | ||||
recursive-include frappe/public * | |||||
recursive-exclude * *.pyc | recursive-exclude * *.pyc |
@@ -630,7 +630,7 @@ def set_filters(jenv): | |||||
jenv.filters["json"] = dumps | jenv.filters["json"] = dumps | ||||
jenv.filters["get_hex_shade"] = get_hex_shade | jenv.filters["get_hex_shade"] = get_hex_shade | ||||
# load jenv_filters from hooks.txt | |||||
# load jenv_filters from hooks.py | |||||
for app in get_all_apps(True): | for app in get_all_apps(True): | ||||
for jenv_filter in (get_hooks(app_name=app).jenv_filter or []): | for jenv_filter in (get_hooks(app_name=app).jenv_filter or []): | ||||
filter_name, filter_function = jenv_filter.split(":") | filter_name, filter_function = jenv_filter.split(":") | ||||
@@ -10,9 +10,9 @@ cur_frm.cscript.refresh = function(doc) { | |||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
cur_frm.appframe.add_button("View In Website", function() { | cur_frm.appframe.add_button("View In Website", function() { | ||||
window.open(doc.page_name); | |||||
window.open(doc.__onload.website_route); | |||||
}, "icon-globe"); | }, "icon-globe"); | ||||
} | } | ||||
} | |||||
} |
@@ -12,18 +12,18 @@ from frappe.utils import today | |||||
class BlogPost(WebsiteGenerator): | class BlogPost(WebsiteGenerator): | ||||
save_versions = True | save_versions = True | ||||
def get_page_title(self): | def get_page_title(self): | ||||
return self.title | return self.title | ||||
def validate(self): | def validate(self): | ||||
if not self.blog_intro: | if not self.blog_intro: | ||||
self.blog_intro = self.content[:140] | self.blog_intro = self.content[:140] | ||||
re.sub("\<[^>]*\>", "", self.blog_intro) | re.sub("\<[^>]*\>", "", self.blog_intro) | ||||
if self.blog_intro: | if self.blog_intro: | ||||
self.blog_intro = self.blog_intro[:140] | self.blog_intro = self.blog_intro[:140] | ||||
if self.published and not self.published_on: | if self.published and not self.published_on: | ||||
self.published_on = today() | self.published_on = today() | ||||
@@ -31,18 +31,18 @@ class BlogPost(WebsiteGenerator): | |||||
{"ref_doctype": "Blog Category", "docname": self.blog_category}) | {"ref_doctype": "Blog Category", "docname": self.blog_category}) | ||||
# update posts | # update posts | ||||
frappe.db.sql("""update tabBlogger set posts=(select count(*) from `tabBlog Post` | |||||
frappe.db.sql("""update tabBlogger set posts=(select count(*) from `tabBlog Post` | |||||
where ifnull(blogger,'')=tabBlogger.name) | where ifnull(blogger,'')=tabBlogger.name) | ||||
where name=%s""", (self.blogger,)) | where name=%s""", (self.blogger,)) | ||||
def on_update(self): | def on_update(self): | ||||
WebsiteGenerator.on_update(self) | WebsiteGenerator.on_update(self) | ||||
clear_cache("writers") | clear_cache("writers") | ||||
def clear_blog_cache(): | def clear_blog_cache(): | ||||
for blog in frappe.db.sql_list("""select page_name from | |||||
for blog in frappe.db.sql_list("""select page_name from | |||||
`tabBlog Post` where ifnull(published,0)=1"""): | `tabBlog Post` where ifnull(published,0)=1"""): | ||||
clear_cache(blog) | clear_cache(blog) | ||||
clear_cache("writers") | clear_cache("writers") |
@@ -11,7 +11,7 @@ $.extend(cur_frm.cscript, { | |||||
} | } | ||||
if(doc.insert_style) { | if(doc.insert_style) { | ||||
if(!doc.css) { | if(!doc.css) { | ||||
cur_frm.set_value("css", '#page-'+doc.name+' { }'); | |||||
cur_frm.set_value("css", '#page-'+doc.name+' { }'); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -20,14 +20,14 @@ $.extend(cur_frm.cscript, { | |||||
cur_frm.cscript.layout(doc); | cur_frm.cscript.layout(doc); | ||||
if(!doc.__islocal && doc.published) { | if(!doc.__islocal && doc.published) { | ||||
cur_frm.appframe.add_button("View In Website", function() { | cur_frm.appframe.add_button("View In Website", function() { | ||||
window.open(doc.page_name); | |||||
window.open(doc.__onload.website_route); | |||||
}, "icon-globe"); | }, "icon-globe"); | ||||
} | } | ||||
}, | }, | ||||
insert_style: function(doc) { | insert_style: function(doc) { | ||||
cur_frm.cscript.layout(doc); | |||||
cur_frm.cscript.layout(doc); | |||||
}, | }, | ||||
insert_code: function(doc) { | insert_code: function(doc) { | ||||
cur_frm.cscript.layout(doc); | |||||
cur_frm.cscript.layout(doc); | |||||
} | } | ||||
}); | |||||
}); |
@@ -194,16 +194,15 @@ $.extend(frappe, { | |||||
$(window).on("popstate", function(event) { | $(window).on("popstate", function(event) { | ||||
// hack for chrome's onload popstate call | // hack for chrome's onload popstate call | ||||
if(window.initial_href==location.href && window.previous_href==undefined) { | if(window.initial_href==location.href && window.previous_href==undefined) { | ||||
frappe.set_force_reload(true); | |||||
window.location.reload(); | |||||
return; | return; | ||||
} | } | ||||
window.previous_href = location.href; | window.previous_href = location.href; | ||||
var state = event.originalEvent.state; | var state = event.originalEvent.state; | ||||
if(!state) { | if(!state) { | ||||
console.log("state not found!"); | |||||
frappe.set_force_reload(true); | |||||
state = window.history.state; | |||||
window.location.reload(); | |||||
return; | |||||
} | } | ||||
frappe.render_json(state); | frappe.render_json(state); | ||||
}); | }); | ||||
@@ -273,44 +272,35 @@ $.extend(frappe, { | |||||
}); | }); | ||||
}, | }, | ||||
render_json: function(data) { | render_json: function(data) { | ||||
if(data.reload) { | |||||
window.location = location.href; | |||||
} else { | |||||
$('[data-html-block]').each(function(i, section) { | |||||
var $section = $(section); | |||||
var stype = $section.attr("data-html-block"); | |||||
var block_data = data[stype] || ""; | |||||
// NOTE: use frappe.ready instead of $.ready for reliable execution | |||||
if(stype==="script") { | |||||
$section.remove(); | |||||
$("<script data-html-block='script'></script>") | |||||
.html(block_data) | |||||
.appendTo("body"); | |||||
} else if(stype==="script_lib") { | |||||
// render once | |||||
if(!$("[data-block-html='script_lib'][data-path='"+data.path+"']").length) { | |||||
$("<script data-block-html='script_lib' data-path='"+data.path+"'></script>") | |||||
.html(data.script_lib) | |||||
.appendTo("body"); | |||||
} | |||||
} else { | |||||
$section.html(block_data); | |||||
$('[data-html-block]').each(function(i, section) { | |||||
var $section = $(section); | |||||
var stype = $section.attr("data-html-block"); | |||||
var block_data = data[stype] || ""; | |||||
// NOTE: use frappe.ready instead of $.ready for reliable execution | |||||
if(stype==="script") { | |||||
$section.remove(); | |||||
$("<script data-html-block='script'></script>") | |||||
.html(block_data) | |||||
.appendTo("body"); | |||||
} else if(stype==="script_lib") { | |||||
// render once | |||||
if(!$("[data-block-html='script_lib'][data-path='"+data.path+"']").length) { | |||||
$("<script data-block-html='script_lib' data-path='"+data.path+"'></script>") | |||||
.html(data.script_lib) | |||||
.appendTo("body"); | |||||
} | } | ||||
}); | |||||
if(data.title) $("title").html(data.title); | |||||
} else { | |||||
$section.html(block_data); | |||||
} | |||||
}); | |||||
if(data.title) $("title").html(data.title); | |||||
// change id of current page | |||||
$(".page-container").attr("id", "page-" + data.path); | |||||
// change id of current page | |||||
$(".page-container").attr("id", "page-" + data.path); | |||||
window.ga && ga('send', 'pageview', location.pathname); | |||||
$(document).trigger("page-change"); | |||||
} | |||||
}, | |||||
set_force_reload: function(reload) { | |||||
// learned this from twitter's implementation | |||||
window.history.replaceState({"reload": reload}, | |||||
window.document.title, location.href); | |||||
window.ga && ga('send', 'pageview', location.pathname); | |||||
$(document).trigger("page-change"); | |||||
}, | }, | ||||
supports_pjax: function() { | supports_pjax: function() { | ||||
return (window.history && window.history.pushState && window.history.replaceState && | return (window.history && window.history.pushState && window.history.replaceState && | ||||
@@ -18,6 +18,9 @@ class WebsiteGenerator(Document): | |||||
self.name = self.get_page_name() | self.name = self.get_page_name() | ||||
append_number_if_name_exists(self) | append_number_if_name_exists(self) | ||||
def onload(self): | |||||
self.get("__onload").website_route = frappe.db.get_value("Website Route", {"ref_doctype": self.doctype, "docname": self.name}) | |||||
def set_page_name(self): | def set_page_name(self): | ||||
"""set page name based on parent page_name and title""" | """set page name based on parent page_name and title""" | ||||
page_name = cleanup_page_name(self.get_page_title()) | page_name = cleanup_page_name(self.get_page_title()) | ||||