blob: 6f3569e32797af675773c825c5e7ef794fd7ee4d [file] [log] [blame]
Rushabh Mehtabd7f7232012-06-15 14:00:06 +05301#!/usr/bin/env python
2
3"""
4return a dynamic page from website templates
Rushabh Mehta96bf0b72012-06-15 17:29:03 +05305
6all html pages except login-page.html get generated here
Rushabh Mehtabd7f7232012-06-15 14:00:06 +05307"""
8
9import cgi, cgitb, os, sys
10cgitb.enable()
11
12# import libs
13sys.path.append('..')
14import conf
15sys.path.append('../lib/py')
16sys.path.append(conf.modules_path)
17
Anand Doshi5d9fc722012-06-21 11:48:51 +053018def init():
19 import webnotes
20 webnotes.form = cgi.FieldStorage(keep_blank_values=True)
21 for key in webnotes.form.keys():
22 webnotes.form_dict[key] = webnotes.form.getvalue(key)
23 webnotes.connect()
24
25def respond():
Anand Doshi72c945b2012-06-22 20:01:07 +053026 import webnotes
27 try:
28 if 'page' in webnotes.form_dict:
29 html = get_html(webnotes.form_dict['page'])
30 else:
31 # show home page
32 html = get_html('index')
33 except Exception, e:
34 html = get_html('404')
35
Anand Doshi5d9fc722012-06-21 11:48:51 +053036 print "Content-Type: text/html"
37 print
38 print html.encode('utf-8')
39
Anand Doshi72c945b2012-06-22 20:01:07 +053040def scrub_page_name(page_name):
41 if page_name.endswith('.html'):
42 page_name = page_name[:-5]
43 return page_name
44
45def get_html(page_name):
Anand Doshi5d9fc722012-06-21 11:48:51 +053046 import webnotes
Anand Doshi72c945b2012-06-22 20:01:07 +053047 import website.web_cache
48 page_name = scrub_page_name(page_name)
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053049
Anand Doshi72c945b2012-06-22 20:01:07 +053050 if page_name == '404':
51 comments = """error: %s""" % webnotes.getTraceback()
52 template = '404.html'
53 else:
54 comments = """page: %s""" % page_name
55 template = 'page.html'
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053056
Anand Doshi72c945b2012-06-22 20:01:07 +053057 html = website.web_cache.load_from_web_cache(page_name, comments, template)
58
Anand Doshi5d9fc722012-06-21 11:48:51 +053059 return html
60
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053061if __name__=="__main__":
Anand Doshi5d9fc722012-06-21 11:48:51 +053062 init()
63 respond()