fixes in web cache record insert for exceptional pages like 404, login-page, index etc.
diff --git a/erpnext/patches/june_2012/cms2.py b/erpnext/patches/june_2012/cms2.py
index fe4774e..a877c76 100644
--- a/erpnext/patches/june_2012/cms2.py
+++ b/erpnext/patches/june_2012/cms2.py
@@ -33,27 +33,5 @@
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
+ import website.web_cache
+ website.web_cache.rebuild_web_cache()
\ No newline at end of file
diff --git a/erpnext/website/web_cache.py b/erpnext/website/web_cache.py
index f83e562..0221f47 100644
--- a/erpnext/website/web_cache.py
+++ b/erpnext/website/web_cache.py
@@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+page_exception_list = ['404', 'blog', 'products', 'login-page']
+
# used by web.py
def load_from_web_cache(page_name, comments, template):
"""
@@ -23,17 +25,13 @@
"""
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
- page_exception_list = ['404', 'index', 'blog', 'products', 'login-page']
- if not res and page_name not in page_exception_list:
+ if not res and page_name not in page_exception_list + ['index']:
raise Exception, "Page %s not found" % page_name
html, doc_type, doc_name = res and res[0] or (None, None, None)
@@ -75,7 +73,8 @@
# save html in web cache
webnotes.conn.begin()
- clear_web_cache(doc_type, doc_name, page_name)
+ if page_name in page_exception_list + ['index']:
+ clear_web_cache(doc_type, doc_name, page_name)
webnotes.conn.set_value('Web Cache', page_name, 'html', html)
webnotes.conn.commit()
@@ -85,7 +84,7 @@
if page_name == 'index':
page_name, doc_type, doc_name = get_index_page()
- if page_name in ['404', 'blog', 'products', 'login-page']:
+ if page_name in page_exception_list:
args = {
'name': page_name,
}
@@ -143,7 +142,7 @@
* 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')
+ res = webnotes.conn.get_value('Web Cache', page_name, ['doc_type', 'name'])
if not res:
import webnotes.model.doc
d = webnotes.model.doc.Document('Web Cache')
@@ -152,11 +151,11 @@
d.doc_name = doc_name
d.html = None
d.save()
- elif res == doc_type:
+ elif not doc_type or res[0] == 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)
+ Please save it with another name.""" % (page_name, res[0]), raise_exception=1)
def clear_all_web_cache():
import webnotes
@@ -174,6 +173,29 @@
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
+def rebuild_web_cache():
+ """build web cache entries"""
+ 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, 0) = 1"""
+ }
+ ]
+
+ 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