Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Anand Doshi 2012-12-06 16:50:46 +05:30
commit c62dabdead
16 changed files with 434 additions and 835 deletions

View File

@ -64,11 +64,11 @@ class DocType:
def validate_balance_leaves(self):
if self.doc.from_date and self.doc.to_date and not self.is_lwp():
bal = get_leave_balance(self.doc.leave_type, self.doc.employee,
self.doc.fiscal_year)["leave_balance"]
self.doc.fiscal_year)
tot_leaves = self.get_total_leave_days()
bal, tot_leaves = bal, tot_leaves
webnotes.conn.set(self.doc,'leave_balance',flt(bal['leave_balance']))
webnotes.conn.set(self.doc,'total_leave_days',flt(tot_leaves['total_leave_days']))
webnotes.conn.set(self.doc, 'leave_balance', flt(bal['leave_balance']))
webnotes.conn.set(self.doc, 'total_leave_days', flt(tot_leaves['total_leave_days']))
if flt(bal['leave_balance']) < flt(tot_leaves['total_leave_days']):
msgprint("Warning : There is not enough leave balance")

View File

@ -0,0 +1,24 @@
from __future__ import unicode_literals
import webnotes
def execute():
# set page published = 1
webnotes.reload_doc("website", "doctype", "web_page")
webnotes.conn.sql("""update `tabWeb Page` set published=1;""")
# convert all page & blog markdowns to html
from markdown2 import markdown
for page in webnotes.conn.sql("""select name, main_section from `tabWeb Page`"""):
m = markdown(page[1]).encode("utf8")
webnotes.conn.set_value("Web Page", page[0], "main_section", m)
for page in webnotes.conn.sql("""select name, content from `tabBlog`"""):
m = markdown(page[1]).encode("utf8")
webnotes.conn.set_value("Blog", page[0], "content", m)
# delete website cache
webnotes.conn.commit()
webnotes.delete_doc("DocType", "Web Cache")
webnotes.conn.sql("""drop table if exists `tabWeb Cache`""")

View File

@ -725,4 +725,8 @@ patch_list = [
'patch_module': 'patches.december_2012',
'patch_file': 'reload_debtors_creditors_ledger',
},
{
'patch_module': 'patches.december_2012',
'patch_file': 'website_cache_refactor',
},
]

View File

@ -25,9 +25,7 @@ from webnotes import msgprint
sql = webnotes.conn.sql
class DocType:
class DocType():
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
@ -40,7 +38,9 @@ class DocType:
return ret
def on_update(self):
self.update_page_name()
# webpage updates
from website.utils import update_page_name
update_page_name(self.doc, self.doc.item_name)
bin = sql("select stock_uom from `tabBin` where item_code = '%s' " % self.doc.item_code)
if bin and cstr(bin[0][0]) != cstr(self.doc.stock_uom):
@ -74,8 +74,6 @@ class DocType:
child.conversion_factor = 1
child.save()
self.clear_web_cache()
# On delete 1. Delete BIN (if none of the corrosponding transactions present, it gets deleted. if present, rolled back due to exception)
def on_trash(self):
sql("""delete from tabBin where item_code=%s""", self.doc.item_code)
@ -194,39 +192,6 @@ class DocType:
def on_rename(self,newdn,olddn):
sql("update tabItem set item_code = %s where name = %s", (newdn, olddn))
def delete_web_cache(self, page_name):
import website.web_cache
website.web_cache.delete_cache(page_name)
def clear_web_cache(self):
if hasattr(self, 'old_page_name') and self.old_page_name and \
self.doc.page_name != self.old_page_name:
self.delete_web_cache(self.doc.page_name)
if self.doc.show_in_website:
import website.web_cache
website.web_cache.create_cache(self.doc.page_name, self.doc.doctype, self.doc.name)
website.web_cache.clear_cache(self.doc.page_name, self.doc.doctype, self.doc.name)
else:
self.delete_web_cache(self.doc.page_name)
def update_page_name(self):
import website.utils
# if same name, do not repeat twice
if self.doc.name == self.doc.item_name or not self.doc.item_name:
page_name = self.doc.name
else:
page_name = self.doc.name + " " + self.doc.item_name
self.doc.page_name = website.utils.page_name(page_name)
webnotes.conn.set_value('Item', self.doc.name, 'page_name', self.doc.page_name)
# no need to check for uniqueness, as name is unique
def prepare_template_args(self):
import markdown2
self.doc.web_description_html = markdown2.markdown(self.doc.description or '',
extras=["wiki-tables"])
self.doc.web_description_html = self.doc.description or ''

