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 | 76ec66d | 2012-07-20 18:11:30 +0530 | [diff] [blame] | 19 | """ |
| 20 | return a dynamic page from website templates |
| 21 | |
| 22 | all html pages related to website are generated here |
| 23 | """ |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 24 | from __future__ import unicode_literals |
Rushabh Mehta | bd7f723 | 2012-06-15 14:00:06 +0530 | [diff] [blame] | 25 | import cgi, cgitb, os, sys |
| 26 | cgitb.enable() |
| 27 | |
| 28 | # import libs |
| 29 | sys.path.append('..') |
| 30 | import conf |
| 31 | sys.path.append('../lib/py') |
| 32 | sys.path.append(conf.modules_path) |
| 33 | |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 34 | def init(): |
Anand Doshi | 76ec66d | 2012-07-20 18:11:30 +0530 | [diff] [blame] | 35 | import webnotes.handler |
| 36 | webnotes.handler.get_cgi_fields() |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 37 | webnotes.connect() |
| 38 | |
| 39 | def respond(): |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 40 | import webnotes |
Anand Doshi | 1703cc8 | 2012-07-19 20:31:56 +0530 | [diff] [blame] | 41 | from webnotes.utils import get_encoded_string |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 42 | try: |
| 43 | if 'page' in webnotes.form_dict: |
| 44 | html = get_html(webnotes.form_dict['page']) |
| 45 | else: |
| 46 | # show home page |
| 47 | html = get_html('index') |
| 48 | except Exception, e: |
| 49 | html = get_html('404') |
Anand Doshi | 76ec66d | 2012-07-20 18:11:30 +0530 | [diff] [blame] | 50 | |
| 51 | content = [] |
| 52 | import webnotes.handler |
| 53 | html = get_encoded_string(html) |
| 54 | html, content = webnotes.handler.gzip_response(html, content) |
| 55 | |
| 56 | content += [ |
| 57 | "Content-Type: text/html", |
| 58 | "", |
| 59 | ] |
| 60 | |
| 61 | webnotes.handler.print_content(content) |
| 62 | print html |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 63 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 64 | def get_html(page_name): |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 65 | import website.utils |
| 66 | page_name = website.utils.scrub_page_name(page_name) |
| 67 | |
| 68 | comments = get_comments(page_name) |
| 69 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 70 | import website.web_cache |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 71 | html = website.web_cache.get_html(page_name, comments) |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 72 | |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 73 | return html |
| 74 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 75 | def get_comments(page_name): |
| 76 | import webnotes |
| 77 | |
| 78 | if page_name == '404': |
| 79 | comments = """error: %s""" % webnotes.getTraceback() |
| 80 | else: |
| 81 | comments = """page: %s""" % page_name |
| 82 | |
| 83 | return comments |
| 84 | |
Rushabh Mehta | bd7f723 | 2012-06-15 14:00:06 +0530 | [diff] [blame] | 85 | if __name__=="__main__": |
Anand Doshi | 5d9fc72 | 2012-06-21 11:48:51 +0530 | [diff] [blame] | 86 | init() |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 87 | respond() |