spyre icon indicating copy to clipboard operation
spyre copied to clipboard

AppBar

Open LuisSoares opened this issue 9 years ago • 4 comments

I recently run in to trouble setting a site instance (not a single app) in pythonanywhere, basically the problem is that in pythonanywhere they take care of the wsgi stuff so to deploy the site you have to deploy individually each app, the problem comes with the implementation of the site class which only serves the entire root with the launch method. This led to problems since the appbar is only added to all the apps within the launch method. I was wondering if I could make a pull request changing the setting of the appbar in each app from the launch method to the addApp method of the Site class.

LuisSoares avatar Oct 28 '15 11:10 LuisSoares

@LuisSoares can you provide the code for your app?

Also, have you looked at this issue: https://github.com/adamhajari/spyre/issues/10 and this example: https://github.com/adamhajari/spyre/blob/master/examples/multi_app_example.py ?

adamhajari avatar Apr 02 '16 19:04 adamhajari

Hi @adamhajari,

First of all congratulation for you work with spyre. The code for my app is:

#stuff required by pythonanywhere
import sys
import atexit
import threading
import cherrypy

cherrypy.config.update({'environment': 'embedded'})

if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
    cherrypy.engine.start(blocking=False)
    atexit.register(cherrypy.engine.stop)

sys.path.append('/home/lint78/web_site')

#spyre stuff
from spyre import server
from index import Index
from pairwise_up import pairwise
from simple_spyre import SimpleApp
from references import References
from geneplotter2 import GenePlotter2
from anchor_plot import AnchorPlot

#more pythonanywhere required stuff
cherrypy.config.update({'engine.autoreload.on': False})
cherrypy.server.unsubscribe()
cherrypy.engine.start()


#create site
site = server.Site(Index)

#add banner to site
site.root.templateVars['custom_head'] ='''Buratowski Lab Yeast H3K4 methylation studies'''

#add app bar to site root
site.root.templateVars['app_bar']=[('/','Index'),('/app2','GenePlotter'),('/app5','GenePlotter2'),('/app3','Comparisons'),('/app6','Anchor Plot'),('/app4','References')]

#add apps to app bar
site.addApp(SimpleApp, '/app2')
site.addApp(pairwise, '/app3')
site.addApp(References, '/app4')
site.addApp(GenePlotter2, '/app5')
site.addApp(AnchorPlot,'/app6')

#add app bar to every app otherwise it is only shown at the root
for fullRoute, _ in site.site_app_bar[1:]:
    parent, route = site.get_route(fullRoute)
    parent.__dict__[route].templateVars['app_bar']=[('/','Index'),('/app2','GenePlotter'),('/app5','GenePlotter2'),('/app3','Comparisons'),('/app6','Anchor Plot'),('/app4','References')]
    parent.__dict__[route].templateVars['custom_head'] ='''Buratowski Lab Yeast H3K4 methylation studies

#create a application function wrapper required by pythonanywhere
application=cherrypy.Application(site.getRoot())

As i said in the first comment, I do need to add the app_bar to every single app otherwise in only shows up in the root (first page). Maybe I am doing something wrong, but I think the problem lies on the fact that for pythonanywhere you can't call the site launch method yourself but have to provide the site.root as cherrypy,Application argument. Since the launch method of site is not called the app bar is not added by default to all apps , just the root one.

LuisSoares avatar Apr 03 '16 01:04 LuisSoares

@huntcsg do you have any insight into this issue?

adamhajari avatar Apr 03 '16 19:04 adamhajari

I think this could probably be fixed by moving the:

self.root.templateVars['app_bar'] = self.site_app_bar for fullRoute, _ in self.site_app_bar[1:]: parent, route = self.get_route(fullRoute) parent.dict[route].templateVars['app_bar']= self.site_app_bar

from the launch method to the getRoot method in the Site class

LuisSoares avatar Apr 03 '16 19:04 LuisSoares