Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

133 rindas
4.2 KiB

  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. <div id="startup_div" style="padding: 8px;
  33. font-size: 12px; font-family: Arial !important; line-height: 1.6em;">
  34. Loading...
  35. </div>
  36. <!-- Main Starts -->
  37. <div id="body_div">
  38. </div>
  39. <footer></footer>
  40. <div class="no_script" style="display: none;">
  41. %s
  42. </div>
  43. <div id="dialog_back"></div>
  44. """
  45. def get():
  46. """get index html"""
  47. import webnotes
  48. from jinja2 import Template
  49. with open('lib/conf/index.html', 'r') as f:
  50. template = Template(f.read())
  51. # google crawler
  52. if '_escaped_fragment_' in webnotes.form:
  53. page = webnotes.form_dict['_escaped_fragment_']
  54. if not page:
  55. page = webnotes.user.get_home_page()
  56. return template.render(bootinfo = '', style_tag='', version='0', analytics_code = '',\
  57. script_tag = '', body_html=html_snapshot(page), ajax_meta_tag = '')
  58. # home page
  59. else:
  60. import webnotes.session_cache
  61. from build.project import get_version
  62. import json
  63. bootdict = webnotes.session_cache.get()
  64. bootinfo = """var wn = {}; wn.boot = %s;""" % json.dumps(bootdict)
  65. if webnotes.session['user'] == 'Guest':
  66. script_tag = '<script type="text/javascript" src="js/all-web.js"></script>'
  67. style_tag = '<link type="text/css" rel="stylesheet" href="css/all-web.css">'
  68. else:
  69. script_tag = '<script type="text/javascript" src="js/all-app.js"></script>'
  70. style_tag = '<link type="text/css" rel="stylesheet" href="css/all-app.css">'
  71. return template.render(bootinfo = bootinfo, version = get_version(),
  72. script_tag = script_tag, style_tag = style_tag, body_html=body_html % '',
  73. ajax_meta_tag = '<meta name="fragment" content="!">',
  74. analytics_code = bootdict.get('analytics_code', '') or '')
  75. def html_snapshot(page):
  76. """get html snapshot for search bot"""
  77. from webnotes.widgets.page import get_page_html
  78. from webnotes.model.doc import Document
  79. doc = Document('Website Settings', 'Website Settings')
  80. doc.content = get_page_html(page)
  81. doc.header_menu = doc.footer_menu = ''
  82. doc.page_name = page
  83. for m in webnotes.conn.sql("""select parentfield, label, url, custom_page
  84. from `tabTop Bar Item` where parent='Top Bar Settings' order by idx""", as_dict=1):
  85. m['std_page'] = m.get('url') or m.get('custom_page')
  86. if m['parentfield']=='top_bar_items':
  87. doc.header_menu += '<li><a href="index.cgi#!%(std_page)s">%(label)s</a></li>' % m
  88. else:
  89. doc.footer_menu += '<li><a href="index.cgi#!%(std_page)s">%(label)s</a></li>' % m
  90. return """
  91. <header>
  92. <h3>%(brand_html)s</h3>
  93. <ul>
  94. %(header_menu)s
  95. </ul>
  96. </header>
  97. %(content)s
  98. <footer>
  99. <ul>
  100. %(footer_menu)s
  101. </ul>
  102. <div>Address: %(address)s</div>
  103. <div>&copy; %(copyright)s</div>
  104. <div>Powered by <a href="https://erpnext.com">erpnext.com</a></div>
  105. <div style="background-color: #ffc; padding: 7px">
  106. This page is for search engines, for standard browsers click
  107. <a href="index.cgi#!%(page_name)s">here</a>
  108. </div>
  109. </footer>
  110. """ % doc.fields