blob: 32b3cd57d82c2e475ee9dd1608b09ce2e4a05490 [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':
Anand Doshibba4db12012-06-27 12:06:45 +053051 traceback = webnotes.getTraceback()
52
53 # script is used to display traceback in error console
54 args = {
55 'comments': """error: %s""" % traceback,
56 'template': '404.html',
57 }
Anand Doshi72c945b2012-06-22 20:01:07 +053058 else:
Anand Doshibba4db12012-06-27 12:06:45 +053059 args = {
60 'comments': """page: %s""" % page_name,
61 'template': 'page.html',
62 }
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053063
Anand Doshibba4db12012-06-27 12:06:45 +053064 html = website.web_cache.load_from_web_cache(page_name, **args)
Anand Doshi72c945b2012-06-22 20:01:07 +053065
Anand Doshi5d9fc722012-06-21 11:48:51 +053066 return html
67
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053068if __name__=="__main__":
Anand Doshi5d9fc722012-06-21 11:48:51 +053069 init()
70 respond()