def get(self): # get the organisms, maps, and models response = yield gen.Task(AsyncHTTPClient().fetch, get_url('server_index', protocol='http')) if response.code == 200 and response.body is not None: server_index_json = response.body.decode('utf-8') else: server_index_json = None # get the cached maps and models index = local_index() # render the template template = env.get_template('homepage.html') data = template.render( d3=get_url('d3', 'local'), boot_css=get_url('boot_css', 'local'), homepage_css=get_url('homepage_css', 'local'), favicon=get_url('favicon', 'local'), logo=get_url('logo', 'local'), documentation=get_url('documentation', protocol='https'), github=get_url('github'), github_releases=get_url('github_releases'), homepage_js=get_url('homepage_js', 'local'), map_download_url=get_url('map_download', 'local'), server_index_json=escape_json_or_null(server_index_json), local_index_json=json_dump_and_escape(index), version=__version__, web_version=False) self.set_header("Content-Type", "text/html") self.serve(data)
def get(self): # get the organisms, maps, and models response = yield gen.Task(AsyncHTTPClient().fetch, get_url('server_index', protocol='http')) if response.code == 200 and response.body is not None: server_index_json = response.body.decode('utf-8') else: server_index_json = None # get the cached maps and models index = local_index() # render the template template = env.get_template('homepage.html') data = template.render(d3=get_url('d3', 'local'), boot_css=get_url('boot_css', 'local'), homepage_css=get_url('homepage_css', 'local'), favicon=get_url('favicon', 'local'), logo=get_url('logo', 'local'), documentation=get_url('documentation', protocol='https'), github=get_url('github'), github_releases=get_url('github_releases'), homepage_js=get_url('homepage_js', 'local'), map_download_url=get_url('map_download', 'local'), server_index_json=escape_json_or_null(server_index_json), local_index_json=json_dump_and_escape(index), version=__version__, web_version=False) self.set_header("Content-Type", "text/html") self.serve(data)
def _get_html(self, js_source='web', menu='none', scroll_behavior='pan', html_wrapper=False, enable_editing=False, enable_keys=False, minified_js=True, fill_screen=False, height='800px', never_ask_before_quit=False, static_site_index_json=None, protocol=None, ignore_bootstrap=False): """Generate the Escher HTML. Arguments -------- js_source: Can be one of the following: 'web' - (Default) use js files from escher.github.io. 'local' - use compiled js files in the local escher installation. Works offline. 'dev' - use the local, uncompiled development files. Works offline. menu: Menu bar options include: 'none' - (Default) No menu or buttons. 'zoom' - Just zoom buttons (does not require bootstrap). 'all' - Menu and button bar (requires bootstrap). scroll_behavior: Scroll behavior options: 'pan' - (Default) Pan the map. 'zoom' - Zoom the map. 'none' - No scroll events. minified_js: If True, use the minified version of JavaScript and CSS files. html_wrapper: If True, return a standalone html file. enable_editing: Enable the editing modes (build, rotate, etc.). enable_keys: Enable keyboard shortcuts. height: The height of the HTML container. never_ask_before_quit: Never display an alert asking if you want to leave the page. By default, this message is displayed if enable_editing is True. static_site_index_json: The index, as a JSON string, for the static site. Use javascript to parse the URL options. Used for generating static pages (see static_site.py). protocol: The protocol can be 'http', 'https', or None which indicates a 'protocol relative URL', as in //escher.github.io. Ignored if source is local. ignore_bootstrap: Do not use Bootstrap for buttons, even if it available. This is used to embed Escher in a Jupyter notebook where it conflicts with the Jupyter Boostrap installation. """ if js_source not in ['web', 'local', 'dev']: raise Exception('Bad value for js_source: %s' % js_source) if menu not in ['none', 'zoom', 'all']: raise Exception('Bad value for menu: %s' % menu) if scroll_behavior not in ['pan', 'zoom', 'none']: raise Exception('Bad value for scroll_behavior: %s' % scroll_behavior) content = env.get_template('content.html') # if height is not a string if type(height) is int: height = "%dpx" % height elif type(height) is float: height = "%fpx" % height elif type(height) is str: height = str(height) # set the proper urls url_source = 'local' if (js_source=='local' or js_source=='dev') else 'web' local_host = self.local_host # get the urls d3_url = get_url('d3', url_source, local_host, protocol) escher_url = get_url(('escher_min' if minified_js else 'escher'), url_source, local_host, protocol) if menu == 'all' and not ignore_bootstrap: jquery_url = get_url('jquery', url_source, local_host, protocol) boot_css_url = get_url('boot_css', url_source, local_host, protocol) boot_js_url = get_url('boot_js', url_source, local_host, protocol) else: jquery_url = boot_css_url = boot_js_url = None escher_css_url = get_url(('builder_css_min' if minified_js else 'builder_css'), url_source, local_host, protocol) favicon_url = get_url('favicon', url_source, local_host, protocol) # for static site map_download_url = get_url('map_download', url_source, local_host, protocol) model_download_url = get_url('model_download', url_source, local_host, protocol) # local host lh_string = ('' if local_host is None else local_host.rstrip('/') + '/') # options options = { 'menu': menu, 'enable_keys': enable_keys, 'enable_editing': enable_editing, 'scroll_behavior': scroll_behavior, 'fill_screen': fill_screen, 'ignore_bootstrap': ignore_bootstrap, 'never_ask_before_quit': never_ask_before_quit, 'reaction_data': self.reaction_data, 'metabolite_data': self.metabolite_data, 'gene_data': self.gene_data, } # Add the specified options for option in self.options: val = getattr(self, option) if val is None: continue options[option] = val html = content.render( # standalone title='Escher ' + ('Builder' if enable_editing else 'Viewer'), jquery_url=jquery_url, boot_js_url=boot_js_url, boot_css_url=boot_css_url, escher_css_url=escher_css_url, favicon_url=favicon_url, # content wrapper=html_wrapper, height=height, id=self.the_id, d3_url=d3_url, escher_url=escher_url, # dump json id_json=json_dump_and_escape(self.the_id), options_json=json_dump_and_escape(options), map_download_url_json=json_dump_and_escape(map_download_url), model_download_url_json=json_dump_and_escape(model_download_url), builder_embed_css_json=json_dump_and_escape(self.embedded_css), # alreay json map_data_json=escape_json_or_null(self.loaded_map_json), model_data_json=escape_json_or_null(self.loaded_model_json), static_site_index_json=escape_json_or_null(static_site_index_json), ) return html
def _get_html(self, js_source='web', menu='none', scroll_behavior='pan', html_wrapper=False, enable_editing=False, enable_keys=False, minified_js=True, fill_screen=False, height='800px', never_ask_before_quit=False, static_site_index_json=None, protocol=None, ignore_bootstrap=False): """Generate the Escher HTML. Arguments -------- js_source: Can be one of the following: 'web' - (Default) use js files from unpkg. 'local' - Use compiled js files in the local escher installation. Works offline. 'dev' - No longer necessary with source maps. This now gives the same behavior as 'local'. menu: Menu bar options include: 'none' - (Default) No menu or buttons. 'zoom' - Just zoom buttons (does not require bootstrap). 'all' - Menu and button bar (requires bootstrap). scroll_behavior: Scroll behavior options: 'pan' - (Default) Pan the map. 'zoom' - Zoom the map. 'none' - No scroll events. minified_js: If True, use the minified version of JavaScript files. html_wrapper: If True, return a standalone html file. enable_editing: Enable the editing modes (build, rotate, etc.). enable_keys: Enable keyboard shortcuts. height: The height of the HTML container. never_ask_before_quit: Never display an alert asking if you want to leave the page. By default, this message is displayed if enable_editing is True. static_site_index_json: The index, as a JSON string, for the static site. Use javascript to parse the URL options. Used for generating static pages (see static_site.py). protocol: The protocol can be 'http', 'https', or None which indicates a 'protocol relative URL', as in //escher.github.io. Ignored if source is local. ignore_bootstrap: Deprecated """ if js_source not in ['web', 'local', 'dev']: raise Exception('Bad value for js_source: %s' % js_source) if menu not in ['none', 'zoom', 'all']: raise Exception('Bad value for menu: %s' % menu) if scroll_behavior not in ['pan', 'zoom', 'none']: raise Exception('Bad value for scroll_behavior: %s' % scroll_behavior) content = env.get_template('content.html') # if height is not a string if type(height) is int: height = "%dpx" % height elif type(height) is float: height = "%fpx" % height elif type(height) is str: height = str(height) # set the proper urls url_source = 'local' if (js_source == 'local' or js_source == 'dev') else 'web' local_host = self.local_host # get the urls escher_url = get_url(('escher_min' if minified_js else 'escher'), url_source, local_host, protocol) favicon_url = get_url('favicon', url_source, local_host, protocol) # for static site map_download_url = get_url('map_download', url_source, local_host, protocol) model_download_url = get_url('model_download', url_source, local_host, protocol) # local host lh_string = ('' if local_host is None else local_host.rstrip('/') + '/') # options options = { 'menu': menu, 'enable_keys': enable_keys, 'enable_editing': enable_editing, 'scroll_behavior': scroll_behavior, 'fill_screen': fill_screen, 'never_ask_before_quit': never_ask_before_quit, 'reaction_data': self.reaction_data, 'metabolite_data': self.metabolite_data, 'gene_data': self.gene_data, } # Add the specified options for option in self.options: val = getattr(self, option) if val is None: continue options[option] = val html = content.render( # standalone title='Escher ' + ('Builder' if enable_editing else 'Viewer'), favicon_url=favicon_url, # content wrapper=html_wrapper, height=height, id=self.the_id, escher_url=escher_url, # dump json id_json=json_dump_and_escape(self.the_id), options_json=json_dump_and_escape(options), map_download_url_json=json_dump_and_escape(map_download_url), model_download_url_json=json_dump_and_escape(model_download_url), builder_embed_css_json=json_dump_and_escape(self.embedded_css), # alreay json map_data_json=escape_json_or_null(self.loaded_map_json), model_data_json=escape_json_or_null(self.loaded_model_json), static_site_index_json=escape_json_or_null(static_site_index_json), ) return html