You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. """
  23. Generate index.cgi html
  24. Loads index.html from the template with:
  25. 1. bootinfo
  26. 2. static html of home / if _escaped_fragment_ is given
  27. 3. top menus and bottom menus
  28. """
  29. import webnotes
  30. body_html = """
  31. <header></header>
  32. <!-- Main Starts -->
  33. <div id="body_div">
  34. </div>
  35. <footer></footer>
  36. <div class="no_script" style="display: none;">
  37. %s
  38. </div>
  39. <div id="dialog_back"></div>
  40. """
  41. def get():
  42. """get index html"""
  43. import webnotes
  44. from jinja2 import Template
  45. with open('lib/conf/index.html', 'r') as f:
  46. template = Template(f.read())
  47. # google crawler
  48. if '_escaped_fragment_' in webnotes.form:
  49. page = webnotes.form_dict['_escaped_fragment_']
  50. if not page:
  51. page = webnotes.user.get_home_page()
  52. return template.render(bootinfo = '', style_tag='', version='0', analytics_code = '',\
  53. script_tag = '', body_html=html_snapshot(page), ajax_meta_tag = '')
  54. # home page
  55. else:
  56. import webnotes.session_cache
  57. from build.project import get_version
  58. import json
  59. bootdict = webnotes.session_cache.get()
  60. bootinfo = """var wn = {}; wn.boot = %s;""" % json.dumps(bootdict)
  61. if webnotes.session['user'] == 'Guest':
  62. script_tag = '<script type="text/javascript" src="js/all-web.js"></script>'
  63. style_tag = '<link type="text/css" rel="stylesheet" href="css/all-web.css">'
  64. else:
  65. script_tag = '<script type="text/javascript" src="js/all-app.js"></script>'
  66. style_tag = '<link type="text/css" rel="stylesheet" href="css/all-app.css">'
  67. return template.render(bootinfo = bootinfo, version = get_version(),
  68. script_tag = script_tag, style_tag = style_tag, body_html=body_html % '',
  69. ajax_meta_tag = '<meta name="fragment" content="!">',
  70. analytics_code = bootdict.get('analytics_code', '') or '')
  71. def html_snapshot(page):
  72. """get html snapshot for search bot"""
  73. from webnotes.widgets.page import get_page_html
  74. from webnotes.model.doc import Document
  75. doc = Document('Website Settings', 'Website Settings')
  76. doc.content = get_page_html(page)
  77. doc.header_menu = doc.footer_menu = ''
  78. doc.page_name = page
  79. for m in webnotes.conn.sql("""select parentfield, label, url, custom_page
  80. from `tabTop Bar Item` where parent='Top Bar Settings' order by idx""", as_dict=1):
  81. m['std_page'] = m.get('url') or m.get('custom_page')
  82. if m['parentfield']=='top_bar_items':
  83. doc.header_menu += '<li><a href="index.cgi#!%(std_page)s">%(label)s</a></li>' % m
  84. else:
  85. doc.footer_menu += '<li><a href="index.cgi#!%(std_page)s">%(label)s</a></li>' % m
  86. return """
  87. <header>
  88. <h3>%(brand_html)s</h3>
  89. <ul>
  90. %(header_menu)s
  91. </ul>
  92. </header>
  93. %(content)s
  94. <footer>
  95. <ul>
  96. %(footer_menu)s
  97. </ul>
  98. <div>Address: %(address)s</div>
  99. <div>&copy; %(copyright)s</div>
  100. <div>Powered by <a href="https://erpnext.com">erpnext.com</a></div>
  101. <div style="background-color: #ffc; padding: 7px">
  102. This page is for search engines, for standard browsers click
  103. <a href="index.cgi#!%(page_name)s">here</a>
  104. </div>
  105. </footer>
  106. """ % doc.fields