blob: 34d38feca00253f73e31e883b2acc92afe1eecf5 [file] [log] [blame]
Rushabh Mehtabd7f7232012-06-15 14:00:06 +05301#!/usr/bin/env python
2
Anand Doshi51146c02012-07-12 18:41:12 +05303# ERPNext - web based ERP (http://erpnext.com)
4# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053019"""
20return a dynamic page from website templates
Rushabh Mehta96bf0b72012-06-15 17:29:03 +053021
22all html pages except login-page.html get generated here
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053023"""
24
25import cgi, cgitb, os, sys
26cgitb.enable()
27
28# import libs
29sys.path.append('..')
30import conf
31sys.path.append('../lib/py')
32sys.path.append(conf.modules_path)
33
Anand Doshi5d9fc722012-06-21 11:48:51 +053034def init():
35 import webnotes
36 webnotes.form = cgi.FieldStorage(keep_blank_values=True)
37 for key in webnotes.form.keys():
38 webnotes.form_dict[key] = webnotes.form.getvalue(key)
39 webnotes.connect()
40
41def respond():
Anand Doshi72c945b2012-06-22 20:01:07 +053042 import webnotes
43 try:
44 if 'page' in webnotes.form_dict:
45 html = get_html(webnotes.form_dict['page'])
46 else:
47 # show home page
48 html = get_html('index')
49 except Exception, e:
50 html = get_html('404')
51
Anand Doshi5d9fc722012-06-21 11:48:51 +053052 print "Content-Type: text/html"
53 print
54 print html.encode('utf-8')
55
Anand Doshi72c945b2012-06-22 20:01:07 +053056def get_html(page_name):
Anand Doshi51146c02012-07-12 18:41:12 +053057 import website.utils
58 page_name = website.utils.scrub_page_name(page_name)
59
60 comments = get_comments(page_name)
61
Anand Doshi72c945b2012-06-22 20:01:07 +053062 import website.web_cache
Anand Doshi51146c02012-07-12 18:41:12 +053063 html = website.web_cache.get_html(page_name, comments)
Anand Doshi72c945b2012-06-22 20:01:07 +053064
Anand Doshi5d9fc722012-06-21 11:48:51 +053065 return html
66
Anand Doshi51146c02012-07-12 18:41:12 +053067def get_comments(page_name):
68 import webnotes
69
70 if page_name == '404':
71 comments = """error: %s""" % webnotes.getTraceback()
72 else:
73 comments = """page: %s""" % page_name
74
75 return comments
76
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053077if __name__=="__main__":
Anand Doshi5d9fc722012-06-21 11:48:51 +053078 init()
Anand Doshi51146c02012-07-12 18:41:12 +053079 respond()