View File

@ -15,12 +15,11 @@ def get_blog_list(args=None):
query = """\
select
cache.name as name, cache.html as content,
blog.owner as owner, blog.creation as published,
blog.title as title, (select count(name) from `tabComment` where
comment_doctype='Blog' and comment_docname=blog.name) as comments
from `tabWeb Cache` cache, `tabBlog` blog
where cache.doc_type = 'Blog' and blog.page_name = cache.name
name, content, owner, creation as creation,
title, (select count(name) from `tabComment` where
comment_doctype='Blog' and comment_docname=name) as comments
from `tabBlog`
where ifnull(published,0)=1
order by published desc, name asc"""
from webnotes.widgets.query_builder import add_limit_to_query
@ -35,7 +34,7 @@ def get_blog_list(args=None):
for res in result:
from webnotes.utils import global_date_format, get_fullname
res['full_name'] = get_fullname(res['owner'])
res['published'] = global_date_format(res['published'])
res['published'] = global_date_format(res['creation'])
if not res['content']:
res['content'] = website.web_cache.get_html(res['name'])
res['content'] = split_blog_content(res['content'])
@ -147,19 +146,14 @@ def add_subscriber():
def get_blog_content(blog_page_name):
import website.web_cache
content = website.web_cache.get_html(blog_page_name)
content = split_blog_content(content)
import webnotes.utils
content = webnotes.utils.escape_html(content)
return content
def split_blog_content(content):
content = content.split("<!-- begin blog content -->")
content = len(content) > 1 and content[1] or content[0]
content = content.split("<!-- end blog content -->")
content = content[0]
return content

View File

