html generation moved from web.py to web_cache.py so it can be called from other places as a response from server.py

This commit is contained in:
Rushabh Mehta 2012-08-02 13:07:23 +05:30
parent dc40385d41
commit a4fe7180f4
3 changed files with 37 additions and 32 deletions

View File

@ -41,3 +41,37 @@ def page_name(title):
name = title.lower()
name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
return '-'.join(name.split()[:4])
def render(page_name):
"""render html page"""
import webnotes
try:
if page_name:
html = get_html(page_name)
else:
html = get_html('index')
except Exception, e:
html = get_html('404')
print "Content-Type: text/html"
print
print html.encode('utf-8')
def get_html(page_name):
"""get page html"""
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)
return html
def get_comments(page_name):
import webnotes
if page_name == '404':
comments = """error: %s""" % webnotes.getTraceback()
else:
comments = """page: %s""" % page_name
return comments

View File

@ -91,6 +91,7 @@ def get_predefined_pages():
return page_list
def prepare_args(page_name):
import webnotes
if page_name == 'index':
page_name = get_home_page()
@ -98,6 +99,7 @@ def prepare_args(page_name):
args = {
'template': 'pages/%s.html' % page_name,
'name': page_name,
'webnotes': webnotes
}
else:
args = get_doc_fields(page_name)

View File

@ -40,39 +40,8 @@ def init():
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 get_html(page_name):
import website.utils
page_name = website.utils.scrub_page_name(page_name)
comments = get_comments(page_name)
import website.web_cache
html = website.web_cache.get_html(page_name, comments)
return html
def get_comments(page_name):
import webnotes
if page_name == '404':
comments = """error: %s""" % webnotes.getTraceback()
else:
comments = """page: %s""" % page_name
return comments
return website.utils.render(webnotes.form_dict.get('page'))
if __name__=="__main__":
init()