diff --git a/webnotes/__init__.py b/webnotes/__init__.py
index 10fe74690a..df30cb4e43 100644
--- a/webnotes/__init__.py
+++ b/webnotes/__init__.py
@@ -109,6 +109,7 @@ def init(site, sites_path=None):
local.restrictions = None
local.user_perms = {}
local.test_objects = {}
+ local.jenv = None
setup_module_map()
@@ -364,9 +365,9 @@ def reload_doc(module, dt=None, dn=None, force=False):
import webnotes.modules
return webnotes.modules.reload_doc(module, dt, dn, force=force)
-def rename_doc(doctype, old, new, debug=0, force=False, merge=False):
+def rename_doc(doctype, old, new, debug=0, force=False, merge=False, ignore_permissions=False):
from webnotes.model.rename_doc import rename_doc
- return rename_doc(doctype, old, new, force=force, merge=merge)
+ return rename_doc(doctype, old, new, force=force, merge=merge, ignore_permissions=ignore_permissions)
def insert(doclist):
import webnotes.model
@@ -544,11 +545,8 @@ def get_list(doctype, filters=None, fields=None, docstatus=None,
group_by=group_by, order_by=order_by, limit_start=limit_start, limit_page_length=limit_page_length,
as_list=as_list, debug=debug)
-jenv = None
-
def get_jenv():
- global jenv
- if not jenv:
+ if not local.jenv:
from jinja2 import Environment, ChoiceLoader, PackageLoader, DebugUndefined
import webnotes.utils
@@ -567,7 +565,9 @@ def get_jenv():
"_": _
})
- return jenv
+ local.jenv = jenv
+
+ return local.jenv
def set_filters(jenv):
from webnotes.utils import global_date_format
diff --git a/webnotes/cli.py b/webnotes/cli.py
index abe4ae66f5..ec2047a8ee 100755
--- a/webnotes/cli.py
+++ b/webnotes/cli.py
@@ -188,6 +188,8 @@ def setup_utilities(parser):
help="Clear website cache")
parser.add_argument("--build_sitemap", default=False, action="store_true",
help="Build Website Sitemap")
+ parser.add_argument("--sync_statics", default=False, action="store_true",
+ help="Sync files from templates/statics to Web Pages")
parser.add_argument("--clear_cache", default=False, action="store_true",
help="Clear cache, doctype cache and defaults")
parser.add_argument("--reset_perms", default=False, action="store_true",
@@ -441,6 +443,14 @@ def build_sitemap():
rebuild_config()
webnotes.destroy()
+@cmd
+def sync_statics():
+ from webnotes.website.doctype.web_page import web_page
+ webnotes.connect()
+ web_page.sync_statics()
+ webnotes.conn.commit()
+ webnotes.destroy()
+
@cmd
def reset_perms():
webnotes.connect()
diff --git a/webnotes/core/doctype/communication/communication.py b/webnotes/core/doctype/communication/communication.py
index afc2e72d3d..8dce5ee0ee 100644
--- a/webnotes/core/doctype/communication/communication.py
+++ b/webnotes/core/doctype/communication/communication.py
@@ -37,7 +37,7 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
raise webnotes.PermissionError("You are not allowed to send emails related to: {doctype} {name}".format(
doctype=doctype, name=name))
- _send(doctype=doctype, name=name, content=content, subject=subject, sent_or_received=sent_or_received,
+ _make(doctype=doctype, name=name, content=content, subject=subject, sent_or_received=sent_or_received,
sender=sender, recipients=recipients, communication_medium=communication_medium, send_email=send_email,
print_html=print_html, attachments=attachments, send_me_a_copy=send_me_a_copy, set_lead=set_lead,
date=date)
@@ -116,9 +116,13 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s
d.content = sent_via.get_content(d)
footer = set_portal_link(sent_via, d)
-
+
+ send_print_in_body = webnotes.conn.get_value("Email Settings", None, "send_print_in_body_and_attachment")
+ if not send_print_in_body:
+ d.content += "
Please see attachment for document details.
"
+
mail = get_email(d.recipients, sender=d.sender, subject=d.subject,
- msg=d.content, footer=footer)
+ msg=d.content, footer=footer, print_html=print_html if send_print_in_body else None)
if send_me_a_copy:
mail.cc.append(webnotes.conn.get_value("Profile", webnotes.session.user, "email"))
diff --git a/webnotes/core/page/setup/setup.txt b/webnotes/core/page/setup/setup.txt
index faf64a661d..3978b77034 100644
--- a/webnotes/core/page/setup/setup.txt
+++ b/webnotes/core/page/setup/setup.txt
@@ -2,7 +2,7 @@
{
"creation": "2012-06-14 15:07:28",
"docstatus": 0,
- "modified": "2014-02-07 14:48:08",
+ "modified": "2014-02-07 14:50:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
diff --git a/webnotes/model/sync.py b/webnotes/model/sync.py
index 804651435f..bb0d994b20 100644
--- a/webnotes/model/sync.py
+++ b/webnotes/model/sync.py
@@ -17,7 +17,7 @@ def sync_all(force=0):
webnotes.clear_cache()
def sync_for(app_name, force=0, sync_everything = False, verbose=False):
- for module_name in webnotes.local.app_modules[app_name]:
+ for module_name in webnotes.local.app_modules.get(app_name) or []:
folder = os.path.dirname(webnotes.get_module(app_name + "." + module_name).__file__)
walk_and_sync(folder, force, sync_everything, verbose=verbose)
diff --git a/webnotes/public/js/wn/views/communication.js b/webnotes/public/js/wn/views/communication.js
index 012f9fde10..d46013def1 100644
--- a/webnotes/public/js/wn/views/communication.js
+++ b/webnotes/public/js/wn/views/communication.js
@@ -274,22 +274,13 @@ wn.views.CommunicationComposer = Class.extend({
});
},
- send_email: function(btn, form_values, selected_attachments, print_format_html) {
+ send_email: function(btn, form_values, selected_attachments, print_html) {
var me = this;
- if(form_values.attach_document_print) {
- var print_html = print_format_html;
- if(cint(wn.boot.send_print_in_body_and_attachment)) {
- form_values.content = form_values.content
- + ""
- + "Please see attachment for document details.
"
- }
- } else {
- var print_html = "";
+ if(!form_values.attach_document_print) {
+ print_html = "";
}
-
+
if(form_values.send_email) {
if(cur_frm && !wn.model.can_email(me.doc.doctype, cur_frm)) {
msgprint(wn._("You are not allowed to send emails related to this document."));
diff --git a/webnotes/public/js/wn/views/formview.js b/webnotes/public/js/wn/views/formview.js
index f7a51be878..970bf43dfa 100644
--- a/webnotes/public/js/wn/views/formview.js
+++ b/webnotes/public/js/wn/views/formview.js
@@ -37,7 +37,7 @@ wn.views.FormFactory = wn.views.Factory.extend({
// doc not found, but starts with New,
// make a new doc and set it
var new_str = wn._("New") + " ";
- if(dn && dn.substr(0, new_str.length)==new_star) {
+ if(dn && dn.substr(0, new_str.length)==new_str) {
var new_name = wn.model.make_new_doc_and_get_name(dt);
if(new_name===dn) {
me.load(dt, dn);
diff --git a/webnotes/templates/emails/standard.html b/webnotes/templates/emails/standard.html
index 12fc2ea276..0ecfafd6a3 100644
--- a/webnotes/templates/emails/standard.html
+++ b/webnotes/templates/emails/standard.html
@@ -8,14 +8,6 @@
/* -------------------------------------
GLOBAL
------------------------------------- */
-* {
- margin:0;
- padding:0;
- font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
- font-size: 100%;
- line-height: 1.6;
-}
-
img {
max-width: 100%;
}
@@ -23,15 +15,26 @@ img {
body {
-webkit-font-smoothing:antialiased;
-webkit-text-size-adjust:none;
- width: 100%!important;
+ width: 100% !important;
height: 100%;
+}
+
+.wrapper {
background-color: #eee;
}
+.wrapper * {
+ margin:0;
+ padding:0;
+ font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
+ font-size: 100%;
+ line-height: 1.6;
+}
+
/* -------------------------------------
ELEMENTS
------------------------------------- */
-a {
+.wrapper a {
color: #348eda;
}
@@ -69,7 +72,7 @@ a {
margin-bottom: 0;
}
-.first{
+.first {
margin-top: 0;
}
@@ -113,7 +116,9 @@ table.footer-wrap a{
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
-h1,h2,h3{
+.wrapper h1,
+.wrapper h2,
+.wrapper h3{
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
line-height: 1.1;
margin-top:15px;
@@ -123,26 +128,29 @@ h1,h2,h3{
font-weight:200;
}
-h1 {
+.wrapper h1 {
font-size: 36px;
}
-h2 {
+.wrapper h2 {
font-size: 28px;
}
-h3 {
+.wrapper h3 {
font-size: 22px;
}
-hr {
+.wrapper hr {
margin: 20px 0;
border-top: 1px solid #eee;
}
-p, ul, ol {
+.wrapper p,
+.wrapper ul,
+.wrapper ol {
margin-bottom: 10px;
font-weight: normal;
font-size:14px;
}
-ul li, ol li {
+.wrapper ul li,
+.wrapper ol li {
margin-left:5px;
list-style-position: inside;
}
@@ -180,7 +188,9 @@ ul li, ol li {
-
+
+
+
diff --git a/webnotes/templates/website_group/forum.py b/webnotes/templates/website_group/forum.py
index f711ab7f11..3dc145d50c 100644
--- a/webnotes/templates/website_group/forum.py
+++ b/webnotes/templates/website_group/forum.py
@@ -56,7 +56,7 @@ def get_post_list_html(group, view, limit_start=0, limit_length=20):
where p.website_group = %s and pr.name = p.owner and ifnull(p.parent_post, '')=''
order by {order_by} limit %s, %s""".format(order_by=order_by),
(group, int(limit_start), int(limit_length)), as_dict=True)
-
+
context = {"posts": posts, "limit_start": limit_start, "view": view}
return webnotes.get_template("templates/includes/post_list.html").render(context)
@@ -65,7 +65,7 @@ views = {
"popular": {
"name": "popular",
"template_path": "templates/website_group/forum.html",
- "url": "/{group}",
+ "url": "{pathname}",
"label": "Popular",
"icon": "icon-heart",
"default": True,
@@ -75,7 +75,7 @@ views = {
"feed": {
"name": "feed",
"template_path": "templates/website_group/forum.html",
- "url": "/{group}?view=feed",
+ "url": "/{pathname}?view=feed",
"label": "Feed",
"icon": "icon-rss",
"upvote": True,
@@ -84,7 +84,7 @@ views = {
"post": {
"name": "post",
"template_path": "templates/website_group/post.html",
- "url": "/{group}?view=post&name={post}",
+ "url": "/{pathname}?view=post&name={post}",
"label": "Post",
"icon": "icon-comments",
"upvote": True,
@@ -95,7 +95,7 @@ views = {
"edit": {
"name": "edit",
"template_path": "templates/website_group/edit_post.html",
- "url": "/{group}?view=edit&name={post}",
+ "url": "/{pathname}?view=edit&name={post}",
"label": "Edit Post",
"icon": "icon-pencil",
"hidden": True,
@@ -105,7 +105,7 @@ views = {
"add": {
"name": "add",
"template_path": "templates/website_group/edit_post.html",
- "url": "/{group}?view=add",
+ "url": "/{pathname}?view=add",
"label": "Add Post",
"icon": "icon-plus",
"hidden": True,
@@ -114,7 +114,7 @@ views = {
"settings": {
"name": "settings",
"template_path": "templates/website_group/settings.html",
- "url": "/{group}?view=settings",
+ "url": "/{pathname}?view=settings",
"label": "Settings",
"icon": "icon-cog",
"hidden": True,
diff --git a/webnotes/templates/website_group/post.py b/webnotes/templates/website_group/post.py
index 9071ea1365..5d28c0220f 100644
--- a/webnotes/templates/website_group/post.py
+++ b/webnotes/templates/website_group/post.py
@@ -20,12 +20,12 @@ def get_post_context(group_context):
"parent_post": post.name
}
- cache_key = "website_group_post:".format(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):
profile = webnotes.bean("Profile", post.owner).doc
- for fieldname in ("first_name", "last_name", "user_image", "fb_hometown", "fb_location"):
+ for fieldname in ("first_name", "last_name", "user_image", "location"):
post.fields[fieldname] = profile.fields[fieldname]
return webnotes.get_template("templates/includes/inline_post.html")\
diff --git a/webnotes/utils/email_lib/email_body.py b/webnotes/utils/email_lib/email_body.py
index 57eb3ea772..752eefe625 100644
--- a/webnotes/utils/email_lib/email_body.py
+++ b/webnotes/utils/email_lib/email_body.py
@@ -9,12 +9,12 @@ import email.utils
from inlinestyler.utils import inline_css
def get_email(recipients, sender='', msg='', subject='[No Subject]',
- text_content = None, footer=None, formatted=None):
+ text_content = None, footer=None, print_html=None, formatted=None):
"""send an html email as multipart with attachments and all"""
email = EMail(sender, recipients, subject)
if (not '
' in msg) and (not '
' in msg) and (not '
')
- email.set_html(msg, text_content, footer=footer, formatted=formatted)
+ email.set_html(msg, text_content, footer=footer, print_html=print_html, formatted=formatted)
return email
@@ -47,10 +47,10 @@ class EMail:
self.cc = []
self.html_set = False
- def set_html(self, message, text_content = None, footer=None, formatted=None):
+ def set_html(self, message, text_content = None, footer=None, print_html=None, formatted=None):
"""Attach message in the html portion of multipart/alternative"""
if not formatted:
- formatted = get_formatted_html(self.subject, message, footer)
+ formatted = get_formatted_html(self.subject, message, footer, print_html)
# this is the first html part of a multi-part message,
# convert to text well
@@ -68,12 +68,12 @@ class EMail:
Attach message in the text portion of multipart/alternative
"""
from email.mime.text import MIMEText
- part = MIMEText(message.encode('utf-8'), 'plain', 'utf-8')
+ part = MIMEText(message, 'plain', 'utf-8')
self.msg_multipart.attach(part)
def set_part_html(self, message):
from email.mime.text import MIMEText
- part = MIMEText(message.encode('utf-8'), 'html', 'utf-8')
+ part = MIMEText(message, 'html', 'utf-8')
self.msg_multipart.attach(part)
def set_html_as_text(self, html):
@@ -191,13 +191,14 @@ class EMail:
self.make()
return self.msg_root.as_string()
-def get_formatted_html(subject, message, footer=None):
+def get_formatted_html(subject, message, footer=None, print_html=None):
message = scrub_urls(message)
return inline_css(webnotes.get_template("templates/emails/standard.html").render({
"content": message,
"footer": get_footer(footer),
- "title": subject
+ "title": subject,
+ "print_html": print_html
}))
def get_footer(footer=None):
diff --git a/webnotes/website/doctype/web_page/web_page.py b/webnotes/website/doctype/web_page/web_page.py
index fe06f65aea..ad638da3b7 100644
--- a/webnotes/website/doctype/web_page/web_page.py
+++ b/webnotes/website/doctype/web_page/web_page.py
@@ -2,9 +2,10 @@
# MIT License. See license.txt
from __future__ import unicode_literals
-import webnotes
+import webnotes, os
from webnotes.webutils import WebsiteGenerator
from webnotes import _
+from markdown2 import markdown
class DocType(WebsiteGenerator):
def autoname(self):
@@ -37,3 +38,66 @@ class DocType(WebsiteGenerator):
if self.doclist.get({"parentfield": "toc"}):
from webnotes.webutils import clear_cache
clear_cache()
+
+def sync_statics():
+ synced = []
+ for app in webnotes.get_installed_apps():
+ statics_path = webnotes.get_app_path(app, "templates", "statics")
+
+ if os.path.exists(webnotes.get_app_path(app, "templates", "statics")):
+ for basepath, folders, files in os.walk(statics_path):
+ for fname in files:
+ fpath = os.path.join(basepath, fname)
+
+ url = os.path.relpath(fpath, statics_path).rsplit(".", 1)[0]
+ if fname.rsplit(".", 1)[0]=="index":
+ url = os.path.dirname(url)
+
+ parent_website_sitemap = os.path.dirname(url)
+ page_name = os.path.basename(url)
+
+ try:
+ sitemap = webnotes.bean("Website Sitemap", url)
+
+ if str(os.path.getmtime(fpath))!=sitemap.doc.static_file_timestamp:
+ page = webnotes.bean("Web Page", sitemap.doc.docname)
+ page.doc.main_section = get_static_content(fpath)
+ page.save()
+
+ sitemap = webnotes.bean("Website Sitemap", url)
+ sitemap.doc.static_file_timestamp = os.path.getmtime(fpath)
+ sitemap.save()
+
+ except webnotes.DoesNotExistError:
+
+ page = webnotes.bean({
+ "doctype":"Web Page",
+ "title": page_name.replace("-", " ").replace("_", " ").title(),
+ "page_name": page_name,
+ "main_section": get_static_content(fpath),
+ "published": 1,
+ "parent_website_sitemap": parent_website_sitemap
+ }).insert()
+
+ # update timestamp
+ sitemap = webnotes.bean("Website Sitemap", {"ref_doctype": "Web Page",
+ "docname": page.doc.name})
+ sitemap.doc.static_file_timestamp = os.path.getmtime(fpath)
+ sitemap.save()
+
+ synced.append(url)
+
+ # delete not synced
+ webnotes.delete_doc("Web Page", webnotes.conn.sql_list("""select docname from `tabWebsite Sitemap`
+ where ifnull(static_file_timestamp,'')!=''
+ and name not in ({}) """.format(', '.join(["%s"]*len(synced))), tuple(synced)))
+
+def get_static_content(fpath):
+ with open(fpath, "r") as contentfile:
+ content = contentfile.read()
+ if fpath.endswith(".md"):
+ content = markdown(content)
+
+ return content
+
+
diff --git a/webnotes/website/doctype/web_page/web_page.txt b/webnotes/website/doctype/web_page/web_page.txt
index 627cb70ae0..8dc4fee280 100644
--- a/webnotes/website/doctype/web_page/web_page.txt
+++ b/webnotes/website/doctype/web_page/web_page.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-03-28 10:35:30",
"docstatus": 0,
- "modified": "2014-02-05 17:02:09",
+ "modified": "2014-02-10 18:07:28",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -61,13 +61,20 @@
"reqd": 1
},
{
- "description": "Page url name (auto-generated) (add \".html\")",
+ "description": "Page url name (auto-generated)",
"doctype": "DocField",
"fieldname": "page_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Page Name",
- "read_only": 1
+ "read_only": 0
+ },
+ {
+ "doctype": "DocField",
+ "fieldname": "parent_website_sitemap",
+ "fieldtype": "Link",
+ "label": "Parent Website Page",
+ "options": "Website Sitemap"
},
{
"doctype": "DocField",
@@ -131,6 +138,12 @@
"label": "Text Align",
"options": "Left\nCenter\nRight"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "custom_javascript",
+ "fieldtype": "Section Break",
+ "label": "Custom Javascript"
+ },
{
"description": "Add code as <script>",
"doctype": "DocField",
@@ -146,6 +159,12 @@
"label": "Javascript",
"options": "Javascript"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "custom_css",
+ "fieldtype": "Section Break",
+ "label": "Custom CSS"
+ },
{
"doctype": "DocField",
"fieldname": "insert_style",
@@ -160,6 +179,12 @@
"label": "CSS",
"options": "CSS"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "table_of_contents",
+ "fieldtype": "Section Break",
+ "label": "Table of Contents"
+ },
{
"doctype": "DocField",
"fieldname": "show_title",
@@ -185,13 +210,6 @@
"label": "Table of Contents",
"options": "Table of Contents"
},
- {
- "doctype": "DocField",
- "fieldname": "parent_website_sitemap",
- "fieldtype": "Link",
- "label": "Parent Website Page",
- "options": "Website Sitemap"
- },
{
"doctype": "DocPerm"
}
diff --git a/webnotes/website/doctype/website_group/website_group.txt b/webnotes/website/doctype/website_group/website_group.txt
index ad6654604b..9eff115989 100644
--- a/webnotes/website/doctype/website_group/website_group.txt
+++ b/webnotes/website/doctype/website_group/website_group.txt
@@ -2,7 +2,7 @@
{
"creation": "2014-01-29 15:57:42",
"docstatus": 0,
- "modified": "2014-02-05 17:00:33",
+ "modified": "2014-02-10 14:38:12",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -39,6 +39,12 @@
"doctype": "DocType",
"name": "Website Group"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "name_and_description",
+ "fieldtype": "Section Break",
+ "label": "Name and Description"
+ },
{
"doctype": "DocField",
"fieldname": "group_name",
@@ -62,6 +68,20 @@
"options": "Forum\nTasks\nEvents",
"reqd": 1
},
+ {
+ "description": "Display in the sidebar of this Website Sitemap node",
+ "doctype": "DocField",
+ "fieldname": "parent_website_sitemap",
+ "fieldtype": "Link",
+ "in_list_view": 0,
+ "label": "Parent Website Page",
+ "options": "Website Sitemap"
+ },
+ {
+ "doctype": "DocField",
+ "fieldname": "column_break_6",
+ "fieldtype": "Column Break"
+ },
{
"doctype": "DocField",
"fieldname": "group_description",
@@ -77,6 +97,12 @@
"no_copy": 1,
"reqd": 0
},
+ {
+ "doctype": "DocField",
+ "fieldname": "details",
+ "fieldtype": "Section Break",
+ "label": "Details"
+ },
{
"doctype": "DocField",
"fieldname": "public_read",
@@ -90,13 +116,9 @@
"label": "Anyone Can Write"
},
{
- "description": "Display in the sidebar of this Website Sitemap node",
"doctype": "DocField",
- "fieldname": "parent_website_sitemap",
- "fieldtype": "Link",
- "in_list_view": 0,
- "label": "Parent Website Page",
- "options": "Website Sitemap"
+ "fieldname": "column_break_12",
+ "fieldtype": "Column Break"
},
{
"doctype": "DocField",
diff --git a/webnotes/website/doctype/website_sitemap/website_sitemap.py b/webnotes/website/doctype/website_sitemap/website_sitemap.py
index ebfeb33d63..985c4d4977 100644
--- a/webnotes/website/doctype/website_sitemap/website_sitemap.py
+++ b/webnotes/website/doctype/website_sitemap/website_sitemap.py
@@ -17,12 +17,46 @@ class DocType(DocTypeNestedSet):
self.nsm_parent_field = "parent_website_sitemap"
def autoname(self):
- self.doc.name = self.doc.page_name
+ self.doc.name = self.get_url()
+
+ def get_url(self):
+ url = self.doc.page_name
+ if self.doc.parent_website_sitemap:
+ url = self.doc.parent_website_sitemap + "/" + url
+
+ return url
def validate(self):
+ if self.get_url() != self.doc.name:
+ self.rename()
self.check_if_page_name_is_unique()
self.make_private_if_parent_is_private()
-
+
+ def rename(self):
+ from webnotes.webutils import clear_cache
+ self.old_name = self.doc.name
+ self.doc.name = self.get_url()
+ webnotes.conn.sql("""update `tabWebsite Sitemap` set name=%s where name=%s""",
+ (self.doc.name, self.old_name))
+ self.rename_links()
+ self.rename_descendants()
+ clear_cache(self.old_name)
+
+ def rename_links(self):
+ for doctype in webnotes.conn.sql_list("""select parent from tabDocField where fieldtype='Link' and
+ fieldname='parent_website_sitemap' and options='Website Sitemap'"""):
+ for name in webnotes.conn.sql_list("""select name from `tab{}`
+ where parent_website_sitemap=%s""".format(doctype), self.old_name):
+ webnotes.conn.set_value(doctype, name, "parent_website_sitemap", self.doc.name)
+
+ def rename_descendants(self):
+ # rename children
+ for name in webnotes.conn.sql_list("""select name from `tabWebsite Sitemap`
+ where parent_website_sitemap=%s""", self.doc.name):
+ child = webnotes.bean("Website Sitemap", name)
+ child.doc.parent_website_sitemap = self.doc.name
+ child.save()
+
def on_update(self):
if not webnotes.flags.in_rebuild_config:
DocTypeNestedSet.on_update(self)
@@ -50,10 +84,9 @@ class DocType(DocTypeNestedSet):
if not parent_pubic_read:
self.doc.public_read = self.doc.public_write = 0
-
- def on_trash(self):
+
+ def on_trash(self):
from webnotes.webutils import clear_cache
-
# remove website sitemap permissions
to_remove = webnotes.conn.sql_list("""select name from `tabWebsite Sitemap Permission`
where website_sitemap=%s""", (self.doc.name,))
@@ -78,6 +111,7 @@ def update_sitemap(website_sitemap, options):
for key in sitemap_fields:
bean.doc.fields[key] = options.get(key)
if not bean.doc.page_name:
+ # for pages
bean.doc.page_name = options.link_name
bean.doc.website_sitemap_config = options.link_name
diff --git a/webnotes/website/doctype/website_sitemap/website_sitemap.txt b/webnotes/website/doctype/website_sitemap/website_sitemap.txt
index 5b4ce0d191..9ee728bd1f 100644
--- a/webnotes/website/doctype/website_sitemap/website_sitemap.txt
+++ b/webnotes/website/doctype/website_sitemap/website_sitemap.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-11-18 15:38:40",
"docstatus": 0,
- "modified": "2014-01-30 16:50:49",
+ "modified": "2014-02-10 18:10:11",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -137,6 +137,12 @@
"fieldtype": "Check",
"label": "Anyone Can Write"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "static_file_timestamp",
+ "fieldtype": "Data",
+ "label": "Static File Timestamp"
+ },
{
"doctype": "DocPerm"
}
diff --git a/webnotes/website/js/website.js b/webnotes/website/js/website.js
index 4bd60df49c..e637692d2c 100644
--- a/webnotes/website/js/website.js
+++ b/webnotes/website/js/website.js
@@ -424,7 +424,7 @@ $(document).ready(function() {
$(document).on("page_change", function() {
$(".page-header").toggleClass("hidden", !!!$(".page-header").text().trim());
$(".page-footer").toggleClass("hidden", !!!$(".page-footer").text().trim());
- $(".page-breadcrumbs").toggleClass("hidden", !!!$(".page-breadcrumbs").text().trim());
+ //$(".page-breadcrumbs").toggleClass("hidden", !!!$(".page-breadcrumbs").text().trim());
// add prive pages to sidebar
if(website.private_pages && $(".page-sidebar").length) {
diff --git a/webnotes/website/js/website_group.js b/webnotes/website/js/website_group.js
index e79280e3b6..5d652629b8 100644
--- a/webnotes/website/js/website_group.js
+++ b/webnotes/website/js/website_group.js
@@ -77,7 +77,7 @@ $.extend(website, {
post: website.post || undefined
}, values),
callback: function(data) {
- var url = "/" + website.group + "?view=post&name=" + data.message;
+ var url = window.location.pathname + "?view=post&name=" + data.message;
window.location.href = url;
// if(history.pushState) {
diff --git a/webnotes/website/page/website_home/website_home.js b/webnotes/website/page/website_home/website_home.js
index 2d7a272746..29d9f7d4d8 100644
--- a/webnotes/website/page/website_home/website_home.js
+++ b/webnotes/website/page/website_home/website_home.js
@@ -12,6 +12,11 @@ wn.module_page["Website"] = [
description: wn._("Content web page."),
doctype:"Web Page"
},
+ {
+ label: wn._("Website Group"),
+ description: wn._("Web Site Forum Page."),
+ doctype:"Web Page"
+ },
{
label: wn._("Blog Post"),
description: wn._("Single Post (article)."),
diff --git a/webnotes/webutils.py b/webnotes/webutils.py
index d2cde07ff7..2353e70abd 100644
--- a/webnotes/webutils.py
+++ b/webnotes/webutils.py
@@ -77,7 +77,7 @@ def build_page(page_name):
html = webnotes.get_template(context.base_template_path).render(context)
html = scrub_relative_urls(html)
-
+
if can_cache(context.no_cache):
webnotes.cache().set_value("page:" + page_name, html)
@@ -126,12 +126,7 @@ def get_sitemap_options(page_name):
def build_sitemap_options(page_name):
sitemap_options = webnotes.doc("Website Sitemap", page_name).fields
-
- # only non default fields
- for fieldname in default_fields:
- if fieldname in sitemap_options:
- del sitemap_options[fieldname]
-
+
sitemap_config = webnotes.doc("Website Sitemap Config",
sitemap_options.get("website_sitemap_config")).fields
@@ -142,13 +137,14 @@ def build_sitemap_options(page_name):
sitemap_options.doctype = sitemap_options.ref_doctype
sitemap_options.title = sitemap_options.page_title
+ sitemap_options.pathname = sitemap_options.name
# 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""", (sitemap_options.page_name,), as_dict=True)
+ where parent_website_sitemap=%s and public_read=1""", (sitemap_options.name,), as_dict=True)
# determine templates to be used
if not sitemap_options.base_template_path:
@@ -254,10 +250,7 @@ def is_ajax():
def scrub_page_name(page_name):
if not page_name:
page_name = "index"
-
- if "/" in page_name:
- page_name = page_name.split("/")[0]
-
+
if page_name.endswith('.html'):
page_name = page_name[:-5]
@@ -316,6 +309,16 @@ def call_website_generator(bean, method):
getattr(WebsiteGenerator(bean.doc, bean.doclist), method)()
class WebsiteGenerator(DocListController):
+ def set_page_name(self):
+ """set page name based on parent page_name and title"""
+ page_name = cleanup_page_name(self.get_page_title)
+ if self.doc.parent_website_sitemap:
+ page_name = self.doc.parent_website_sitemap + "/" + page_name
+
+ webnotes.conn.set(self.doc, self._website_config.page_name_field, page_name)
+
+ return page_name
+
def setup_generator(self):
if webnotes.flags.in_install_app:
return
@@ -354,7 +357,7 @@ class WebsiteGenerator(DocListController):
def add_or_update_sitemap(self):
page_name = self.get_page_name()
- existing_page_name = webnotes.conn.get_value("Website Sitemap", {"ref_doctype": self.doc.doctype,
+ existing_site_map = webnotes.conn.get_value("Website Sitemap", {"ref_doctype": self.doc.doctype,
"docname": self.doc.name})
opts = webnotes._dict({
@@ -365,32 +368,35 @@ 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() \
- if hasattr(self, "get_page_title") else (self.doc.title or self.doc.name)
+ "page_title": self.get_page_title()
})
-
+
+ self.update_permissions(opts)
+
+ if existing_site_map:
+ update_sitemap(existing_site_map, opts)
+ else:
+ add_to_sitemap(opts)
+
+ def update_permissions(self, opts):
if self.meta.get_field("public_read"):
opts.public_read = self.doc.public_read
opts.public_write = self.doc.public_write
else:
opts.public_read = 1
-
- if existing_page_name:
- if existing_page_name != page_name:
- webnotes.rename_doc("Website Sitemap", existing_page_name, page_name, ignore_permissions=True)
- update_sitemap(page_name, opts)
- else:
- add_to_sitemap(opts)
-
- def get_page_name(self):
- if not self.doc.fields.get(self._website_config.page_name_field):
- new_page_name = cleanup_page_name(self.get_page_title() \
- if hasattr(self, "get_page_title") else (self.doc.title or self.doc.name))
- webnotes.conn.set(self.doc, self._website_config.page_name_field, new_page_name)
+ def get_page_name(self):
+ if not self._get_page_name():
+ self.set_page_name()
+ return self._get_page_name()
+
+ def _get_page_name(self):
return self.doc.fields.get(self._website_config.page_name_field)
+ def get_page_title(self):
+ return self.doc.title or (self.doc.name.replace("-", " ").replace("_", " ").title())
+
def cleanup_page_name(title):
"""make page name from title"""
import re
@@ -436,7 +442,7 @@ def render_blocks(context):
out = {}
template = webnotes.get_template(context["template_path"])
-
+
# required as per low level API
context = template.new_context(context)