# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) # # MIT License (MIT) # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # """ Generate index.cgi html Loads index.html from the template with: 1. bootinfo 2. static html of home / if _escaped_fragment_ is given 3. top menus and bottom menus """ import webnotes body_html = """
Loading...
""" def get(): """get index html""" import webnotes from jinja2 import Template with open('lib/conf/index.html', 'r') as f: template = Template(f.read()) # google crawler if '_escaped_fragment_' in webnotes.form: page = webnotes.form_dict['_escaped_fragment_'] if not page: page = webnotes.user.get_home_page() return template.render(bootinfo = '', style_tag='', version='0', analytics_code = '',\ script_tag = '', body_html=html_snapshot(page), ajax_meta_tag = '') # home page else: import webnotes.session_cache from build.project import get_version import json bootdict = webnotes.session_cache.get() bootinfo = """var wn = {}; wn.boot = %s;""" % json.dumps(bootdict) if webnotes.session['user'] == 'Guest': script_tag = '' style_tag = '' else: script_tag = '' style_tag = '' return template.render(bootinfo = bootinfo, version = get_version(), script_tag = script_tag, style_tag = style_tag, body_html=body_html % '', ajax_meta_tag = '', analytics_code = bootdict.get('analytics_code', '') or '') def html_snapshot(page): """get html snapshot for search bot""" from webnotes.widgets.page import get_page_html from webnotes.model.doc import Document doc = Document('Website Settings', 'Website Settings') doc.content = get_page_html(page) doc.header_menu = doc.footer_menu = '' doc.page_name = page for m in webnotes.conn.sql("""select parentfield, label, url, custom_page from `tabTop Bar Item` where parent='Top Bar Settings' order by idx""", as_dict=1): m['std_page'] = m.get('url') or m.get('custom_page') if m['parentfield']=='top_bar_items': doc.header_menu += '
  • %(label)s
  • ' % m else: doc.footer_menu += '
  • %(label)s
  • ' % m return """

    %(brand_html)s

    %(content)s """ % doc.fields