Rushabh Mehta | bd7f723 | 2012-06-15 14:00:06 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 3 | # 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 Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 19 | from __future__ import unicode_literals |
Rushabh Mehta | bd7f723 | 2012-06-15 14:00:06 +0530 | [diff] [blame] | 20 | """ |
| 21 | return a dynamic page from website templates |
Rushabh Mehta | 96bf0b7 | 2012-06-15 17:29:03 +0530 | [diff] [blame] | 22 | |
| 23 | all html pages except login-page.html get generated here |
Rushabh Mehta | bd7f723 | 2012-06-15 14:00:06 +0530 | [diff] [blame] | 24 | """ |
| 25 | |
| 26 | import cgi, cgitb, os, sys |
| 27 | cgitb.enable() |
| 28 | |
| 29 | # import libs |
| 30 | sys.path.append('..') |
| 31 | import conf |
| 32 | sys.path.append('../lib/py') |
| 33 | sys.path.append(conf.modules_path) |
| 34 | |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 35 | def 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 | |
| 42 | def respond(): |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 43 | import webnotes |
Anand Doshi | 1703cc8 | 2012-07-19 20:31:56 +0530 | [diff] [blame^] | 44 | from webnotes.utils import get_encoded_string |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 45 | 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 Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 54 | print "Content-Type: text/html" |
| 55 | print |
Anand Doshi | 1703cc8 | 2012-07-19 20:31:56 +0530 | [diff] [blame^] | 56 | print get_encoded_string(html) |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 57 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 58 | def get_html(page_name): |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 59 | import website.utils |
| 60 | page_name = website.utils.scrub_page_name(page_name) |
| 61 | |
| 62 | comments = get_comments(page_name) |
| 63 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 64 | import website.web_cache |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 65 | html = website.web_cache.get_html(page_name, comments) |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 66 | |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 67 | return html |
| 68 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 69 | def 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 Mehta | bd7f723 | 2012-06-15 14:00:06 +0530 | [diff] [blame] | 79 | if __name__=="__main__": |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 80 | init() |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 81 | respond() |