diff --git a/accounts/page/voucher_import_tool/voucher_import_tool.py b/accounts/page/voucher_import_tool/voucher_import_tool.py index 4afa41af7d..ab81801c53 100644 --- a/accounts/page/voucher_import_tool/voucher_import_tool.py +++ b/accounts/page/voucher_import_tool/voucher_import_tool.py @@ -179,7 +179,7 @@ def import_vouchers(common_values, data, start_idx, import_type): def get_common_values(rows): start = False - common_values = webnotes.DictObj() + common_values = webnotes._dict() for r in rows: if start: @@ -200,7 +200,7 @@ def get_data(rows, company_abbr): if r[0]: if start_row and i >= start_row: if not start_row_idx: start_row_idx = i - d, acc_dict = webnotes.DictObj(), webnotes.DictObj() + d, acc_dict = webnotes._dict(), webnotes._dict() for cidx in xrange(len(columns)): d[columns[cidx]] = r[cidx] diff --git a/controllers/tax_controller.py b/controllers/tax_controller.py index d70ba3e4f2..009ab31628 100644 --- a/controllers/tax_controller.py +++ b/controllers/tax_controller.py @@ -37,7 +37,7 @@ class TaxController(TransactionController): {"parentfield": self.fmap.taxes_and_charges}) for base_tax in master_tax_list: - tax = DictObj([[field, base_tax.fields.get(field)] + tax = _dict([[field, base_tax.fields.get(field)] for field in base_tax.fields if field not in webnotes.model.default_fields]) tax.update({ diff --git a/controllers/transaction_controller.py b/controllers/transaction_controller.py index 07fdc67b85..3e4d62e291 100644 --- a/controllers/transaction_controller.py +++ b/controllers/transaction_controller.py @@ -17,7 +17,7 @@ from __future__ import unicode_literals import webnotes import webnotes.model -from webnotes import _, DictObj +from webnotes import _, _dict from webnotes.utils import cint import json @@ -32,7 +32,7 @@ class TransactionController(DocListController): @property def precision(self): if not hasattr(self, "_precision"): - self._precision = DictObj() + self._precision = _dict() self._precision.main = self.meta.get_precision_map() self._precision.item = self.meta.get_precision_map(parentfield = \ self.item_table_field) @@ -69,7 +69,7 @@ class TransactionController(DocListController): if not hasattr(self, "_fmap"): if self.doc.doctype in ["Lead", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note"]: - self._fmap = webnotes.DictObj( { + self._fmap = webnotes._dict( { "exchange_rate": "conversion_rate", "taxes_and_charges": "other_charges", "taxes_and_charges_master": "charge", @@ -93,7 +93,7 @@ class TransactionController(DocListController): "cost_center": "cost_center_other_charges", }) else: - self._fmap = webnotes.DictObj({ + self._fmap = webnotes._dict({ "exchange_rate": "conversion_rate", "taxes_and_charges": "purchase_tax_details", "taxes_and_charges_master": "purchase_other_charges", @@ -120,4 +120,4 @@ class TransactionController(DocListController): "rate": "rate" }) - return self._fmap or webnotes.DictObj() \ No newline at end of file + return self._fmap or webnotes._dict() \ No newline at end of file diff --git a/website/doctype/style_settings/style_settings.py b/website/doctype/style_settings/style_settings.py index bf39c8d6c5..113dbf89d4 100644 --- a/website/doctype/style_settings/style_settings.py +++ b/website/doctype/style_settings/style_settings.py @@ -45,6 +45,5 @@ class DocType: def on_update(self): """rebuild pages""" - from webnotes.cms.make import make_web_core - make_web_core() - \ No newline at end of file + from website.helpers.make_web_include_files import make + make() \ No newline at end of file diff --git a/website/doctype/website_settings/website_settings.py b/website/doctype/website_settings/website_settings.py index 577e8d57bb..88af6348ac 100644 --- a/website/doctype/website_settings/website_settings.py +++ b/website/doctype/website_settings/website_settings.py @@ -24,8 +24,8 @@ class DocType: def on_update(self): # make js and css - from webnotes.cms.make import make_web_core - make_web_core() + from website.helpers.make_web_include_files import make + make() # clear web cache (for menus!) from website.utils import clear_cache diff --git a/website/helpers/__init__.py b/website/helpers/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website/blog.py b/website/helpers/blog.py similarity index 97% rename from website/blog.py rename to website/helpers/blog.py index f3102f28b7..b294f90e23 100644 --- a/website/blog.py +++ b/website/helpers/blog.py @@ -1,3 +1,6 @@ +# Copyright (c) 2012 Web Notes Technologies Pvt Ltd. +# License: GNU General Public License (v3). For more information see license.txt + from __future__ import unicode_literals import webnotes diff --git a/website/helpers/blog_feed.py b/website/helpers/blog_feed.py new file mode 100644 index 0000000000..20c78cae2a --- /dev/null +++ b/website/helpers/blog_feed.py @@ -0,0 +1,79 @@ +# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) +# +# MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +from __future__ import unicode_literals +""" +Generate RSS feed for blog +""" + +rss = u""" + + + %(title)s + %(description)s + %(link)s + %(modified)s + %(modified)s + 1800 + %(items)s + +""" + +rss_item = u""" + + %(title)s + %(content)s + %(link)s + %(name)s + %(creation)s +""" + +def generate(): + """generate rss feed""" + import webnotes, os + from webnotes.model.doc import Document + from website.helpers.blog import get_blog_content + + host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST') + + items = '' + blog_list = webnotes.conn.sql("""\ + select page_name as name, modified, creation, title from tabBlog + where ifnull(published,0)=1 + order by creation desc, modified desc, name asc limit 100""", as_dict=1) + + for blog in blog_list: + blog.link = host + '/' + blog.name + '.html' + blog.content = get_blog_content(blog.name) + + items += rss_item % blog + + modified = max((blog['modified'] for blog in blog_list)) + + ws = Document('Website Settings', 'Website Settings') + return (rss % { + 'title': ws.title_prefix, + 'description': ws.description or (ws.title_prefix + ' Blog'), + 'modified': modified, + 'items': items, + 'link': host + '/blog.html' + }).encode('utf-8', 'ignore') diff --git a/website/helpers/make_web_include_files.py b/website/helpers/make_web_include_files.py new file mode 100644 index 0000000000..3bbc563631 --- /dev/null +++ b/website/helpers/make_web_include_files.py @@ -0,0 +1,32 @@ +# Copyright (c) 2012 Web Notes Technologies Pvt Ltd. +# License: GNU General Public License (v3). For more information see license.txt + +def make(): + import os + import webnotes + import website.utils + import startup.event_handlers + + if not webnotes.conn: + webnotes.connect() + + home_page = website.utils.get_home_page() + + fname = 'js/wn-web.js' + if os.path.basename(os.path.abspath('.'))!='public': + fname = os.path.join('public', fname) + + if hasattr(startup.event_handlers, 'get_web_script'): + with open(fname, 'w') as f: + script = 'window.home_page = "%s";\n' % home_page + script += startup.event_handlers.get_web_script() + f.write(script) + + fname = 'css/wn-web.css' + if os.path.basename(os.path.abspath('.'))!='public': + fname = os.path.join('public', fname) + + # style - wn.css + if hasattr(startup.event_handlers, 'get_web_style'): + with open(fname, 'w') as f: + f.write(startup.event_handlers.get_web_style()) \ No newline at end of file diff --git a/website/product.py b/website/helpers/product.py similarity index 95% rename from website/product.py rename to website/helpers/product.py index fd471cb510..6bafc2b436 100644 --- a/website/product.py +++ b/website/helpers/product.py @@ -1,3 +1,6 @@ +# Copyright (c) 2012 Web Notes Technologies Pvt Ltd. +# License: GNU General Public License (v3). For more information see license.txt + from __future__ import unicode_literals import webnotes diff --git a/website/helpers/sitemap.py b/website/helpers/sitemap.py new file mode 100644 index 0000000000..23008af665 --- /dev/null +++ b/website/helpers/sitemap.py @@ -0,0 +1,38 @@ +# Copyright (c) 2012 Web Notes Technologies Pvt Ltd. +# License: GNU General Public License (v3). For more information see license.txt + +from __future__ import unicode_literals +frame_xml = """ +%s +""" + +link_xml = """\n%s%s""" + +# generate the sitemap XML +def generate(domain): + global frame_xml, link_xml + import urllib, os + import webnotes + import website.utils + + # settings + max_doctypes = 10 + max_items = 1000 + + site_map = '' + page_list = [] + + if domain: + # list of all pages in web cache + for doctype in website.utils.page_map: + d = website.utils.page_map[doctype]; + pages = webnotes.conn.sql("""select page_name, `modified` + from `tab%s` where ifnull(%s,0)=1 + order by modified desc""" % (doctype, d.condition_field)) + + for p in pages: + page_url = os.path.join(domain, urllib.quote(p[0]) + '.html') + modified = p[1].strftime('%Y-%m-%d') + site_map += link_xml % (page_url, modified) + + return frame_xml % site_map diff --git a/website/templates/js/blog.js b/website/templates/js/blog.js index 8c9b9d7252..a5ade31af3 100644 --- a/website/templates/js/blog.js +++ b/website/templates/js/blog.js @@ -18,7 +18,7 @@ wn.pages['{{ name }}'].onload = function(wrapper) { erpnext.blog_list = new wn.ui.Listing({ parent: $(wrapper).find('#blog-list').get(0), - method: 'website.blog.get_blog_list', + method: 'website.helpers.blog.get_blog_list', hide_refresh: true, no_toolbar: true, render_row: function(parent, data) { diff --git a/website/templates/js/blog_page.js b/website/templates/js/blog_page.js index 617993c508..524de8e770 100644 --- a/website/templates/js/blog_page.js +++ b/website/templates/js/blog_page.js @@ -52,7 +52,7 @@ erpnext.blog.render_recent_list = function(wrapper) { wrapper.recent_list = new wn.ui.Listing({ parent: $(wrapper).find('.recent-posts'), no_toolbar: true, - method: 'website.blog.get_recent_blog_list', + method: 'website.helpers.blog.get_recent_blog_list', get_args: function() { return { name: '{{ name }}' } }, @@ -139,7 +139,7 @@ erpnext.blog.add_comment = function(wrapper) { args.page_name = '{{ page_name }}'; wn.call({ - method: 'website.blog.add_comment', + method: 'website.helpers.blog.add_comment', args: args, btn: this, callback: function(r) { diff --git a/website/templates/js/blog_subscribe.js b/website/templates/js/blog_subscribe.js index b3e10a7f70..cdc013025d 100644 --- a/website/templates/js/blog_subscribe.js +++ b/website/templates/js/blog_subscribe.js @@ -15,7 +15,7 @@ wn.provide('erpnext.blog'); var args = d.get_values(); if(!args) return; wn.call({ - method: 'website.blog.add_subscriber', + method: 'website.helpers.blog.add_subscriber', args: args, callback: function(r) { if(r.exc) { diff --git a/website/templates/js/product_category.js b/website/templates/js/product_category.js index 4229d00c6c..2b34708ec2 100644 --- a/website/templates/js/product_category.js +++ b/website/templates/js/product_category.js @@ -6,7 +6,7 @@ erpnext.products.make_product_categories = function(wrapper) { wrapper.category_list = new wn.ui.Listing({ parent: $(wrapper).find('.more-categories').get(0), - method: 'website.product.get_product_category_list', + method: 'website.helpers.product.get_product_category_list', hide_refresh: true, render_row: function(parent, data) { parent.innerHTML = repl( diff --git a/website/templates/js/product_page.js b/website/templates/js/product_page.js index 0c4abb4195..f4620336e8 100644 --- a/website/templates/js/product_page.js +++ b/website/templates/js/product_page.js @@ -53,7 +53,7 @@ erpnext.products.make_similar_products = function(wrapper) { parent: $(wrapper).find('.similar-products').get(0), hide_refresh: true, page_length: 5, - method: 'website.product.get_similar_product_list', + method: 'website.helpers.product.get_similar_product_list', get_args: function() { return { product_group: wrapper.product_group, diff --git a/website/templates/js/products.js b/website/templates/js/products.js index f4c68cbf80..720d192f3e 100644 --- a/website/templates/js/products.js +++ b/website/templates/js/products.js @@ -45,7 +45,7 @@ erpnext.products.make_product_list = function(wrapper) { parent: $(wrapper).find('#products-list').get(0), run_btn: $(wrapper).find('.products-search .btn').get(0), no_toolbar: true, - method: 'website.product.get_product_list', + method: 'website.helpers.product.get_product_list', get_args: function() { return { search: $('input[name="products-search"]').val() || '', diff --git a/website/utils.py b/website/utils.py index 70b05ed91e..991a486003 100644 --- a/website/utils.py +++ b/website/utils.py @@ -21,10 +21,19 @@ import conf import webnotes from webnotes.utils import cstr -template_map = { - 'Web Page': 'html/web_page.html', - 'Blog': 'html/blog_page.html', - 'Item': 'html/product_page.html', +page_map = { + 'Web Page': webnotes._dict({ + "template": 'html/web_page.html', + "condition_field": "published" + }), + 'Blog': webnotes._dict({ + "template": 'html/blog_page.html', + "condition_field": "published", + }), + 'Item': webnotes._dict({ + "template": 'html/product_page.html', + "condition_field": "show_in_website", + }) } def render(page_name): @@ -51,11 +60,12 @@ def get_html(page_name): # load from cache, if auto cache clear is falsy if not (hasattr(conf, 'auto_cache_clear') and conf.auto_cache_clear or 0): html = webnotes.cache().get_value("page:" + page_name) - comments += "\nload status: fresh" - if not html: - html = load_into_cache(page_name) + if html: comments += "\nload status: cache" + else: + html = load_into_cache(page_name) + comments += "\nload status: fresh" # insert comments html += """\n""" % webnotes.utils.cstr(comments) @@ -131,7 +141,7 @@ def prepare_args(page_name): return args -def get_template_pages(): +def get_template_pages(): pages_path = os.path.join(os.path.dirname(conf.__file__), 'app', 'website', 'templates', 'pages') page_list = [] @@ -142,27 +152,25 @@ def get_template_pages(): def get_doc_fields(page_name): doc_type, doc_name = get_source_doc(page_name) - obj = webnotes.get_obj(doc_type, doc_name) - + if hasattr(obj, 'prepare_template_args'): obj.prepare_template_args() - + args = obj.doc.fields - args['template'] = template_map[doc_type] + args['template'] = page_map[doc_type].template return args 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')]: + for doctype in page_map: 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) + page_name=%s and ifnull(%s, 0)=1""" % (doctype, "%s", + page_map[doctype].condition_field), page_name) if name: - return doctype[0], name[0][0] - + return doctype, name[0][0] + return None, None def get_outer_env(): @@ -205,7 +213,7 @@ def get_home_page(): return page_name -def clear_cache(page_name): +def clear_cache(page_name=None): if page_name: delete_page_cache(page_name) else: