blob: 4696ebe0423279aa95fc30826099f57fdf7b425f [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
Anand Doshi486f9df2012-07-19 13:40:31 +053019from __future__ import unicode_literals
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053020"""
21return a dynamic page from website templates
Rushabh Mehta96bf0b72012-06-15 17:29:03 +053022
23all html pages except login-page.html get generated here
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053024"""
25
26import cgi, cgitb, os, sys
27cgitb.enable()
28
29# import libs
30sys.path.append('..')
31import conf
32sys.path.append('../lib/py')
33sys.path.append(conf.modules_path)
34
Anand Doshi5d9fc722012-06-21 11:48:51 +053035def init():
36 import webnotes
37 webnotes.form = cgi.FieldStorage(keep_blank_values=True)
38 for key in webnotes.form.keys():
39 webnotes.form_dict[key] = webnotes.form.getvalue(key)
40 webnotes.connect()
41
42def respond():
Anand Doshi72c945b2012-06-22 20:01:07 +053043 import webnotes
Anand Doshi1703cc82012-07-19 20:31:56 +053044 from webnotes.utils import get_encoded_string
Anand Doshi72c945b2012-06-22 20:01:07 +053045 try:
46 if 'page' in webnotes.form_dict:
47 html = get_html(webnotes.form_dict['page'])
48 else:
49 # show home page
50 html = get_html('index')
51 except Exception, e:
52 html = get_html('404')
53
Anand Doshi5d9fc722012-06-21 11:48:51 +053054 print "Content-Type: text/html"
55 print
Anand Doshi1703cc82012-07-19 20:31:56 +053056 print get_encoded_string(html)
Anand Doshi5d9fc722012-06-21 11:48:51 +053057
Anand Doshi72c945b2012-06-22 20:01:07 +053058def get_html(page_name):
Anand Doshi51146c02012-07-12 18:41:12 +053059 import website.utils
60 page_name = website.utils.scrub_page_name(page_name)
61
62 comments = get_comments(page_name)
63
Anand Doshi72c945b2012-06-22 20:01:07 +053064 import website.web_cache
Anand Doshi51146c02012-07-12 18:41:12 +053065 html = website.web_cache.get_html(page_name, comments)
Anand Doshi72c945b2012-06-22 20:01:07 +053066
Anand Doshi5d9fc722012-06-21 11:48:51 +053067 return html
68
Anand Doshi51146c02012-07-12 18:41:12 +053069def get_comments(page_name):
70 import webnotes
71
72 if page_name == '404':
73 comments = """error: %s""" % webnotes.getTraceback()
74 else:
75 comments = """page: %s""" % page_name
76
77 return comments
78
Rushabh Mehtabd7f7232012-06-15 14:00:06 +053079if __name__=="__main__":
Anand Doshi5d9fc722012-06-21 11:48:51 +053080 init()
Anand Doshi51146c02012-07-12 18:41:12 +053081 respond()