@ -18,20 +18,25 @@ from __future__ import unicode_literals
import webnotes
import website.utils
import website.web_page
class DocType(website.web_page.Page):
class DocType():
def __init__(self, d, dl):
super(DocType, self).__init__('Blog')
self.doc, self.doclist = d, dl
def autoname(self):
from website.utils import page_name
self.doc.name = page_name(self.doc.title)
def on_update(self):
from website.utils import update_page_name
update_page_name(self.doc, self.doc.title)
def send_emails(self):
"""send emails to subscribers"""
if self.doc.email_sent:
webnotes.msgprint("""Blog Subscribers already updated""", raise_exception=1)
from webnotes.utils.email_lib.bulk import send
from markdown2 import markdown
import webnotes.utils
# get leads that are subscribed to the blog
@ -40,23 +45,15 @@ class DocType(website.web_page.Page):
# make heading as link
content = '<h2><a href="%s/%s.html">%s</a></h2>\n\n%s' % (webnotes.utils.get_request_site_address(),
self.doc.page_name, self.doc.title, markdown(self.doc.content))
self.doc.page_name, self.doc.title, self.doc.content)
# send the blog
send(recipients = recipients, doctype='Lead', email_field='email_id',
subject=self.doc.title, message = markdown(content))
subject=self.doc.title, message = content)
webnotes.conn.set(self.doc, 'email_sent', 1)
webnotes.msgprint("""Scheduled to send to %s subscribers""" % len(recipients))
def on_update(self):
super(DocType, self).on_update()
if not webnotes.utils.cint(self.doc.published):
self.delete_web_cache(self.doc.page_name)
else:
import website.blog
website.blog.get_blog_content(self.doc.page_name)
def prepare_template_args(self):
import webnotes.utils
@ -68,8 +65,7 @@ class DocType(website.web_page.Page):
from webnotes.utils import global_date_format, get_fullname
self.doc.full_name = get_fullname(self.doc.owner)
self.doc.updated = global_date_format(self.doc.creation)
self.markdown_to_html(['content'])
self.doc.content_html = self.doc.content
comment_list = webnotes.conn.sql("""\
select comment, comment_by_fullname, creation

View File

@ -1,137 +1,102 @@
# DocType, Blog
[
# These values are common in all dictionaries
{
'creation': '2012-07-27 19:32:53',
'docstatus': 0,
'modified': '2012-08-03 12:18:36',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all DocType
{
'_last_update': u'1328599743',
'allow_attach': 1,
'colour': u'White:FFF',
'doctype': 'DocType',
'max_attachments': 5,
'module': u'Website',
'name': '__common__',
'section_style': u'Simple',
'show_in_menu': 0,
'version': 1
},
# These values are common for all DocField
{
'doctype': u'DocField',
'name': '__common__',
'parent': u'Blog',
'parentfield': u'fields',
'parenttype': u'DocType'
},
# These values are common for all DocPerm
{
'doctype': u'DocPerm',
'name': '__common__',
'parent': u'Blog',
'parentfield': u'permissions',
'parenttype': u'DocType',
'permlevel': 0,
'read': 1
},
# DocType, Blog
{
'doctype': 'DocType',
'name': u'Blog'
},
# DocPerm
{
'create': 1,
'doctype': u'DocPerm',
'role': u'Website Manager',
'write': 1
},
# DocPerm
{
'create': 1,
'doctype': u'DocPerm',
'role': u'Blogger',
'write': 1
},
# DocPerm
{
'doctype': u'DocPerm',
'role': u'Guest',
'write': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'title',
'fieldtype': u'Data',
'label': u'Title',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'published',
'fieldtype': u'Check',
'label': u'Published',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'content',
'fieldtype': u'Code',
'label': u'Content',
'options': u'Markdown',
'permlevel': 0,
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'page_name',
'fieldtype': u'Data',
'hidden': 1,
'label': u'Page Name',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'email_sent',
'fieldtype': u'Check',
'hidden': 1,
'label': u'Email Sent',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'file_list',
'fieldtype': u'Text',
'hidden': 1,
'label': u'File List',
'no_copy': 1,
'permlevel': 0,
'print_hide': 1
}
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-11-30 18:14:18",
"modified_by": "Administrator",
"modified": "2012-12-06 16:33:36"
},
{
"allow_attach": 1,
"doctype": "DocType",
"module": "Website",
"max_attachments": 5,
"name": "__common__"
},
{
"name": "__common__",
"parent": "Blog",
"doctype": "DocField",
"parenttype": "DocType",
"parentfield": "fields"
},
{
"name": "__common__",
"parent": "Blog",
"read": 1,
"doctype": "DocPerm",
"parenttype": "DocType",
"permlevel": 0,
"parentfield": "permissions"
},
{
"name": "Blog",
"doctype": "DocType"
},
{
"doctype": "DocField",
"label": "Title",
"fieldname": "title",
"fieldtype": "Data",
"reqd": 1,
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Published",
"fieldname": "published",
"fieldtype": "Check",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Content",
"fieldname": "content",
"fieldtype": "Text Editor",
"reqd": 0,
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Page Name",
"fieldname": "page_name",
"fieldtype": "Data",
"hidden": 1,
"permlevel": 1
},
{
"doctype": "DocField",
"label": "Email Sent",
"fieldname": "email_sent",
"fieldtype": "Check",
"hidden": 1,
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"doctype": "DocField",
"label": "File List",
"fieldname": "file_list",
"fieldtype": "Text",
"hidden": 1,
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",
"write": 1,
"role": "Website Manager"
},
{
"create": 1,
"doctype": "DocPerm",
"write": 1,
"role": "Blogger"
},
{
"write": 0,
"role": "Guest",
"doctype": "DocPerm"
}
]

View File

@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@ -1,22 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl

View File

@ -1,99 +0,0 @@
# DocType, Web Cache
[
# These values are common in all dictionaries
{
u'creation': '2012-07-12 22:19:44',
u'docstatus': 0,
u'modified': '2012-09-17 10:48:17',
u'modified_by': u'Administrator',
u'owner': u'Administrator'
},
# These values are common for all DocType
{
u'doctype': u'DocType',
'document_type': u'System',
'module': u'Website',
u'name': u'__common__',
'version': 1
},
# These values are common for all DocField
{
u'doctype': u'DocField',
u'name': u'__common__',
'parent': u'Web Cache',
'parentfield': u'fields',
'parenttype': u'DocType',
'permlevel': 0
},
# These values are common for all DocPerm
{
u'doctype': u'DocPerm',
u'name': u'__common__',
'parent': u'Web Cache',
'parentfield': u'permissions',
'parenttype': u'DocType',
'permlevel': 0,
'read': 1,
'write': 1
},
# DocType, Web Cache
{
u'doctype': u'DocType',
u'name': u'Web Cache'
},
# DocField
{
u'doctype': u'DocField',
'fieldname': u'doc_type',
'fieldtype': u'Link',
'in_filter': 1,
'label': u'DocType',
'options': u'DocType',
'reqd': 1
},
# DocField
{
u'doctype': u'DocField',
'fieldname': u'doc_name',
'fieldtype': u'Data',
'in_filter': 0,
'label': u'DocName',
'reqd': 1
},
# DocField
{
u'doctype': u'DocField',
'fieldname': u'html',
'fieldtype': u'Long Text',
'label': u'HTML'
},
# DocPerm
{
'create': 0,
u'doctype': u'DocPerm',
'role': u'Guest'
},
# DocPerm
{
'create': 1,
u'doctype': u'DocPerm',
'role': u'Website Manager'
},
# DocPerm
{
'create': 1,
u'doctype': u'DocPerm',
'role': u'Blogger'
}
]

View File

@ -16,16 +16,18 @@
from __future__ import unicode_literals
import webnotes
import website.utils
import website.web_page
class DocType(website.web_page.Page):
class DocType():
def __init__(self, d, dl):
super(DocType, self).__init__('Web Page')
self.doc, self.doclist = d, dl
def autoname(self):
from website.utils import page_name
self.doc.name = page_name(self.doc.title)
def on_update(self):
super(DocType, self).on_update()
from website.utils import update_page_name
update_page_name(self.doc, self.doc.title)
self.if_home_clear_cache()
def if_home_clear_cache(self):
@ -33,9 +35,11 @@ class DocType(website.web_page.Page):
if webnotes.conn.get_value("Website Settings", None, "home_page")==self.doc.name:
from webnotes.sessions import clear_cache
clear_cache('Guest')
import website.web_cache
website.web_cache.clear_cache(self.doc.page_name)
website.web_cache.clear_cache('index')
from website.web_cache import clear_cache
clear_cache(self.doc.page_name)
clear_cache('index')
def prepare_template_args(self):
self.markdown_to_html(['head_section','main_section', 'side_section'])
self.doc.main_section_html = self.doc.main_section
self.doc.side_section_html = self.doc.side_section

View File

@ -1,244 +1,188 @@
# DocType, Web Page
[
# These values are common in all dictionaries
{
'creation': '2012-06-19 15:02:20',
'docstatus': 0,
'modified': '2012-06-22 18:49:02',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all DocType
{
'_last_update': u'1328093379',
'allow_attach': 1,
'colour': u'White:FFF',
'description': u'A custom page is a simple page with the layout - headline, main section, side section\n\nEditing:\n\n- Editing is in [markdown format](http://daringfireball.net/projects/markdown/syntax)\n- You can also add images and embed html code\n\nAccessing the page:\n\n- The page can be accessed as #![page-name] after the main url\n\nIdeal for pages like FAQ, Terms and Conditions, Help etc.\n\n',
'doctype': 'DocType',
'max_attachments': 20,
'module': u'Website',
'name': '__common__',
'section_style': u'Simple',
'show_in_menu': 0,
'version': 1
},
# These values are common for all DocField
{
'doctype': u'DocField',
'name': '__common__',
'parent': u'Web Page',
'parentfield': u'fields',
'parenttype': u'DocType'
},
# These values are common for all DocPerm
{
'amend': 0,
'doctype': u'DocPerm',
'name': '__common__',
'parent': u'Web Page',
'parentfield': u'permissions',
'parenttype': u'DocType',
'read': 1,
'role': u'Website Manager',
'submit': 0
},
# DocType, Web Page
{
'doctype': 'DocType',
'name': u'Web Page'
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'write': 1
},
# DocPerm
{
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'write': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'sb0',
'fieldtype': u'Section Break',
'label': u'Title and Style',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Title / headline of your page',
'doctype': u'DocField',
'fieldname': u'title',
'fieldtype': u'Data',
'label': u'Title',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'colour': u'White:FFF',
'description': u'Page url name (auto-generated) ',
'doctype': u'DocField',
'fieldname': u'page_name',
'fieldtype': u'Data',
'label': u'Page Name',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'cb1',
'fieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'layout',
'fieldtype': u'Select',
'label': u'Layout',
'options': u'Single column\nTwo column\nTwo column with header',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Page content',
'doctype': u'DocField',
'fieldname': u'sb1',
'fieldtype': u'Section Break',
'label': u'Content',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Section that will span 2 columns, formatted as markdown. If no head, leave blank. If you are displaying a banner, it must be 860px',
'doctype': u'DocField',
'fieldname': u'head_section',
'fieldtype': u'Text',
'label': u'Head Section',
'options': u'Markdown',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Content in markdown format that appears on the main side of your page',
'doctype': u'DocField',
'fieldname': u'main_section',
'fieldtype': u'Code',
'label': u'Main Section',
'options': u'Markdown',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Content in markdown format that appears on the right side',
'doctype': u'DocField',
'fieldname': u'side_section',
'fieldtype': u'Code',
'label': u'Side Section',
'options': u'Markdown',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Link to other pages in the side bar and next section',
'doctype': u'DocField',
'fieldname': u'sb2',
'fieldtype': u'Section Break',
'label': u'More',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'text_align',
'fieldtype': u'Select',
'label': u'Text Align',
'options': u'Left\nCenter\nRight',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Add code as &lt;script&gt;',
'doctype': u'DocField',
'fieldname': u'insert_code',
'fieldtype': u'Check',
'label': u'Insert Code',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'javascript',
'fieldtype': u'Code',
'label': u'Javascript',
'options': u'Javascript',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'insert_style',
'fieldtype': u'Check',
'label': u'Insert Style',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'css',
'fieldtype': u'Code',
'label': u'CSS',
'options': u'CSS',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'file_list',
'fieldtype': u'Text',
'hidden': 1,
'label': u'File List',
'no_copy': 1,
'permlevel': 0,
'print_hide': 1
}
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-11-30 18:14:18",
"modified_by": "Administrator",
"modified": "2012-12-06 15:59:02"
},
{
"allow_attach": 1,
"doctype": "DocType",
"module": "Website",
"name": "__common__",
"max_attachments": 20,
"document_type": "Transaction",
"description": "Page to show on the website\n"
},
{
"name": "__common__",
"parent": "Web Page",
"doctype": "DocField",
"parenttype": "DocType",
"parentfield": "fields"
},
{
"name": "__common__",
"parent": "Web Page",
"read": 1,
"submit": 0,
"doctype": "DocPerm",
"amend": 0,
"parenttype": "DocType",
"role": "Website Manager",
"parentfield": "permissions"
},
{
"name": "Web Page",
"doctype": "DocType"
},
{
"doctype": "DocField",
"label": "Title and Style",
"fieldname": "sb0",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"description": "Title / headline of your page",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Title",
"fieldname": "title",
"fieldtype": "Data",
"reqd": 1,
"permlevel": 0
},
{
"description": "Page url name (auto-generated) ",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Page Name",
"fieldname": "page_name",
"fieldtype": "Data",
"permlevel": 1
},
{
"doctype": "DocField",
"width": "50%",
"fieldname": "cb1",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Published",
"fieldname": "published",
"fieldtype": "Check",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Layout",
"options": "Single column\nTwo column",
"fieldname": "layout",
"fieldtype": "Select",
"permlevel": 0
},
{
"description": "Page content",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Content",
"fieldname": "sb1",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"description": "Content in markdown format that appears on the main side of your page",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Main Section",
"fieldname": "main_section",
"fieldtype": "Text Editor",
"permlevel": 0
},
{
"description": "Content in markdown format that appears on the right side",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Side Section",
"fieldname": "side_section",
"fieldtype": "Text Editor",
"permlevel": 0
},
{
"description": "Link to other pages in the side bar and next section",
"colour": "White:FFF",
"doctype": "DocField",
"label": "More",
"fieldname": "sb2",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Text Align",
"options": "Left\nCenter\nRight",
"fieldname": "text_align",
"fieldtype": "Select",
"permlevel": 0
},
{
"description": "Add code as &lt;script&gt;",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Insert Code",
"fieldname": "insert_code",
"fieldtype": "Check",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Javascript",
"options": "Javascript",
"fieldname": "javascript",
"fieldtype": "Code",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Insert Style",
"fieldname": "insert_style",
"fieldtype": "Check",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "CSS",
"options": "CSS",
"fieldname": "css",
"fieldtype": "Code",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"doctype": "DocField",
"label": "File List",
"fieldname": "file_list",
"fieldtype": "Text",
"hidden": 1,
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",
"write": 1,
"cancel": 1,
"permlevel": 0
},
{
"create": 0,
"doctype": "DocPerm",
"write": 0,
"cancel": 0,
"permlevel": 1
}
]

View File

@ -20,11 +20,6 @@ class DocType:
self.doc, self.doclist = d, dl
def validate(self):
"""
* set home page
* validate domain list
* clear cache
"""
self.set_home_page()
def on_update(self):
@ -32,10 +27,9 @@ class DocType:
from webnotes.cms.make import make_web_core
make_web_core()
# clear web cache
import website.web_cache
#website.web_cache.refresh_cache(build=['Blog'])
website.web_cache.refresh_cache()
# clear web cache (for menus!)
from website.web_cache import clear_cache
clear_cache()
from webnotes.sessions import clear_cache
clear_cache('Guest')

View File

@ -19,7 +19,6 @@ import webnotes
def render(page_name):
"""render html page"""
import webnotes
try:
if page_name:
html = get_html(page_name)
@ -37,13 +36,11 @@ def get_html(page_name):
page_name = scrub_page_name(page_name)
comments = get_comments(page_name)
import website.web_cache
html = website.web_cache.get_html(page_name, comments)
from website.web_cache import get_page_html
html = get_page_html(page_name, comments)
return html
def get_comments(page_name):
import webnotes
def get_comments(page_name):
if page_name == '404':
comments = """error: %s""" % webnotes.getTraceback()
else:
@ -60,9 +57,7 @@ def scrub_page_name(page_name):
def make_template(doc, path, convert_fields = ['main_section', 'side_section']):
"""make template"""
import os, jinja2
markdown(doc, convert_fields)
# write template
with open(path, 'r') as f:
temp = jinja2.Template(f.read())
@ -75,3 +70,16 @@ def page_name(title):
name = title.lower()
name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
return '-'.join(name.split()[:4])
def update_page_name(doc, title):
"""set page_name and check if it is unique"""
webnotes.conn.sql(doc, "page_name", title)
res = webnotes.conn.sql("""\
select count(*) from `tab%s`
where page_name=%s and name!=%s""" % (doc.doctype, '%s', '%s'),
(doc.page_name, doc.name))
if res and res[0][0] > 0:
webnotes.msgprint("""A %s with the same title already exists.
Please change the title of %s and save again."""
% (doc.doctype, doc.name), raise_exception=1)

View File

@ -17,25 +17,29 @@
# html generation functions
from __future__ import unicode_literals
import os
import conf
import webnotes
import website.utils
template_map = {
'Web Page': 'html/web_page.html',
'Blog': 'html/blog_page.html',
'Item': 'html/product_page.html',
}
def get_html(page_name, comments=''):
import conf
def get_page_html(page_name, comments=''):
html = ''
# load from cache, if auto cache clear is falsy
if not (hasattr(conf, 'auto_cache_clear') and conf.auto_cache_clear or 0):
html = load_from_cache(page_name)
comments += "\n\npage load status: from cache"
html = webnotes.cache().get_value("page:" + page_name)
comments += "\n\npage load status: fresh"
if not html:
html = load_into_cache(page_name)
comments += "\n\npage load status: fresh"
comments += "\n\npage load status: cache"
# insert comments
import webnotes.utils
@ -43,9 +47,37 @@ def get_html(page_name, comments=''):
return html
def load_from_cache(page_name):
import webnotes
def load_into_cache(page_name):
templates_path = os.path.join(os.path.dirname(conf.__file__),
'app', 'website', 'templates')
args = prepare_args(page_name)
from jinja2 import Environment, FileSystemLoader
jenv = Environment(loader = FileSystemLoader(templates_path))
html = jenv.get_template(args['template']).render(args)
return html
html = build_html()
webnotes.cache().set_value("page:" + page_name, html)
return html
def prepare_args(page_name):
if page_name == 'index':
page_name = get_home_page()
if page_name in get_predefined_pages():
args = {
'template': 'pages/%s.html' % page_name,
'name': page_name,
}
else:
args = get_doc_fields(page_name)
args.update(get_outer_env())
return args
def load_from_cache(page_name):
result = search_cache(page_name)
if not result:
@ -58,61 +90,16 @@ def load_from_cache(page_name):
return result[0][0]
def load_into_cache(page_name):
args = prepare_args(page_name)
html = build_html(args)
# create cache entry for predefined pages, if not exists
if page_name in get_predefined_pages():
create_cache(page_name)
import webnotes
webnotes.conn.begin()
webnotes.conn.set_value('Web Cache', page_name, 'html', html)
webnotes.conn.commit()
return html
def get_predefined_pages():
"""
gets a list of predefined pages
they do not exist in `tabWeb Page`
"""
import os
import conf
import website.utils
def get_predefined_pages():
pages_path = os.path.join(os.path.dirname(conf.__file__), 'app',
'website', 'templates', 'pages')
page_list = []
for page in os.listdir(pages_path):
page_list.append(website.utils.scrub_page_name(page))
return page_list
def prepare_args(page_name):
import webnotes
if page_name == 'index':
page_name = get_home_page()
if page_name in get_predefined_pages():
args = {
'template': 'pages/%s.html' % page_name,
'name': page_name,
'webnotes': webnotes
}
else:
args = get_doc_fields(page_name)
args.update(get_outer_env())
return args
def get_home_page():
import webnotes
doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
if doc_name:
page_name = webnotes.conn.get_value('Web Page', doc_name, 'page_name')
@ -122,12 +109,9 @@ def get_home_page():
return page_name
def get_doc_fields(page_name):
import webnotes
doc_type, doc_name = webnotes.conn.get_value('Web Cache', page_name,
['doc_type', 'doc_name'])
doc_type, doc_name = get_source_doc(page_name)
import webnotes.model.code
obj = webnotes.model.code.get_obj(doc_type, doc_name)
obj = webnotes.get_obj(doc_type, doc_name)
if hasattr(obj, 'prepare_template_args'):
obj.prepare_template_args()
@ -137,12 +121,19 @@ def get_doc_fields(page_name):
return args
def get_outer_env():
"""
env dict for outer template
"""
import webnotes
def get_source_doc(page_name):
"""get source doc for the given page name"""
for doctype in [('Web Page', 'published'), ('Blog', 'published'),
('Item', 'show_in_website')]:
name = webnotes.conn.sql("""select name from `tab%s` where
page_name=%s and ifnull(`%s`, 0)=1""" % (doctype[0], "%s", doctype[1]),
page_name)
if name:
return doctype[0], name[0][0]
return None, None
def get_outer_env():
all_top_items = webnotes.conn.sql("""\
select * from `tabTop Bar Item`
where parent='Website Settings' and parentfield='top_bar_items'
@ -173,97 +164,11 @@ def get_outer_env():
'favicon': webnotes.conn.get_value('Website Settings', None, 'favicon')
}
def build_html(args):
"""
build html using jinja2 templates
"""
import os
import conf
templates_path = os.path.join(os.path.dirname(conf.__file__), 'app', 'website', 'templates')
from jinja2 import Environment, FileSystemLoader
jenv = Environment(loader = FileSystemLoader(templates_path))
html = jenv.get_template(args['template']).render(args)
return html
# cache management
def search_cache(page_name):
if not page_name: return ()
import webnotes
return webnotes.conn.sql("""\
select html, doc_type, doc_name
from `tabWeb Cache`
where name = %s""", page_name)
def create_cache(page_name, doc_type=None, doc_name=None):
# check if a record already exists
result = search_cache(page_name)
if result: return
# create a Web Cache record
import webnotes.model.doc
d = webnotes.model.doc.Document('Web Cache')
d.name = page_name
d.doc_type = doc_type
d.doc_name = doc_name
d.html = None
d.save()
def clear_cache(page_name, doc_type=None, doc_name=None):
"""
* if no page name, clear whole cache
* if page_name, doc_type and doc_name match, clear cache's copy
* else, raise exception that such a page already exists
"""
import webnotes
if not page_name:
webnotes.conn.sql("""update `tabWeb Cache` set html = ''""")
return
result = search_cache(page_name)
if not doc_type or (result and result[0][1] == doc_type and result[0][2] == doc_name):
webnotes.conn.set_value('Web Cache', page_name, 'html', '')
if page_name:
delete_page_cache(page_name)
else:
webnotes.msgprint("""Page with name "%s" already exists as a %s.
Please save it with another name.""" % (page_name, result[0][1]),
raise_exception=1)
def delete_cache(page_name):
"""
delete entry of page_name from Web Cache
used when:
* web page is deleted
* blog is un-published
"""
import webnotes
webnotes.conn.sql("""delete from `tabWeb Cache` where name=%s""", (page_name,))
def refresh_cache(build=None):
"""delete and re-create web cache entries"""
import webnotes
webnotes.cache().flush_keys("page:")
# webnotes.conn.sql("delete from `tabWeb Cache`")
clear_cache(None)
query_map = {
'Web Page': """select page_name, name from `tabWeb Page` where docstatus=0""",
'Blog': """\
select page_name, name from `tabBlog`
where docstatus = 0 and ifnull(published, 0) = 1""",
'Item': """\
select page_name, name from `tabItem`
where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
}
for dt in query_map:
if build and dt in build:
for result in webnotes.conn.sql(query_map[dt], as_dict=1):
create_cache(result['page_name'], dt, result['name'])
load_into_cache(result['page_name'])
for page_name in get_predefined_pages():
create_cache(page_name, None, None)
if build: load_into_cache(page_name)
def delete_page_cache(page_name):
webnotes.cache().delete_value("page:" + page_name)

View File

@ -1,82 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
import website.utils
import website.web_cache
class Page(object):
def __init__(self, doctype):
self.doctype = doctype
def autoname(self):
"""name from title"""
self.doc.name = website.utils.page_name(self.doc.title)
def validate(self):
if self.doc.name:
self.old_page_name = webnotes.conn.get_value(self.doctype, self.doc.name, 'page_name')
def on_update(self):
# page name updates with the title
self.update_page_name()
self.clear_web_cache()
self.doc.save()
def on_trash(self):
"""delete Web Cache entry"""
self.delete_web_cache(self.doc.page_name)
def update_page_name(self):
"""set page_name and check if it is unique"""
self.doc.page_name = website.utils.page_name(self.doc.title)
res = webnotes.conn.sql("""\
select count(*) from `tab%s`
where page_name=%s and name!=%s""" % (self.doctype, '%s', '%s'),
(self.doc.page_name, self.doc.name))
if res and res[0][0] > 0:
webnotes.msgprint("""A %s with the same title already exists.
Please change the title of %s and save again."""
% (self.doctype, self.doc.name), raise_exception=1)
def clear_web_cache(self):
"""
if web cache entry doesn't exist, it creates one
if duplicate entry exists for another doctype, it raises exception
"""
# delete web cache entry of old name
if hasattr(self, 'old_page_name') and self.old_page_name and \
self.old_page_name != self.doc.page_name:
self.delete_web_cache(self.old_page_name)
website.web_cache.create_cache(self.doc.page_name, self.doc.doctype, self.doc.name)
website.web_cache.clear_cache(self.doc.page_name, self.doc.doctype, self.doc.name)
def delete_web_cache(self, page_name):
"""delete entry of page name from Web Cache"""
website.web_cache.delete_cache(page_name)
def markdown_to_html(self, fields_list):
"""convert fields from markdown to html"""
import markdown2
for f in fields_list:
field_name = "%s_html" % f
self.doc.fields[field_name] = markdown2.markdown(self.doc.fields.get(f) or '', \
extras=["wiki-tables"])