Merge branch 'master' of github.com:webnotes/erpnext into cms2
diff --git a/erpnext/patches/june_2012/cms2.py b/erpnext/patches/june_2012/cms2.py
new file mode 100644
index 0000000..48f0152
--- /dev/null
+++ b/erpnext/patches/june_2012/cms2.py
@@ -0,0 +1,46 @@
+def execute():
+ import webnotes
+ import webnotes.model.sync
+
+ # sync web page, blog doctype
+ webnotes.model.sync.sync('website', 'web_page')
+ webnotes.model.sync.sync('website', 'blog')
+
+ cleanup()
+
+ save_pages()
+
+def cleanup():
+ import webnotes
+
+ # delete pages from `tabPage` of module Website or of type Webpage
+ webnotes.conn.sql("""\
+ delete from `tabPage`
+ where module='Website' and ifnull(web_page, 'No') = 'Yes'""")
+
+def save_pages():
+ """save all web pages, blogs to create content"""
+ import webnotes
+ from webnotes.model.doclist import DocList
+ save_list = [
+ {
+ 'doctype': 'Web Page',
+ 'query': """select name from `tabWeb Page` where docstatus=0"""
+ },
+ {
+ 'doctype': 'Blog',
+ 'query': """\
+ select name from `tabBlog`
+ where docstatus = 0 and ifnull(published, 0) = 1"""
+ },
+ {
+ 'doctype': 'Item',
+ 'query': """\
+ select name from `tabItem`
+ where docstatus = 0 and ifnull(show_in_website, 'No') = 'Yes'"""
+ }
+ ]
+
+ for s in save_list:
+ for p in webnotes.conn.sql(s['query'], as_dict=1):
+ DocList(s['doctype'], p['name']).save()
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index f0fb5e7..85af0bb 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -46,6 +46,8 @@
return ret
def on_update(self):
+ self.update_page_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):
msgprint("Please Update Stock UOM with the help of Stock UOM Replace Utility.")
@@ -79,9 +81,14 @@
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))
+
+ import website.web_cache
+ website.web_cache.delete_web_cache(self.doc.page_name)
# Check whether Ref Rate is not entered twice for same Price List and Currency
def check_ref_rate_detail(self):
@@ -163,9 +170,9 @@
if self.doc.has_serial_no == 'Yes' and self.doc.is_stock_item == 'No':
msgprint("'Has Serial No' can not be 'Yes' for non-stock item", raise_exception=1)
- # make product page
- self.make_page()
-
+ if self.doc.name:
+ self.old_page_name = webnotes.conn.get_value('Item', self.doc.name, 'page_name')
+
def check_non_asset_warehouse(self):
if self.doc.is_asset_item == "Yes":
existing_qty = sql("select t1.warehouse, t1.actual_qty from tabBin t1, tabWarehouse t2 where t1.item_code=%s and (t2.warehouse_type!='Fixed Asset' or t2.warehouse_type is null) and t1.warehouse=t2.name and t1.actual_qty > 0", self.doc.name)
@@ -218,35 +225,59 @@
def on_rename(self,newdn,olddn):
sql("update tabItem set item_code = %s where name = %s", (newdn, olddn))
- def make_page(self):
- if self.doc.show_in_website=='Yes':
-
- import website.utils
-
- if self.doc.page_name:
- import webnotes.model
- webnotes.model.delete_doc('Page', self.doc.page_name)
-
- p = website.utils.add_page("Product " + self.doc.item_name)
- self.doc.page_name = p.name
-
- from jinja2 import Template
- import markdown2
- import os
-
-
- self.doc.long_description_html = markdown2.markdown(self.doc.description or '')
-
- with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
- p.content = Template(f.read()).render(doc=self.doc)
-
- with open(os.path.join(os.path.dirname(__file__), 'product_page.js'), 'r') as f:
- p.script = Template(f.read()).render(doc=self.doc)
-
- p.save()
-
- website.utils.add_guest_access_to_page(p.name)
-
- del self.doc.fields['long_description_html']
-
-
\ No newline at end of file
+ # def make_page(self):
+ # if self.doc.show_in_website=='Yes':
+ #
+ # import website.utils
+ #
+ # if self.doc.page_name:
+ # import webnotes.model
+ # webnotes.model.delete_doc('Page', self.doc.page_name)
+ #
+ # p = website.utils.add_page("Product " + self.doc.item_name)
+ # self.doc.page_name = p.name
+ #
+ # from jinja2 import Template
+ # import markdown2
+ # import os
+ #
+ #
+ # self.doc.long_description_html = markdown2.markdown(self.doc.description or '')
+ #
+ # with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
+ # p.content = Template(f.read()).render(doc=self.doc)
+ #
+ # with open(os.path.join(os.path.dirname(__file__), 'product_page.js'), 'r') as f:
+ # p.script = Template(f.read()).render(doc=self.doc)
+ #
+ # p.save()
+ #
+ # website.utils.add_guest_access_to_page(p.name)
+ #
+ # del self.doc.fields['long_description_html']
+ #
+ def clear_web_cache(self):
+ import website.web_cache
+
+ if hasattr(self, 'old_page_name') and self.old_page_name and \
+ self.doc.page_name != self.old_page_name:
+ website.web_cache.delete_web_cache(self.old_page_name)
+
+ if self.doc.show_in_website == 'Yes':
+ website.web_cache.clear_web_cache(self.doc.doctype, self.doc.name, self.doc.page_name)
+ else:
+ website.web_cache.delete_web_cache(self.doc.page_name)
+
+ def update_page_name(self):
+ import website.utils
+ self.doc.page_name = website.utils.page_name(self.doc.name + " " + self.doc.item_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 get_html(self):
+ import markdown2
+ self.doc.web_description_html = markdown2.markdown(self.doc.description or '',
+ extras=["wiki-tables"])
+
+
\ No newline at end of file
diff --git a/erpnext/website/doctype/blog/blog.py b/erpnext/website/doctype/blog/blog.py
index 919b830..0e8acac 100644
--- a/erpnext/website/doctype/blog/blog.py
+++ b/erpnext/website/doctype/blog/blog.py
@@ -22,52 +22,26 @@
import webnotes
import website.utils
+import website.web_page
-class DocType():
+class DocType(website.web_page.Page):
def __init__(self, d, dl):
+ super(DocType, self).__init__('Blog')
self.doc, self.doclist = d, dl
+
+ 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)
+
+ def get_html(self):
+ # this is for double precaution. usually it wont reach this code if not published
+ if not webnotes.utils.cint(self.doc.published):
+ raise Exception, "This blog has not been published yet!"
- def autoname(self):
- """save file by its name"""
- self.doc.name = website.utils.page_name(self.doc.title)
-
- def validate(self):
- """write/update 'Page' with the blog"""
- # we need the name for the templates
- if not self.doc.name:
- self.autoname()
-
- if self.doc.page_name:
- webnotes.conn.sql("""delete from tabPage where name=%s""", self.doc.page_name)
-
- p = website.utils.add_page(self.doc.title)
-
- from jinja2 import Template
- import markdown2
- import os
+ # temp fields
from webnotes.utils import global_date_format, get_fullname
- from webnotes.model.code import get_obj
-
- self.doc.content_html = unicode(markdown2.markdown(self.doc.content or ''))
self.doc.full_name = get_fullname(self.doc.owner)
self.doc.updated = global_date_format(self.doc.modified)
-
- with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
- p.content = Template(f.read()).render(doc=self.doc)
-
- with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'), 'r') as f:
- p.script = Template(f.read()).render(doc=self.doc)
-
- p.web_page = 'Yes'
- p.save()
- get_obj(doc=p).write_cms_page()
-
- website.utils.add_guest_access_to_page(p.name)
- self.doc.page_name = p.name
-
- # cleanup
- for f in ['full_name', 'updated', 'content_html']:
- if f in self.doc.fields:
- del self.doc.fields[f]
-
\ No newline at end of file
+ self.markdown_to_html(['content'])
\ No newline at end of file
diff --git a/erpnext/website/doctype/blog/blog.txt b/erpnext/website/doctype/blog/blog.txt
index ad44d13..24187e3 100644
--- a/erpnext/website/doctype/blog/blog.txt
+++ b/erpnext/website/doctype/blog/blog.txt
@@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
- 'creation': '2012-04-02 16:02:43',
+ 'creation': '2012-05-28 19:22:38',
'docstatus': 0,
- 'modified': '2012-04-26 16:58:27',
+ 'modified': '2012-06-22 18:56:16',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@@ -21,7 +21,7 @@
'name': '__common__',
'section_style': u'Simple',
'show_in_menu': 0,
- 'version': 5
+ 'version': 1
},
# These values are common for all DocField
@@ -51,6 +51,7 @@
# DocPerm
{
+ 'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
@@ -71,7 +72,14 @@
{
'doctype': u'DocPerm',
'permlevel': 1,
- 'role': u'All'
+ 'role': u'Website Manager'
+ },
+
+ # DocPerm
+ {
+ 'doctype': u'DocPerm',
+ 'permlevel': 1,
+ 'role': u'Blogger'
},
# DocField
@@ -99,6 +107,7 @@
'fieldname': u'content',
'fieldtype': u'Code',
'label': u'Content',
+ 'options': u'Markdown',
'permlevel': 0,
'reqd': 0
},
@@ -106,19 +115,11 @@
# DocField
{
'doctype': u'DocField',
- 'fieldname': u'content_html',
- 'fieldtype': u'Text',
- 'label': u'Content HTML',
- 'permlevel': 1
- },
-
- # DocField
- {
- 'doctype': u'DocField',
'fieldname': u'page_name',
'fieldtype': u'Data',
+ 'hidden': 1,
'label': u'Page Name',
- 'permlevel': 0
+ 'permlevel': 1
},
# DocField
diff --git a/erpnext/website/doctype/blog/template.html b/erpnext/website/doctype/blog/template.html
deleted file mode 100644
index 510f1be..0000000
--- a/erpnext/website/doctype/blog/template.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<div class="layout-wrapper layout-wrapper-background">
- <div class="web-content" id="blog-{{ doc.name }}">
- <div class="layout-main-section">
- <h2>{{ doc.title }}</h2>
- <div class="help">By {{ doc.full_name }} on {{ doc.updated }}</div>
- <br>
- {{ doc.content_html }}
- <hr><h3>Comments</h3>
- <br>
- <div class="blog-comments"></div>
- </div>
- <div class="layout-side-section">
- <p><a href="blog.html">All Blogs</a></p>
- <h4>Recent Posts</h4>
- <div class="recent-posts" style="min-height: 100px;"></div>
- <h4>Subscribe</h4>
- <p>
- <img src="images/feed.png" style="margin-right: 4px; margin-bottom: -4px">
- <a href="rss.xml" target="_blank">RSS Feed</a>
- </p>
- </div>
- <div style="clear: both"></div>
- </div>
-</div>
\ No newline at end of file
diff --git a/erpnext/website/doctype/web_cache/__init__.py b/erpnext/website/doctype/web_cache/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/website/doctype/web_cache/__init__.py
diff --git a/erpnext/website/doctype/web_cache/web_cache.txt b/erpnext/website/doctype/web_cache/web_cache.txt
new file mode 100644
index 0000000..98a4891
--- /dev/null
+++ b/erpnext/website/doctype/web_cache/web_cache.txt
@@ -0,0 +1,99 @@
+# DocType, Web Cache
+[
+
+ # These values are common in all dictionaries
+ {
+ 'creation': '2012-06-21 12:01:17',
+ 'docstatus': 0,
+ 'modified': '2012-06-21 17:25:52',
+ 'modified_by': u'Administrator',
+ 'owner': u'Administrator'
+ },
+
+ # These values are common for all DocType
+ {
+ 'doctype': 'DocType',
+ 'document_type': u'System',
+ 'module': u'Website',
+ 'name': '__common__',
+ 'version': 1
+ },
+
+ # These values are common for all DocField
+ {
+ 'doctype': u'DocField',
+ 'name': '__common__',
+ 'parent': u'Web Cache',
+ 'parentfield': u'fields',
+ 'parenttype': u'DocType',
+ 'permlevel': 0
+ },
+
+ # These values are common for all DocPerm
+ {
+ 'doctype': u'DocPerm',
+ 'name': '__common__',
+ 'parent': u'Web Cache',
+ 'parentfield': u'permissions',
+ 'parenttype': u'DocType',
+ 'permlevel': 0,
+ 'read': 1,
+ 'write': 1
+ },
+
+ # DocType, Web Cache
+ {
+ 'doctype': 'DocType',
+ 'name': u'Web Cache'
+ },
+
+ # DocPerm
+ {
+ 'create': 0,
+ 'doctype': u'DocPerm',
+ 'role': u'All'
+ },
+
+ # DocPerm
+ {
+ 'create': 1,
+ 'doctype': u'DocPerm',
+ 'role': u'Website Manager'
+ },
+
+ # DocPerm
+ {
+ 'create': 1,
+ 'doctype': u'DocPerm',
+ 'role': u'Blogger'
+ },
+
+ # DocField
+ {
+ 'doctype': u'DocField',
+ 'fieldname': u'doc_type',
+ 'fieldtype': u'Link',
+ 'in_filter': 1,
+ 'label': u'DocType',
+ 'options': u'DocType',
+ 'reqd': 1
+ },
+
+ # DocField
+ {
+ 'doctype': u'DocField',
+ 'fieldname': u'doc_name',
+ 'fieldtype': u'Data',
+ 'in_filter': 0,
+ 'label': u'DocName',
+ 'reqd': 1
+ },
+
+ # DocField
+ {
+ 'doctype': u'DocField',
+ 'fieldname': u'html',
+ 'fieldtype': u'Long Text',
+ 'label': u'HTML'
+ }
+]
\ No newline at end of file
diff --git a/erpnext/website/doctype/web_page/template.html b/erpnext/website/doctype/web_page/template.html
deleted file mode 100644
index c6d4b40..0000000
--- a/erpnext/website/doctype/web_page/template.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<div class="layout-wrapper layout-wrapper-background">
- <div class="web-content"
- style="text-align: {{ doc.text_align }};">
-
- {% if doc.layout and doc.layout.startswith('Two column') %}
- <div class="layout-main-section">
- {% else %}
- <div class="layout-main">
- {% endif %}
- {{ doc.main_section_html }}
- {% if doc.next_page_html %}
- {{ doc.next_page_html }}
- {% endif %}
-
- </div>
-
- {% if doc.layout and doc.layout.startswith('Two column') %}
- <div class="layout-side-section">
- {{ doc.side_section_html }}
- {% if doc.see_also %}
- <div class="info-box">
- <h4>See Also</h4>
- {{ doc.see_also }}
- </div>
- {% endif %}
- </div>
- {% endif %}
- <div style="clear: both"></div>
- </div>
-</div>
diff --git a/erpnext/website/doctype/web_page/web_page.py b/erpnext/website/doctype/web_page/web_page.py
index 27ce5c0..37e0cee 100644
--- a/erpnext/website/doctype/web_page/web_page.py
+++ b/erpnext/website/doctype/web_page/web_page.py
@@ -16,82 +16,22 @@
import webnotes
import website.utils
+import website.web_page
-class DocType:
+class DocType(website.web_page.Page):
def __init__(self, d, dl):
+ super(DocType, self).__init__('Web Page')
self.doc, self.doclist = d, dl
-
- def autoname(self):
- """name from title"""
- self.doc.name = website.utils.page_name(self.doc.title)
def on_update(self):
- """make page for this product"""
- from jinja2 import Template
- from webnotes.utils import global_date_format
- from webnotes.model.code import get_obj
- import os
-
- # we need the name for the templates
- if self.doc.name.startswith('New Web Page'):
- self.autoname()
-
- if self.doc.page_name:
- webnotes.conn.sql("""delete from tabPage where name=%s""", self.doc.page_name)
-
- p = website.utils.add_page(self.doc.name)
- self.doc.page_name = p.name
-
- self.doc.updated = global_date_format(self.doc.modified)
- website.utils.markdown(self.doc, ['head_section','main_section', 'side_section'])
-
- with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
- p.content = Template(f.read()).render(doc=self.doc)
-
- p.title = self.doc.title
- p.web_page = 'Yes'
-
- if self.doc.insert_code:
- p.script = self.doc.javascript
-
- if self.doc.insert_style:
- p.style = self.doc.css
-
- p.save()
- get_obj(doc=p).write_cms_page()
-
- website.utils.add_guest_access_to_page(p.name)
- self.cleanup_temp()
-
- self.doc.save()
-
+ super(DocType, self).on_update()
self.if_home_clear_cache()
-
- def add_page_links(self):
- """add links for next_page and see_also"""
- if self.doc.next_page:
- self.doc.next_page_html = """<div class="info-box round" style="text-align: right">
- <b>Next:</b>
- <a href="#!%(name)s">%(title)s</a></div>""" % {"name":self.doc.next_page, \
- "title": webnotes.conn.get_value("Page", self.doc.next_page, "title")}
- self.doc.see_also = ''
- for d in self.doclist:
- if d.doctype=='Related Page':
- tmp = {"page":d.page, "title":webnotes.conn.get_value('Page', d.page, 'title')}
- self.doc.see_also += """<div><a href="#!%(page)s">%(title)s</a></div>""" % tmp
-
- def cleanup_temp(self):
- """cleanup temp fields"""
- fl = ['main_section_html', 'side_section_html', 'see_also', \
- 'next_page_html', 'head_section_html', 'updated']
- for f in fl:
- if f in self.doc.fields:
- del self.doc.fields[f]
-
def if_home_clear_cache(self):
"""if home page, clear cache"""
if webnotes.conn.get_value("Website Settings", None, "home_page")==self.doc.name:
from webnotes.session_cache import clear_cache
- clear_cache('Guest')
-
\ No newline at end of file
+ clear_cache('Guest')
+
+ def get_html(self):
+ self.markdown_to_html(['head_section','main_section', 'side_section'])
\ No newline at end of file
diff --git a/erpnext/website/doctype/web_page/web_page.txt b/erpnext/website/doctype/web_page/web_page.txt
index c40caff..a1fd894 100644
--- a/erpnext/website/doctype/web_page/web_page.txt
+++ b/erpnext/website/doctype/web_page/web_page.txt
@@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
- 'creation': '2012-04-02 16:02:43',
+ 'creation': '2012-06-19 15:02:20',
'docstatus': 0,
- 'modified': '2012-05-02 15:24:31',
+ 'modified': '2012-06-22 18:49:02',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@@ -36,13 +36,15 @@
# 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'
+ 'role': u'Website Manager',
+ 'submit': 0
},
# DocType, Web Page
@@ -53,6 +55,7 @@
# DocPerm
{
+ 'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
@@ -61,8 +64,11 @@
# DocPerm
{
+ 'cancel': 0,
+ 'create': 0,
'doctype': u'DocPerm',
- 'permlevel': 1
+ 'permlevel': 1,
+ 'write': 0
},
# DocField
@@ -88,6 +94,17 @@
# 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',
@@ -101,7 +118,7 @@
'fieldname': u'layout',
'fieldtype': u'Select',
'label': u'Layout',
- 'options': u'Two column with header\nTwo column\nSingle column',
+ 'options': u'Single column\nTwo column\nTwo column with header',
'permlevel': 0
},
@@ -176,6 +193,7 @@
# DocField
{
'colour': u'White:FFF',
+ 'description': u'Add code as <script>',
'doctype': u'DocField',
'fieldname': u'insert_code',
'fieldtype': u'Check',
@@ -215,15 +233,6 @@
# DocField
{
'doctype': u'DocField',
- 'fieldname': u'page_name',
- 'fieldtype': u'Data',
- 'label': u'Page Name',
- 'permlevel': 1
- },
-
- # DocField
- {
- 'doctype': u'DocField',
'fieldname': u'file_list',
'fieldtype': u'Text',
'hidden': 1,
diff --git a/erpnext/website/doctype/website_settings/website_settings.py b/erpnext/website/doctype/website_settings/website_settings.py
index 9390e74..aec5a39 100644
--- a/erpnext/website/doctype/website_settings/website_settings.py
+++ b/erpnext/website/doctype/website_settings/website_settings.py
@@ -54,8 +54,13 @@
from webnotes.cms.make import make_web_core
make_web_core()
- get_obj('Page', 'blog').write_cms_page(force=True)
- get_obj('Page', 'Login Page').write_cms_page(force=True)
+ import website.web_cache
+ for page in ['blog', 'products']:
+ website.web_cache.delete_web_cache(page)
+ website.web_cache.clear_web_cache(None, None, page)
+
+ #get_obj('Page', 'blog').write_cms_page(force=True)
+ #get_obj('Page', 'Login Page').write_cms_page(force=True)
webnotes.msgprint('Rebuilt all blogs and pages')
diff --git a/erpnext/website/js/product_category.js b/erpnext/website/js/product_category.js
index 8d3f898..bed4d24 100644
--- a/erpnext/website/js/product_category.js
+++ b/erpnext/website/js/product_category.js
@@ -18,7 +18,10 @@
wrapper.category_list = new wn.ui.Listing({
parent: $(wrapper).find('.more-categories').get(0),
query: 'select count(name) as items, item_group \
- from tabItem where is_sales_item="Yes" \
+ from tabItem \
+ where is_sales_item="Yes" and \
+ ifnull(show_in_website, "No")="Yes" and \
+ docstatus = 0 \
group by item_group order by items desc',
hide_refresh: true,
render_row: function(parent, data) {
@@ -26,5 +29,6 @@
data);
}
});
- wrapper.category_list.run();
+ wrapper.category_list.run();
+ console.log('product categories made');
}
diff --git a/erpnext/website/templates/404.html b/erpnext/website/templates/404.html
new file mode 100644
index 0000000..8a30892
--- /dev/null
+++ b/erpnext/website/templates/404.html
@@ -0,0 +1,12 @@
+{% extends "outer.html" %}
+
+{% block content %}
+<div class="content">
+ <div class="layout-wrapper layout-main">
+ <h3>Page missing or moved</h3>
+ <br>
+ <p>We are very sorry for this, but the page you are looking for is missing
+ (this could be because of a typo in the address) or moved.</p>
+ </div>
+</div>
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/__init__.py b/erpnext/website/templates/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/website/templates/__init__.py
diff --git a/erpnext/website/templates/base.html b/erpnext/website/templates/base.html
new file mode 100644
index 0000000..cd64139
--- /dev/null
+++ b/erpnext/website/templates/base.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<head>
+ <meta charset="utf-8">
+ <title>{% block title %}{% endblock %}</title>
+ <meta name="generator" content="wnframework">
+ <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
+ <link rel="icon" href="images/favicon.ico" type="image/x-icon">
+ <script type="text/javascript" src="js/lib/jquery/jquery.min.js"></script>
+ <script type="text/javascript" src="js/all-web.js"></script>
+ <script type="text/javascript" src="js/wn-web.js"></script>
+ <link type="text/css" rel="stylesheet" href="css/all-web.css">
+ <link type="text/css" rel="stylesheet" href="css/wn-web.css">
+
+ {% block header %}
+ {% endblock %}
+</head>
+<body>
+ {% block body %}
+ {% endblock %}
+</body>
\ No newline at end of file
diff --git a/erpnext/website/templates/blog/blog.html b/erpnext/website/templates/blog/blog.html
new file mode 100644
index 0000000..03a2ed7
--- /dev/null
+++ b/erpnext/website/templates/blog/blog.html
@@ -0,0 +1,31 @@
+{% extends "blog/blog.js" %}
+
+{% block content %}
+ <div class="layout-wrapper layout-wrapper-background">
+ <div class="web-content" id="blog-{{ name }}">
+
+ <div class="layout-main-section">
+ <h2>{{ title }}</h2>
+ <div class="help">By {{ full_name }} on {{ updated }}</div>
+ <br>
+ {{ content_html }}
+ <hr><h3>Comments</h3>
+ <br>
+ <div class="blog-comments"></div>
+ </div>
+
+ <div class="layout-side-section">
+ <p><a href="blog.html">All Blogs</a></p>
+ <h4>Recent Posts</h4>
+ <div class="recent-posts" style="min-height: 100px;"></div>
+ <h4>Subscribe</h4>
+ <p>
+ <img src="images/feed.png" style="margin-right: 4px; margin-bottom: -4px">
+ <a href="rss.xml" target="_blank">RSS Feed</a>
+ </p>
+ </div>
+
+ <div style="clear: both"></div>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/doctype/blog/blog_page.js b/erpnext/website/templates/blog/blog.js
similarity index 89%
rename from erpnext/website/doctype/blog/blog_page.js
rename to erpnext/website/templates/blog/blog.js
index 4b28392..80cb813 100644
--- a/erpnext/website/doctype/blog/blog_page.js
+++ b/erpnext/website/templates/blog/blog.js
@@ -1,3 +1,6 @@
+{% extends "page.html" %}
+
+{% block javascript %}
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
@@ -15,14 +18,13 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// js inside blog page
-
-pscript['onload_{{ doc.name }}'] = function(wrapper) {
+wn.pages['{{ name }}'].onload = function(wrapper) {
// sidebar
wrapper.recent_list = new wn.ui.Listing({
parent: $(wrapper).find('.recent-posts'),
no_toolbar: true,
query: 'select name, title, left(content, 100) as content from tabBlog\
- where ifnull(published,0)=1 and name!="{{ doc.name }}" order by creation desc',
+ where ifnull(published,0)=1 and name!="{{ name }}" order by creation desc',
hide_refresh: true,
render_row: function(parent, data) {
//console.log(data);
@@ -33,13 +35,13 @@
page_length: 5,
});
wrapper.recent_list.run();
-
+
wrapper.comment_list = new wn.ui.Listing({
parent: $(wrapper).find('.blog-comments').get(0),
no_toolbar: true,
query: 'select comment, comment_by_fullname, creation\
from `tabComment` where comment_doctype="Page"\
- and comment_docname="{{ doc.name }}" order by creation desc',
+ and comment_docname="{{ name }}" order by creation desc',
no_result_message: 'Be the first one to comment',
render_row: function(parent, data) {
data.comment_date = prettyDate(data.creation);
@@ -48,10 +50,10 @@
</div>\
<p style='margin-left: 20px;'>%(comment)s</p><br>", data))
},
- hide_refresh: true
+ hide_refresh: true,
});
wrapper.comment_list.run();
-
+
// add comment
$(wrapper).find('.layout-main-section').append('<br><button class="btn add-comment">\
Add Comment</button>');
@@ -70,7 +72,7 @@
var args = d.get_values();
if(!args) return;
args.comment_doctype = 'Page';
- args.comment_docname = '{{ doc.name }}';
+ args.comment_docname = '{{ name }}';
$(btn).set_working();
$c('webnotes.widgets.form.comments.add_comment', args, function(r) {
$(btn).done_working();
@@ -80,4 +82,6 @@
}
d.show();
})
-}
\ No newline at end of file
+}
+
+{% endblock %}
diff --git a/erpnext/website/templates/blog/blog_list.html b/erpnext/website/templates/blog/blog_list.html
new file mode 100644
index 0000000..242f814
--- /dev/null
+++ b/erpnext/website/templates/blog/blog_list.html
@@ -0,0 +1,43 @@
+{% extends "blog/blog_list.js" %}
+
+{% block title %}Blog{% endblock %}
+
+{% block css %}
+ <style>
+ h2 > a, h2 > a:link, h2 > a:visited, h2 > a:active,
+ h2 > a:hover, h2 > a:focus {
+ text-decoration: none;
+ color: inherit;
+ }
+ </style>
+{% endblock %}
+
+{% block content %}
+ <div class="layout-wrapper layout-wrapper-background">
+ <div class="web-content" id="content-blog">
+
+ <div class="layout-main-section">
+ <h1>Blog</h1>
+ <br>
+ <div id="blog-list">
+ <!-- blog list will be generated dynamically -->
+ </div>
+ </div>
+
+ <div class="layout-side-section">
+ <!-- for later
+ <h4>Get Updates</h4>
+ <p>
+ <input name="blog-subscribe">
+ <button class="btn" id="blog-subscribe">Subscribe</button>
+ </p>-->
+ <h4>Subscribe</h4>
+ <p>
+ <img src="images/feed.png" style="margin-right: 4px; margin-bottom: -4px">
+ <a href="rss.xml" target="_blank">RSS Feed</a>
+ </p>
+ </div>
+ <div style="clear: both"></div>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/blog/blog_list.js b/erpnext/website/templates/blog/blog_list.js
new file mode 100644
index 0000000..70628c1
--- /dev/null
+++ b/erpnext/website/templates/blog/blog_list.js
@@ -0,0 +1,48 @@
+{% extends "page.html" %}
+
+{% block javascript %}
+// 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/>.
+
+// js inside blog page
+wn.pages['{{ name }}'].onload = function(wrapper) {
+ erpnext.blog_list = new wn.ui.Listing({
+ parent: $(wrapper).find('#blog-list').get(0),
+ query: 'select tabBlog.name, title, left(content, 1000) as content, tabBlog.creation, \
+ ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \
+ from tabProfile, tabBlog\
+ where ifnull(published,0)=1 and tabBlog.owner = tabProfile.name \
+ order by tabBlog.creation desc',
+ hide_refresh: true,
+ no_toolbar: true,
+ render_row: function(parent, data) {
+ if(data.content && data.content.length==1000) {
+ data.content += repl('... <a href="%(name)s.html">(read on)</a>', data);
+ }
+ data.content = wn.markdown(data.content);
+ if(data.last_name) data.last_name = ' ' + data.last_name;
+ data.date = prettyDate(data.creation);
+ parent.innerHTML = repl('<h2><a href="%(name)s.html">%(title)s</a></h2>\
+ <p><div class="help">By %(first_name)s%(last_name)s, %(date)s</div></p>\
+ <p>%(content)s</p><br>', data)
+ //<a href="%(name)s.html">Read Full Text</a><br>', data);
+ },
+ page_length: 10
+ });
+ erpnext.blog_list.run();
+}
+
+{% endblock %}
diff --git a/erpnext/website/templates/outer.html b/erpnext/website/templates/outer.html
new file mode 100644
index 0000000..4b8c04d
--- /dev/null
+++ b/erpnext/website/templates/outer.html
@@ -0,0 +1,57 @@
+{#
+ requires, brand, top_bar_items, footer_items, copyright, content
+#}
+
+{% extends "base.html" %}
+
+{% block body %}
+
+ <header>
+ <div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="index.html">{{ brand }}</a>
+ <ul class="nav">
+ {% for page in top_bar_items %}
+ {% if not page.parent_label %}
+ <li data-label="{{ page.label }}">
+ <a href="{{ page.url }}" {{ page.target }}>
+ {{ page.label }}
+ {% if page.child_items %}
+ <ul class="dropdown-menu">
+ {% for child in page.child_items %}
+ <li data-label="{{ child.label }}">
+ <a href="{{ child.url }}" {{ child.target }}>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ </a></li>
+ {% endif %}
+ {% endfor %}
+ </ul>
+ <img src="images/lib/ui/spinner.gif" id="spinner"/>
+ <ul class="nav pull-right">
+ <li id="login-topbar-item"><a href="login-page.html">Login</a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ </header>
+ <div id="body_div">
+ <div class="content" id="page-{{ name }}" style="display: block;">
+ {% block content %}
+ {% endblock %}
+ </div>
+ </div>
+ <footer><div class="web-footer">
+ <div class="web-footer-menu"><ul>
+ {% for item in footer_items %}
+ <li><a href="{{ item.url }}" {{ item.target }}
+ data-label="{{ item.label }}">{{ item.label }}</a></li>
+ {% endfor %}
+ </ul></div>
+ <div class="web-footer-copyright">© {{ copyright }}
+ </div>
+ </footer>
+
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/page.html b/erpnext/website/templates/page.html
new file mode 100644
index 0000000..c6e0715
--- /dev/null
+++ b/erpnext/website/templates/page.html
@@ -0,0 +1,39 @@
+{% extends "outer.html" %}
+
+{% block title %}{{ title }}{% endblock %}
+
+{% block header %}
+ {{ super() }}
+ {% if insert_code %}
+ <script>
+ window.page_name = "{{ name }}";
+
+ $(document).bind('app_ready', function() {
+ var _page = new wn.views.Page(window.page_name);
+
+ // page script
+ {% block javascript %}
+ {{ javascript }}
+ {% endblock %}
+
+ // trigger onload
+ _page.trigger('onload');
+
+ // activate page
+ wn.container.change_to(window.page_name);
+ });
+ </script>
+ {% endif %}
+
+ {% block css %}
+ {% if insert_style %}
+
+ <style>{{ css }}</style>
+
+ {% endif %}
+ {% endblock %}
+{% endblock %}
+
+{% block content %}
+ {{ content }}
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/product/product.html b/erpnext/website/templates/product/product.html
new file mode 100644
index 0000000..5d3c3da
--- /dev/null
+++ b/erpnext/website/templates/product/product.html
@@ -0,0 +1,33 @@
+{% extends "product/product.js" %}
+
+{% block title %}{{ item_name }} [{{ name }}]{% endblock %}
+
+{% block content %}
+ <div class="layout-wrapper layout-wrapper-background">
+ <div class="web-content" id="content-product-{{ name }}">
+ <div class="layout-main-section">
+ <h1>{{ item_name }}</h1>
+ <div style="float: left;">
+ <br><br>
+ {% if website_image %}
+ <image src="files/{{ website_image }}" style="width: 300px;
+ margin-left: 15px;" />
+ <br><br>
+ {% endif %}
+ {{ web_description_html }}
+ <button class="btn primary product-inquiry"
+ data-product="{{ name }}"
+ data-description="{{ description }}">Send Inquiry</button>
+ </div>
+ </div>
+ <div class="layout-side-section">
+ <h4>More Categories</h4>
+ <div class="more-categories"></div>
+ <br>
+ <h4>Similar Products</h4>
+ <div class="similar-products"></div>
+ </div>
+ <div style="clear: both"></div>
+ </div>
+ </div>
+{% endblock %}
diff --git a/erpnext/website/templates/product/product.js b/erpnext/website/templates/product/product.js
new file mode 100644
index 0000000..3475204
--- /dev/null
+++ b/erpnext/website/templates/product/product.js
@@ -0,0 +1,78 @@
+{% extends "product/product_category.js" %}
+
+{% block javascript %}
+{{ super() }}
+// 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/>.
+wn.provide('erpnext.products');
+wn.pages['{{ name }}'].onload = function(wrapper) {
+ wrapper.product_group = "{{ item_group }}";
+ wrapper.product_name = "{{ name }}";
+ erpnext.products.make_product_categories(wrapper);
+
+ // TODO make this working
+ $(wrapper).find('.product-inquiry').click(function() {
+ loadpage('contact', function() {
+ $('#content-contact-us [name="contact-message"]').val("Hello,\n\n\
+ Please send me more information on {{ item_name }} (Item Code:{{ name }})\n\n\
+ My contact details are:\n\nThank you!\
+ ");
+ })
+ });
+
+ // similar products
+ wrapper.similar = new wn.ui.Listing({
+ parent: $(wrapper).find('.similar-products').get(0),
+ hide_refresh: true,
+ page_length: 5,
+ get_query: function() {
+ args = {
+ cat: wrapper.product_group,
+ name: wrapper.product_name
+ };
+ var query = repl('select name, item_name, website_image, \
+ page_name, description \
+ from tabItem \
+ where is_sales_item="Yes" \
+ and ifnull(show_in_website, "No")="Yes" \
+ and name != "%(name)s" and docstatus = 0 \
+ and item_group="%(cat)s" order by modified desc', args)
+ return query
+ },
+ render_row: function(parent, data) {
+ if(data.description.length > 100) {
+ data.description = data.description.substr(0,100) + '...';
+ }
+ parent.innerHTML = repl('\
+ <div style="float:left; width: 60px; padding-bottom: 5px" class="img-area"></div>\
+ <div style="float:left; width: 180px">\
+ <b><a href="%(page_name)s.html">%(item_name)s</a></b>\
+ <p>%(description)s</p></div>\
+ <div style="clear: both; margin-bottom: 15px;"></div>', data);
+
+ if(data.website_image) {
+ $(parent).find('.img-area').append(repl(
+ '<img src="files/%(website_image)s" style="width:55px;">', data))
+ } else {
+ $(parent).find('.img-area').append(wn.dom.placeholder(50,
+ data.item_name));
+ }
+ }
+ });
+ wrapper.similar.run();
+}
+
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/product/product_category.js b/erpnext/website/templates/product/product_category.js
new file mode 100644
index 0000000..d8b09b3
--- /dev/null
+++ b/erpnext/website/templates/product/product_category.js
@@ -0,0 +1,27 @@
+{% extends "page.html" %}
+
+{% block javascript %}
+wn.provide('erpnext.products');
+erpnext.products.make_product_categories = function(wrapper) {
+ if (!wrapper) { wrapper = erpnext.products.wrapper; }
+ if (!wrapper) { return; }
+
+ wrapper.category_list = new wn.ui.Listing({
+ parent: $(wrapper).find('.more-categories').get(0),
+ query: 'select count(name) as items, item_group \
+ from tabItem \
+ where is_sales_item="Yes" and \
+ ifnull(show_in_website, "No")="Yes" and \
+ docstatus = 0 \
+ group by item_group order by items desc',
+ hide_refresh: true,
+ render_row: function(parent, data) {
+ parent.innerHTML = repl(
+ '<a href="products.html#!products/%(item_group)s">%(item_group)s</a> (%(items)s)',
+ data);
+ }
+ });
+ wrapper.category_list.run();
+}
+
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/product/product_list.html b/erpnext/website/templates/product/product_list.html
new file mode 100644
index 0000000..100bfca
--- /dev/null
+++ b/erpnext/website/templates/product/product_list.html
@@ -0,0 +1,38 @@
+{% extends "product/product_list.js" %}
+
+{% block title %}Products{% endblock %}
+
+{% block css %}
+ <style>
+ h3 > a, h3 > a:link, h3 > a:visited, h3 > a:active,
+ h3 > a:hover, h3 > a:focus {
+ text-decoration: none;
+ color: inherit;
+ }
+ </style>
+{% endblock %}
+
+
+{% block content %}
+ <div class="layout-wrapper layout-wrapper-background">
+ <div class="web-content" id="content-products">
+
+ <div class="layout-main-section">
+ <h1 class="products-category"></h1>
+ <div class="products-search" style="margin-bottom: 15px;">
+ <input name="products-search" />
+ <button class="btn" style="margin-left: 7px">Search</button>
+ </div>
+ <div id="products-list">
+ <!-- product list will be generated dynamically -->
+ </div>
+ </div>
+
+ <div class="layout-side-section">
+ <h3><a href="products.html">Categories</a></h3>
+ <div class="more-categories"></div>
+ </div>
+ <div style="clear: both"></div>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/templates/product/product_list.js b/erpnext/website/templates/product/product_list.js
new file mode 100644
index 0000000..5166fed
--- /dev/null
+++ b/erpnext/website/templates/product/product_list.js
@@ -0,0 +1,122 @@
+{% extends "product/product_category.js" %}
+
+{% block javascript %}
+{{ super() }}
+
+// 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/>.
+
+// js inside blog page
+wn.provide('erpnext.products');
+
+wn.pages['{{ name }}'].onload = function(wrapper) {
+ erpnext.products.wrapper = wrapper;
+
+ // make product categories in the sidebar
+ erpnext.products.make_product_categories(wrapper);
+
+ // make lists
+ erpnext.products.make_product_list(wrapper);
+
+ // erpnext.products.product_list.run();
+
+ // bind search button or enter key
+ $(wrapper).find('.products-search .btn').click(function() {
+ erpnext.products.product_list.run();
+ });
+
+ $(wrapper).find('.products-search input').keypress(function(ev) {
+ if(ev.which==13) $(wrapper).find('.products-search .btn').click();
+ });
+}
+
+erpnext.products.make_product_list = function(wrapper) {
+ if (!wrapper) { wrapper = erpnext.products.wrapper; }
+ if (!wrapper) { return; }
+
+ erpnext.products.product_list = new wn.ui.Listing({
+ parent: $(wrapper).find('#products-list').get(0),
+ run_btn: $(wrapper).find('.products-search .btn').get(0),
+ no_toolbar: true,
+ get_query: function() {
+ var srch = $('input[name="products-search"]').val()
+ var search_cond = 'and (description like "%%(srch)s%"\
+ or item_name like "%%(srch)s%")';
+ var product_group_cond = 'and item_group="%(group)s"';
+ var cur_group = erpnext.products.cur_group
+ args = {
+ search_cond: srch ? repl(search_cond, {srch:srch}) : '',
+ cat: cur_group ? repl(product_group_cond, {group: cur_group}) : '',
+ };
+ return repl('select name, item_name, website_image, \
+ description, page_name \
+ from tabItem \
+ where is_sales_item="Yes" \
+ %(cat)s \
+ and docstatus = 0 and ifnull(show_in_website, "No")="Yes"\
+ %(search_cond)s', args)
+ },
+ render_row: function(parent, data) {
+ parent.innerHTML = repl('\
+ <div style="float:left; width: 115px;" class="img-area"></div>\
+ <div style="float:left; width: 400px">\
+ <p><b><a href="%(page_name)s.html">%(item_name)s</a></b></p>\
+ <p>%(description)s</p></div>\
+ <div style="clear: both;"></div>', data);
+
+ if(data.website_image) {
+ $(parent).find('.img-area').append(repl(
+ '<img src="files/%(website_image)s" style="width:100px;">', data))
+ } else {
+ $(parent).find('.img-area').append(wn.dom.placeholder(100,
+ data.item_name));
+ }
+ }
+ });
+}
+
+wn.pages['{{ name }}'].onshow = function(wrapper) {
+ // show default product category
+ erpnext.products.set_group();
+}
+
+erpnext.products.set_group = function() {
+ var cat = erpnext.products.get_group();
+
+ // get erpnext.products.default_category
+ var wrapper = erpnext.products.wrapper;
+
+ $(wrapper).find('h1').html(cat.label);
+ erpnext.products.product_list.run();
+}
+
+erpnext.products.get_group = function() {
+ route = wn.get_route();
+ if(route && route.length>1) {
+ // from url
+ var grp = route[1];
+ var label = route[1];
+ erpnext.products.cur_group = grp;
+ } else {
+ // default
+ var grp = 'Products';
+ var label = 'Products';
+ erpnext.products.cur_group = null;
+ }
+ return {grp:grp, label:label};
+}
+
+{% endblock %}
diff --git a/erpnext/website/templates/web_page.html b/erpnext/website/templates/web_page.html
new file mode 100644
index 0000000..8188e71
--- /dev/null
+++ b/erpnext/website/templates/web_page.html
@@ -0,0 +1,23 @@
+{% extends "page.html" %}
+
+{% block content %}
+ <div class="layout-wrapper layout-wrapper-background">
+ <div class="web-content" style="text-align: {{ text_align }};">
+
+ {% if layout and layout.startswith('Two column') %}
+ <div class="layout-main-section">
+ {% else %}
+ <div class="layout-main">
+ {% endif %}
+ {{ main_section_html }}
+ </div>
+
+ {% if layout and layout.startswith('Two column') %}
+ <div class="layout-side-section">
+ {{ side_section_html }}
+ </div>
+ {% endif %}
+ <div style="clear: both"></div>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/utils.py b/erpnext/website/utils.py
index 57e940a..06bb60d 100644
--- a/erpnext/website/utils.py
+++ b/erpnext/website/utils.py
@@ -29,43 +29,12 @@
return temp.render(doc = doc.fields)
-def markdown(doc, fields):
- """convert fields to markdown"""
- import markdown2
- # markdown
- for f in fields:
- doc.fields[f + '_html'] = markdown2.markdown(doc.fields[f] or '', \
- extras=["wiki-tables"])
-
-
def page_name(title):
- """make page name from title, and check that there is no duplicate"""
- import webnotes.cms
- return webnotes.cms.page_name(title)
-
-def add_page(title):
- """add a custom page with title"""
- name = page_name(title)
- if webnotes.conn.sql("""select name from tabPage where name=%s""", name):
- p = Document('Page', name)
- else:
- p = Document('Page')
-
- p.title = title
- p.name = p.page_name = name
- p.module = 'Website'
- p.standard = 'No'
-
- return p
-
-def add_guest_access_to_page(page):
- """add Guest in Page Role"""
- if not webnotes.conn.sql("""select parent from `tabPage Role`
- where role='Guest' and parent=%s""", page):
- d = Document('Page Role')
- d.parent = page
- d.role = 'Guest'
- d.save()
+ """make page name from title"""
+ import re
+ name = title.lower()
+ name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
+ return '-'.join(name.split()[:4])
def get_header(page_name):
"""get page header"""
@@ -144,4 +113,4 @@
{% endfor %}
</ul></div>
<div class="web-footer-copyright">© {{ copyright }}
- </div>""").render(website_settings.fields)
+ </div>""").render(website_settings.fields)
\ No newline at end of file
diff --git a/erpnext/website/web_cache.py b/erpnext/website/web_cache.py
new file mode 100644
index 0000000..42bd1d1
--- /dev/null
+++ b/erpnext/website/web_cache.py
@@ -0,0 +1,171 @@
+# 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/>.
+
+# used by web.py
+def load_from_web_cache(page_name, comments, template): #, script=None):
+ """
+ * search for page in cache
+ * if html exists, return
+ * if not, build html, store it in cache, return
+ """
+ import webnotes
+ import conf
+
+ if page_name == 'index':
+ page_name = get_index_page()[0]
+
+ res = webnotes.conn.sql("""\
+ select html, doc_type, doc_name from `tabWeb Cache`
+ where name = %s""", page_name)
+
+ # if page doesn't exist, raise exception
+ if not res and page_name not in ['404', 'index', 'blog', 'products']:
+ raise Exception, "Page %s not found" % page_name
+
+ html, doc_type, doc_name = res and res[0] or (None, None, None)
+ auto_cache_clear = hasattr(conf, 'auto_cache_clear') and conf.auto_cache_clear or 0
+ if not html or auto_cache_clear:
+ comments += "\n\npage load status: fresh"
+ html = load_into_web_cache(page_name, template, doc_type, doc_name)
+ else:
+ comments += "\n\npage load status: cached"
+
+ from webnotes.utils import cstr
+ html += """\n<!-- %s -->""" % cstr(comments)
+
+ # show error in error console
+ # if script: html += """\n\n<script>\n%s\n</script>""" % cstr(script)
+ return html
+
+def load_into_web_cache(page_name, template, doc_type, doc_name):
+ """build html and store it in web cache"""
+ import webnotes
+ outer_env_dict = get_outer_env()
+
+ if page_name in ['404', 'blog', 'products']:
+ args = outer_env_dict
+ args.update({
+ 'name': page_name,
+ })
+ else:
+ if page_name == 'index':
+ page_name, doc_type, doc_name = get_index_page()
+
+ from webnotes.model.code import get_obj
+ obj = get_obj(doc_type, doc_name)
+ if hasattr(obj, 'get_html'):
+ obj.get_html()
+ args = obj.doc.fields
+ args.update(outer_env_dict)
+
+ # decide template and update args
+ if doc_type == 'Blog':
+ template = 'blog/blog.html'
+ args.update({ 'insert_code': 1 })
+ elif doc_type == 'Item':
+ template = 'product/product.html'
+ args.update({ 'insert_code': 1 })
+ elif doc_type == 'Web Page':
+ template = 'web_page.html'
+ elif page_name == 'blog':
+ template = 'blog/blog_list.html'
+ args.update({ 'insert_code': 1 })
+ elif page_name == 'products':
+ template = 'product/product_list.html'
+ args.update({ 'insert_code': 1 })
+
+ html = build_html(args, template)
+
+ # save html in web cache
+ webnotes.conn.begin()
+ webnotes.conn.set_value('Web Cache', page_name, 'html', html)
+ webnotes.conn.commit()
+
+ return html
+
+def build_html(args, template):
+ """build html using jinja2 templates"""
+ from jinja2 import Environment, FileSystemLoader
+ jenv = Environment(loader = FileSystemLoader('../erpnext/website/templates'))
+ html = jenv.get_template(template).render(args)
+ return html
+
+def get_outer_env():
+ """env dict for outer template"""
+ import webnotes
+ return {
+ 'top_bar_items': webnotes.conn.sql("""select * from `tabTop Bar Item`
+ where parent='Website Settings' and parentfield='top_bar_items'
+ order by idx asc""", as_dict=1),
+
+ 'footer_items': webnotes.conn.sql("""select * from `tabTop Bar Item`
+ where parent='Website Settings' and parentfield='footer_items'
+ order by idx asc""", as_dict=1),
+
+ 'brand': webnotes.conn.get_value('Website Settings', None, 'brand_html'),
+ 'copyright': webnotes.conn.get_value('Website Settings', None, 'copyright'),
+ }
+
+def get_index_page():
+ import webnotes
+ doc_type = 'Web Page'
+ doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
+ page_name = webnotes.conn.get_value(doc_type, doc_name, 'page_name')
+ return page_name, doc_type, doc_name
+
+# cache management
+def clear_web_cache(doc_type, doc_name, page_name):
+ """
+ * check if a record corresponding to (type, name) exists
+ * if exists, just clear html column
+ * if does not exist, create a record for (type, name)
+ * if a record like (some other type, name) exists, raise exception that the page name is not unique
+ """
+ import webnotes
+ res = webnotes.conn.get_value('Web Cache', page_name, 'doc_type')
+ if not res:
+ 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()
+ elif res == doc_type:
+ webnotes.conn.set_value('Web Cache', page_name, 'html', None)
+ else:
+ webnotes.msgprint("""Page with name "%s" already exists as a %s.
+ Please save it with another name.""" % (page_name, res), raise_exception=1)
+
+def clear_all_web_cache():
+ import webnotes
+ webnotes.conn.sql("update `tabWeb Cache` set html = NULL")
+
+def delete_web_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 build_web_cache():
+ """build web cache so that pages can load faster"""
+ pass
\ No newline at end of file
diff --git a/erpnext/website/web_page.py b/erpnext/website/web_page.py
new file mode 100644
index 0000000..58ff40b
--- /dev/null
+++ b/erpnext/website/web_page.py
@@ -0,0 +1,79 @@
+# 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/>.
+
+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 and save again.""" % self.doctype, 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.clear_web_cache(self.doctype, self.doc.name, self.doc.page_name)
+
+ def delete_web_cache(self, page_name):
+ """delete entry of page name from Web Cache"""
+ website.web_cache.delete_web_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"])
\ No newline at end of file
diff --git a/public/js/all-app.js b/public/js/all-app.js
index 791c0a3..f320cc1 100644
--- a/public/js/all-app.js
+++ b/public/js/all-app.js
@@ -252,8 +252,7 @@
wn.route=function(){if(wn.re_route[window.location.hash]){var re_route_val=wn.get_route_str(wn.re_route[window.location.hash]);var cur_route_val=wn.get_route_str(wn._cur_route);if(decodeURIComponent(re_route_val)===decodeURIComponent(cur_route_val)){window.history.back();return;}else{window.location.hash=wn.re_route[window.location.hash];}}
wn._cur_route=window.location.hash;route=wn.get_route();switch(route[0]){case"List":wn.views.doclistview.show(route[1]);break;case"Form":if(route.length>3){route[2]=route.splice(2).join('/');}
wn.views.formview.show(route[1],route[2]);break;case"Report":wn.views.reportview.show(route[1],route[2]);break;case"Report2":wn.views.reportview2.show();break;default:wn.views.pageview.show(route[0]);}}
-wn.get_route=function(route){if(!wn.boot){return[window.page_name];}
-return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});}
+wn.get_route=function(route){return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});}
wn.get_route_str=function(route){if(!route)
route=window.location.hash;if(route.substr(0,1)=='#')route=route.substr(1);if(route.substr(0,1)=='!')route=route.substr(1);return route;}
wn.set_route=function(){route=$.map(arguments,function(a){return encodeURIComponent(a)}).join('/');window.location.hash=route;wn.app.set_favicon();}
@@ -310,13 +309,13 @@
if(me.no_toolbar||me.hide_toolbar){me.$w.find('.list-toolbar-wrapper').toggle(false);}},make_new_doc:function(new_doctype){new_doc(new_doctype);},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
this.onrun=a0;if(a0&&a0.callback)
this.onrun=a0.callback;if(!a1&&!(a0&&a0.append))
-this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(a0),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(opts){if(!this.method){this.query=this.get_query?this.get_query():this.query;this.add_limits();var args={query_max:this.query_max,as_dict:1}
-args.simple_query=this.query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
+this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(a0),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(opts){if(!this.method){var query=this.get_query?this.get_query():this.query;query=this.add_limits(query);var args={query_max:this.query_max,as_dict:1}
+args.simple_query=query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
if(this.args)
$.extend(args,this.args)
if(this.get_args){$.extend(args,this.get_args(opts));}
return args;},render_results:function(r){if(this.start==0)this.clear();this.$w.find('.btn-more').toggle(false);if(r.message)r.values=r.message;if(r.values&&r.values.length){this.data=this.data.concat(r.values);this.render_list(r.values);this.update_paging(r.values);}else{if(this.start==0){this.$w.find('.result').toggle(false);this.$w.find('.no-result').toggle(true);}}
-if(this.onrun)this.onrun();if(this.callback)this.callback(r);},render_list:function(values){var m=Math.min(values.length,this.page_length);for(var i=0;i<m;i++){this.render_row(this.add_row(),values[i],this,i);}},update_paging:function(values){if(values.length>=this.page_length){this.$w.find('.btn-more').toggle(true);this.start+=this.page_length;}},add_row:function(){return $('<div class="list-row">').appendTo(this.$w.find('.result-list')).get(0);},refresh:function(){this.run();},add_limits:function(){this.query+=' LIMIT '+this.start+','+(this.page_length+1);}});
+if(this.onrun)this.onrun();if(this.callback)this.callback(r);},render_list:function(values){var m=Math.min(values.length,this.page_length);for(var i=0;i<m;i++){this.render_row(this.add_row(),values[i],this,i);}},update_paging:function(values){if(values.length>=this.page_length){this.$w.find('.btn-more').toggle(true);this.start+=this.page_length;}},add_row:function(){return $('<div class="list-row">').appendTo(this.$w.find('.result-list')).get(0);},refresh:function(){this.run();},add_limits:function(query){query+=' LIMIT '+this.start+','+(this.page_length+1);return query}});
/*
* lib/js/wn/ui/filters.js
*/
@@ -390,7 +389,7 @@
/*
* lib/js/wn/request.js
*/
-wn.provide('wn.request');wn.request.url='index.cgi';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts)
+wn.provide('wn.request');wn.request.url='server.py';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts)
throw"Incomplete Request";}}
wn.request.cleanup=function(opts,r){if(opts.btn)$(opts.btn).done_working();if(opts.show_spinner)hide_loading();if(opts.freeze)unfreeze();if(wn.boot&&wn.boot.sid&&wn.get_cookie('sid')!=wn.boot.sid){if(!wn.app.logged_out){msgprint('Session Expired. Logging you out');wn.app.logout();}
return;}
diff --git a/public/js/all-web.js b/public/js/all-web.js
index de09c32..257984e 100644
--- a/public/js/all-web.js
+++ b/public/js/all-web.js
@@ -139,8 +139,7 @@
wn.route=function(){if(wn.re_route[window.location.hash]){var re_route_val=wn.get_route_str(wn.re_route[window.location.hash]);var cur_route_val=wn.get_route_str(wn._cur_route);if(decodeURIComponent(re_route_val)===decodeURIComponent(cur_route_val)){window.history.back();return;}else{window.location.hash=wn.re_route[window.location.hash];}}
wn._cur_route=window.location.hash;route=wn.get_route();switch(route[0]){case"List":wn.views.doclistview.show(route[1]);break;case"Form":if(route.length>3){route[2]=route.splice(2).join('/');}
wn.views.formview.show(route[1],route[2]);break;case"Report":wn.views.reportview.show(route[1],route[2]);break;case"Report2":wn.views.reportview2.show();break;default:wn.views.pageview.show(route[0]);}}
-wn.get_route=function(route){if(!wn.boot){return[window.page_name];}
-return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});}
+wn.get_route=function(route){return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});}
wn.get_route_str=function(route){if(!route)
route=window.location.hash;if(route.substr(0,1)=='#')route=route.substr(1);if(route.substr(0,1)=='!')route=route.substr(1);return route;}
wn.set_route=function(){route=$.map(arguments,function(a){return encodeURIComponent(a)}).join('/');window.location.hash=route;wn.app.set_favicon();}
@@ -197,13 +196,13 @@
if(me.no_toolbar||me.hide_toolbar){me.$w.find('.list-toolbar-wrapper').toggle(false);}},make_new_doc:function(new_doctype){new_doc(new_doctype);},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
this.onrun=a0;if(a0&&a0.callback)
this.onrun=a0.callback;if(!a1&&!(a0&&a0.append))
-this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(a0),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(opts){if(!this.method){this.query=this.get_query?this.get_query():this.query;this.add_limits();var args={query_max:this.query_max,as_dict:1}
-args.simple_query=this.query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
+this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(a0),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(opts){if(!this.method){var query=this.get_query?this.get_query():this.query;query=this.add_limits(query);var args={query_max:this.query_max,as_dict:1}
+args.simple_query=query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
if(this.args)
$.extend(args,this.args)
if(this.get_args){$.extend(args,this.get_args(opts));}
return args;},render_results:function(r){if(this.start==0)this.clear();this.$w.find('.btn-more').toggle(false);if(r.message)r.values=r.message;if(r.values&&r.values.length){this.data=this.data.concat(r.values);this.render_list(r.values);this.update_paging(r.values);}else{if(this.start==0){this.$w.find('.result').toggle(false);this.$w.find('.no-result').toggle(true);}}
-if(this.onrun)this.onrun();if(this.callback)this.callback(r);},render_list:function(values){var m=Math.min(values.length,this.page_length);for(var i=0;i<m;i++){this.render_row(this.add_row(),values[i],this,i);}},update_paging:function(values){if(values.length>=this.page_length){this.$w.find('.btn-more').toggle(true);this.start+=this.page_length;}},add_row:function(){return $('<div class="list-row">').appendTo(this.$w.find('.result-list')).get(0);},refresh:function(){this.run();},add_limits:function(){this.query+=' LIMIT '+this.start+','+(this.page_length+1);}});
+if(this.onrun)this.onrun();if(this.callback)this.callback(r);},render_list:function(values){var m=Math.min(values.length,this.page_length);for(var i=0;i<m;i++){this.render_row(this.add_row(),values[i],this,i);}},update_paging:function(values){if(values.length>=this.page_length){this.$w.find('.btn-more').toggle(true);this.start+=this.page_length;}},add_row:function(){return $('<div class="list-row">').appendTo(this.$w.find('.result-list')).get(0);},refresh:function(){this.run();},add_limits:function(query){query+=' LIMIT '+this.start+','+(this.page_length+1);return query}});
/*
* lib/js/wn/ui/filters.js
*/
@@ -277,7 +276,7 @@
/*
* lib/js/wn/request.js
*/
-wn.provide('wn.request');wn.request.url='index.cgi';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts)
+wn.provide('wn.request');wn.request.url='server.py';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts)
throw"Incomplete Request";}}
wn.request.cleanup=function(opts,r){if(opts.btn)$(opts.btn).done_working();if(opts.show_spinner)hide_loading();if(opts.freeze)unfreeze();if(wn.boot&&wn.boot.sid&&wn.get_cookie('sid')!=wn.boot.sid){if(!wn.app.logged_out){msgprint('Session Expired. Logging you out');wn.app.logout();}
return;}
diff --git a/public/js/product_category.js b/public/js/product_category.js
index aac872f..da50d78 100644
--- a/public/js/product_category.js
+++ b/public/js/product_category.js
@@ -3,5 +3,8 @@
* erpnext/website/js/product_category.js
*/
erpnext.make_product_categories=function(wrapper){wrapper.category_list=new wn.ui.Listing({parent:$(wrapper).find('.more-categories').get(0),query:'select count(name) as items, item_group \
- from tabItem where is_sales_item="Yes" \
- group by item_group order by items desc',hide_refresh:true,render_row:function(parent,data){parent.innerHTML=repl('<a href="#!products/%(item_group)s">%(item_group)s</a> (%(items)s)',data);}});wrapper.category_list.run();}
\ No newline at end of file
+ from tabItem \
+ where is_sales_item="Yes" and \
+ ifnull(show_in_website, "No")="Yes" and \
+ docstatus = 0 \
+ group by item_group order by items desc',hide_refresh:true,render_row:function(parent,data){parent.innerHTML=repl('<a href="#!products/%(item_group)s">%(item_group)s</a> (%(items)s)',data);}});wrapper.category_list.run();console.log('product categories made');}
\ No newline at end of file
diff --git a/public/index.cgi b/public/server.py
similarity index 100%
rename from public/index.cgi
rename to public/server.py
diff --git a/public/web.py b/public/web.py
new file mode 100755
index 0000000..e70b61c
--- /dev/null
+++ b/public/web.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+"""
+return a dynamic page from website templates
+
+all html pages except login-page.html get generated here
+"""
+
+import cgi, cgitb, os, sys
+cgitb.enable()
+
+# import libs
+sys.path.append('..')
+import conf
+sys.path.append('../lib/py')
+sys.path.append(conf.modules_path)
+
+def init():
+ import webnotes
+ webnotes.form = cgi.FieldStorage(keep_blank_values=True)
+ for key in webnotes.form.keys():
+ webnotes.form_dict[key] = webnotes.form.getvalue(key)
+ webnotes.connect()
+
+def respond():
+ import webnotes
+ try:
+ if 'page' in webnotes.form_dict:
+ html = get_html(webnotes.form_dict['page'])
+ else:
+ # show home page
+ html = get_html('index')
+ except Exception, e:
+ html = get_html('404')
+
+ print "Content-Type: text/html"
+ print
+ print html.encode('utf-8')
+
+def scrub_page_name(page_name):
+ if page_name.endswith('.html'):
+ page_name = page_name[:-5]
+ return page_name
+
+def get_html(page_name):
+ import webnotes
+ import website.web_cache
+ page_name = scrub_page_name(page_name)
+
+ if page_name == '404':
+ traceback = webnotes.getTraceback()
+
+ # script is used to display traceback in error console
+ args = {
+ 'comments': """error: %s""" % traceback,
+ 'template': '404.html',
+ }
+ # 'script': """(function() {
+ # var error = "ERROR: %s";
+ # console.log(error);
+ # })();""" % traceback.replace('"', '\\"').replace('\n', ' \\\n'),
+ # }
+
+ else:
+ args = {
+ 'comments': """page: %s""" % page_name,
+ 'template': 'page.html',
+ }
+
+ html = website.web_cache.load_from_web_cache(page_name, **args)
+
+ return html
+
+if __name__=="__main__":
+ init()
+ respond()