@@ -113,6 +113,7 @@ def init(site, sites_path=None): | |||
local.user_perms = {} | |||
local.test_objects = {} | |||
local.jenv = None | |||
local.jloader =None | |||
setup_module_map() | |||
@@ -550,18 +551,13 @@ def get_list(doctype, filters=None, fields=None, docstatus=None, | |||
def get_jenv(): | |||
if not local.jenv: | |||
from jinja2 import Environment, ChoiceLoader, PackageLoader, DebugUndefined | |||
from jinja2 import Environment, DebugUndefined | |||
import webnotes.utils | |||
apps = get_installed_apps() | |||
apps.remove("webnotes") | |||
# webnotes will be loaded last, so app templates will get precedence | |||
jenv = Environment(loader = ChoiceLoader([PackageLoader(app, ".") \ | |||
for app in apps + ["webnotes"]]), undefined=DebugUndefined) | |||
jenv = Environment(loader = get_jloader(), undefined=DebugUndefined) | |||
set_filters(jenv) | |||
jenv.globals.update({ | |||
"webnotes": sys.modules[__name__], | |||
"webnotes.utils": webnotes.utils, | |||
@@ -572,6 +568,18 @@ def get_jenv(): | |||
return local.jenv | |||
def get_jloader(): | |||
if not local.jloader: | |||
from jinja2 import ChoiceLoader, PackageLoader | |||
apps = get_installed_apps() | |||
apps.remove("webnotes") | |||
local.jloader = ChoiceLoader([PackageLoader(app, ".") \ | |||
for app in apps + ["webnotes"]]) | |||
return local.jloader | |||
def set_filters(jenv): | |||
from webnotes.utils import global_date_format | |||
from webnotes.webutils import get_hex_shade | |||
@@ -35,5 +35,11 @@ data = { | |||
"link": "applications", | |||
"type": "page", | |||
"label": _("Installer") | |||
} | |||
}, | |||
"Setup": { | |||
"color": "#bdc3c7", | |||
"icon": "icon-wrench", | |||
"link": "Setup", | |||
"type": "setup" | |||
}, | |||
} |
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2012-06-14 15:07:25", | |||
"docstatus": 0, | |||
"modified": "2013-12-20 17:14:14", | |||
"modified": "2014-02-13 16:09:26", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -15,8 +15,19 @@ | |||
"standard": "Yes", | |||
"title": "Data Import Tool" | |||
}, | |||
{ | |||
"doctype": "Page Role", | |||
"name": "__common__", | |||
"parent": "data-import-tool", | |||
"parentfield": "roles", | |||
"parenttype": "Page", | |||
"role": "System Manager" | |||
}, | |||
{ | |||
"doctype": "Page", | |||
"name": "data-import-tool" | |||
}, | |||
{ | |||
"doctype": "Page Role" | |||
} | |||
] |
@@ -22,13 +22,7 @@ | |||
{%- for link in web_include_css -%} | |||
<link type="text/css" rel="stylesheet" href="{{ link }}"> | |||
{%- endfor -%} | |||
{% block script -%} | |||
<script data-html-block="script"> | |||
{%- if script is defined -%}{{ script }}{%- endif -%} | |||
</script> | |||
{%- endblock %} | |||
{% block style -%} | |||
<style data-html-block="style"> | |||
{%- if style is defined -%}{{ style }}{%- endif -%} | |||
@@ -86,5 +80,10 @@ | |||
<div id="wrap-footer"> | |||
{%- block footer -%}{% include "templates/includes/footer.html" %}{%- endblock -%} | |||
</div> | |||
{% block script -%} | |||
<script data-html-block="script"> | |||
{%- if script is defined -%}{{ script }}{%- endif -%} | |||
</script> | |||
{%- endblock %} | |||
</body> | |||
</html> |
@@ -0,0 +1,11 @@ | |||
{% extends "templates/pages/blog.html" %} | |||
{% block title %}{{ title }}{% endblock %} | |||
{% block header %}<h2>{{ title }}</h2>{% endblock %} | |||
{% block script %} | |||
$(function() { | |||
window.category = "{{ docname }}"; | |||
}); | |||
{% endblock %} |
@@ -0,0 +1,2 @@ | |||
doctype = "Blog Category" | |||
no_cache = 1 |
@@ -13,7 +13,7 @@ var blog = { | |||
cmd: "webnotes.templates.generators.blog_post.get_blog_list", | |||
start: blog.start, | |||
by: get_url_arg("by"), | |||
category: get_url_arg("category") | |||
category: window.category || get_url_arg("category") | |||
}, | |||
dataType: "json", | |||
success: function(data) { | |||
@@ -1 +1 @@ | |||
<a href="https://github.com/webnotes/wnframework" style="color: #aaa">Built on Web Notes</a> | |||
<a href="https://github.com/webnotes/wnframework" style="color: #aaa">Built on Frappe</a> |
@@ -1,4 +1,4 @@ | |||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | |||
# MIT License. See license.txt | |||
no_sitemap = 1 | |||
no_sitemap = 1 |
@@ -3,13 +3,18 @@ | |||
from __future__ import unicode_literals | |||
import webnotes | |||
from webnotes.webutils import WebsiteGenerator, cleanup_page_name, clear_cache | |||
class DocType: | |||
class DocType(WebsiteGenerator): | |||
def __init__(self, d, dl): | |||
self.doc, self.doclist = d, dl | |||
def get_page_title(self): | |||
return self.doc.title | |||
def on_update(self): | |||
# for blog footer | |||
WebsiteGenerator.on_update(self) | |||
from webnotes.webutils import clear_cache | |||
clear_cache() | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2013-03-08 09:41:11", | |||
"docstatus": 0, | |||
"modified": "2014-01-20 17:48:25", | |||
"modified": "2014-02-13 17:31:52", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -17,15 +17,11 @@ | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "category_name", | |||
"fieldtype": "Data", | |||
"label": "Category Name", | |||
"name": "__common__", | |||
"parent": "Blog Category", | |||
"parentfield": "fields", | |||
"parenttype": "DocType", | |||
"permlevel": 0, | |||
"reqd": 1 | |||
"permlevel": 0 | |||
}, | |||
{ | |||
"doctype": "DocPerm", | |||
@@ -43,10 +39,42 @@ | |||
"name": "Blog Category" | |||
}, | |||
{ | |||
"doctype": "DocField" | |||
"doctype": "DocField", | |||
"fieldname": "category_name", | |||
"fieldtype": "Data", | |||
"label": "Category Name", | |||
"reqd": 1 | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "title", | |||
"fieldtype": "Data", | |||
"label": "Title", | |||
"reqd": 1 | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "published", | |||
"fieldtype": "Check", | |||
"label": "Published" | |||
}, | |||
{ | |||
"default": "blog", | |||
"doctype": "DocField", | |||
"fieldname": "parent_website_sitemap", | |||
"fieldtype": "Link", | |||
"label": "Parent Website Sitemap", | |||
"options": "Website Sitemap", | |||
"reqd": 1 | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "page_name", | |||
"fieldtype": "Data", | |||
"label": "Page Name" | |||
}, | |||
{ | |||
"cancel": 1, | |||
"cancel": 0, | |||
"create": 1, | |||
"delete": 1, | |||
"doctype": "DocPerm", | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2013-04-30 12:58:46", | |||
"docstatus": 0, | |||
"modified": "2014-02-03 15:25:54", | |||
"modified": "2014-02-13 15:31:31", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -123,6 +123,20 @@ | |||
"label": "Top Bar Items", | |||
"options": "Top Bar Item" | |||
}, | |||
{ | |||
"description": "Sidebar Links for Home Page only", | |||
"doctype": "DocField", | |||
"fieldname": "sidebar", | |||
"fieldtype": "Section Break", | |||
"label": "Sidebar" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "sidebar_items", | |||
"fieldtype": "Table", | |||
"label": "Sidebar Items", | |||
"options": "Top Bar Item" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "footer", | |||
@@ -113,9 +113,8 @@ def update_sitemap(website_sitemap, options): | |||
if not bean.doc.page_name: | |||
# for pages | |||
bean.doc.page_name = options.link_name | |||
bean.doc.website_sitemap_config = options.link_name | |||
bean.doc.website_sitemap_config = options.link_name | |||
bean.save(ignore_permissions=True) | |||
def remove_sitemap(page_name=None, ref_doctype=None, docname=None): | |||
@@ -20,10 +20,13 @@ class DocType: | |||
website_sitemap = webnotes.conn.get_value("Website Sitemap", | |||
{"website_sitemap_config": self.doc.name, "page_or_generator": "Page"}) | |||
opts = self.doc.fields.copy() | |||
opts.update({"public_read": 1}) | |||
if website_sitemap: | |||
update_sitemap(website_sitemap, self.doc.fields) | |||
update_sitemap(website_sitemap, opts) | |||
else: | |||
add_to_sitemap(self.doc.fields) | |||
add_to_sitemap(opts) | |||
else: | |||
condition = "" | |||
@@ -87,6 +90,7 @@ def add_website_sitemap_config(page_or_generator, app, path, fname, basepath): | |||
module = webnotes.get_module(wsc.controller) | |||
wsc.no_cache = getattr(module, "no_cache", 0) | |||
wsc.no_sitemap = wsc.no_cache or getattr(module, "no_sitemap", 0) | |||
wsc.no_sidebar = wsc.no_sidebar or getattr(module, "no_sidebar", 0) | |||
wsc.ref_doctype = getattr(module, "doctype", None) | |||
wsc.page_name_field = getattr(module, "page_name_field", "page_name") | |||
wsc.condition_field = getattr(module, "condition_field", None) | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2013-11-18 15:35:00", | |||
"docstatus": 0, | |||
"modified": "2014-01-30 17:25:27", | |||
"modified": "2014-02-13 15:48:16", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -103,6 +103,12 @@ | |||
"label": "No Sitemap", | |||
"read_only": 1 | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "no_sidebar", | |||
"fieldtype": "Check", | |||
"label": "No Sidebar" | |||
}, | |||
{ | |||
"doctype": "DocField", | |||
"fieldname": "page_name_field", | |||
@@ -260,7 +260,14 @@ $.extend(wn, { | |||
} else { | |||
$('[data-html-block]').each(function(i, section) { | |||
var $section = $(section); | |||
$section.html(data[$section.attr("data-html-block")] || ""); | |||
if($section.attr("data-html-block")==="script") { | |||
$section.remove(); | |||
$("<script data-html-block='script'></script>") | |||
.html(data[$section.attr("data-html-block")] || "") | |||
.appendTo("body"); | |||
} else { | |||
$section.html(data[$section.attr("data-html-block")] || ""); | |||
} | |||
}); | |||
if(data.title) $("title").html(data.title); | |||
$(document).trigger("page_change"); | |||
@@ -118,7 +118,7 @@ def get_sitemap_options(path): | |||
cache_key = "sitemap_options:{}".format(path) | |||
if can_cache(): | |||
sitemap_options = webnotes.cache().get_value(cache_key) | |||
sitemap_options = webnotes._dict(webnotes.cache().get_value(cache_key)) | |||
if not sitemap_options: | |||
sitemap_options = build_sitemap_options(path) | |||
@@ -129,6 +129,7 @@ def get_sitemap_options(path): | |||
def build_sitemap_options(path): | |||
sitemap_options = webnotes.doc("Website Sitemap", path).fields | |||
home_page = get_home_page() | |||
sitemap_config = webnotes.doc("Website Sitemap Config", | |||
sitemap_options.get("website_sitemap_config")).fields | |||
@@ -142,21 +143,24 @@ def build_sitemap_options(path): | |||
sitemap_options.title = sitemap_options.page_title | |||
sitemap_options.pathname = sitemap_options.name | |||
def set_sidebar_items(pathname): | |||
if pathname==home_page or not pathname: | |||
sitemap_options.children = webnotes.conn.sql("""select url as name, label as page_title, | |||
1 as public_read from `tabTop Bar Item` where parentfield='sidebar_items' order by idx""", as_dict=True) | |||
else: | |||
sitemap_options.children = webnotes.conn.sql("""select * from `tabWebsite Sitemap` | |||
where ifnull(parent_website_sitemap,'')=%s | |||
and public_read=1 order by -idx desc, page_title asc""", pathname, as_dict=True) | |||
# establish hierarchy | |||
sitemap_options.parents = webnotes.conn.sql("""select name, page_title from `tabWebsite Sitemap` | |||
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 | |||
and public_read=1 order by -idx desc, page_title asc""", (sitemap_options.pathname,), as_dict=True) | |||
# leaf node, show siblings | |||
if not sitemap_options.children: | |||
sitemap_options.children = webnotes.conn.sql("""select * from `tabWebsite Sitemap` | |||
where ifnull(parent_website_sitemap, '')=%s | |||
and public_read=1 order by -idx desc, page_title asc""", | |||
sitemap_options.parent_website_sitemap or "", as_dict=True) | |||
if not sitemap_options.no_sidebar: | |||
set_sidebar_items(sitemap_options.pathname) | |||
if not sitemap_options.children: | |||
set_sidebar_items(sitemap_options.parent_website_sitemap) | |||
# determine templates to be used | |||
if not sitemap_options.base_template_path: | |||
sitemap_options.base_template_path = "templates/base.html" | |||
@@ -195,8 +199,6 @@ def get_home_page(): | |||
or [webnotes.conn.get_value("Website Settings", None, "home_page") \ | |||
or "login"])[0]) | |||
print home_page | |||
return home_page | |||
def get_website_settings(): | |||
@@ -370,7 +372,7 @@ class WebsiteGenerator(DocListController): | |||
existing_site_map = webnotes.conn.get_value("Website Sitemap", {"ref_doctype": self.doc.doctype, | |||
"docname": self.doc.name}) | |||
opts = webnotes._dict({ | |||
"page_or_generator": "Generator", | |||
"ref_doctype":self.doc.doctype, | |||
@@ -379,11 +381,12 @@ class WebsiteGenerator(DocListController): | |||
"link_name": self._website_config.name, | |||
"lastmod": webnotes.utils.get_datetime(self.doc.modified).strftime("%Y-%m-%d"), | |||
"parent_website_sitemap": self.doc.parent_website_sitemap, | |||
"page_title": self.get_page_title() | |||
"page_title": self.get_page_title(), | |||
"public_read": 1 if not self._website_config.no_sidebar else 0 | |||
}) | |||
self.update_permissions(opts) | |||
if existing_site_map: | |||
update_sitemap(existing_site_map, opts) | |||
else: | |||
@@ -450,16 +453,23 @@ def get_hex_shade(color, percent): | |||
def render_blocks(context): | |||
"""returns a dict of block name and its rendered content""" | |||
from jinja2.utils import concat | |||
from jinja2 import meta | |||
out = {} | |||
template = webnotes.get_template(context["template_path"]) | |||
env = webnotes.get_jenv() | |||
# required as per low level API | |||
context = template.new_context(context) | |||
def _render_blocks(template_path): | |||
source = webnotes.local.jloader.get_source(webnotes.local.jenv, template_path)[0] | |||
for referenced_template_path in meta.find_referenced_templates(env.parse(source)): | |||
if referenced_template_path: | |||
_render_blocks(referenced_template_path) | |||
template = webnotes.get_template(template_path) | |||
for block, render in template.blocks.items(): | |||
out[block] = scrub_relative_urls(concat(render(template.new_context(context)))) | |||
# render each block individually | |||
for block, render in template.blocks.items(): | |||
out[block] = scrub_relative_urls(concat(render(context))) | |||
_render_blocks(context["template_path"]) | |||
return out | |||