def configure_app(): app_cfg = AppConfig(minimal=True) app_cfg.renderers = ['genshi'] app_cfg.default_renderer = 'genshi' app_cfg.use_dotted_templatenames = True app_cfg.package = FakeAppPackage() app_cfg.use_toscawidgets2 = True app_cfg['tw2.enabled'] = True app_cfg.sa_auth.authmetadata = TestAuthMetadata() app_cfg['beaker.session.secret'] = 'SECRET' app_cfg.auth_backend = 'sqlalchemy' app_cfg.sa_auth.cookie_secret = 'SECRET' app_cfg.package.model = FakeSQLAModel() app_cfg.use_sqlalchemy = True app_cfg['sqlalchemy.url'] = 'sqlite://' app_cfg.use_transaction_manager = True app_cfg['tm.enabled'] = True app_cfg.model = app_cfg.package.model app_cfg.DBSession = app_cfg.package.model.DBSession plug(app_cfg, 'calendarevents', event_types=[FakeEventType()], global_models=False, plug_bootstrap=False, form_instance=calendar_form) # This is to reset @cached_properties so they get reconfigured for new backend return app_cfg
def setup(self): conf = AppConfig(minimal=True, root_controller=i18nRootController()) conf['paths']['root'] = 'tests' conf['i18n.enabled'] = True conf['session.enabled'] = True conf['i18n.lang'] = 'kr' conf['beaker.session.key'] = 'tg_test_session' conf['beaker.session.secret'] = 'this-is-some-secret' conf.renderers = ['json'] conf.default_renderer = 'json' conf.package = _FakePackage() app = conf.make_wsgi_app() self.app = TestApp(app)
def run(): global userconfig global httpd config = AppConfig(minimal=True, root_controller=RootController()) config['helpers'] = webhelpers2 config.renderers = ['kajiki'] config.serve_static = True config.paths['static_files'] = 'web/public' application = config.make_wsgi_app() print("Serving on port " + userconfig['Web']['porttoserve'] + "...") httpd = make_server('', int(userconfig['Web']['porttoserve']), application, 3) httpd.serve_forever()
def configure_app(using, create_form=True): # Simulate starting configuration process from scratch milestones._reset_all() app_cfg = AppConfig(minimal=True) app_cfg.renderers = ['kajiki'] app_cfg.default_renderer = 'kajiki' app_cfg.use_dotted_templatenames = True app_cfg.package = FakeAppPackage() app_cfg.use_toscawidgets2 = True app_cfg['tw2.enabled'] = True app_cfg.sa_auth.authmetadata = TestAuthMetadata() app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET' app_cfg['mail.debugmailer'] = 'dummy' if using == 'sqlalchemy': app_cfg.auth_backend = 'sqlalchemy' app_cfg.package.model = FakeSQLAModel() app_cfg.use_sqlalchemy = True app_cfg['sqlalchemy.url'] = 'sqlite://' app_cfg.use_transaction_manager = True app_cfg['tm.enabled'] = True elif using == 'ming': app_cfg.auth_backend = 'ming' app_cfg.package.model = FakeMingModel() app_cfg.use_ming = True app_cfg['ming.url'] = 'mim:///testresetpassword' else: raise ValueError('Unsupported backend') # Reset the Sprox provider on every change of configuration. from resetpassword import model as resetpassword_model resetpassword_model.provider._provider = None app_cfg.model = app_cfg.package.model app_cfg.DBSession = app_cfg.package.model.DBSession # CUSTOM resetpassword options app_cfg['resetpassword.email_sender'] = '*****@*****.**' plug(app_cfg, 'tgext.mailer', plug_bootstrap=True, debugmailer='dummy') plug( app_cfg, 'resetpassword', plug_bootstrap=False, reset_password_form_instance=resetpassword_form if create_form else None, new_password_form_instance=newpassword_form if create_form else None, ) return app_cfg
def run_api(): global userconfig try: port = userconfig['Web']['apiport'] except KeyError: port = '9380' global httpd config = AppConfig(minimal=True, root_controller=APIRootController()) config['helpers'] = webhelpers2 config.renderers = ['kajiki'] config.serve_static = False application = config.make_wsgi_app() print("Serving APIs on port " + port + "...") httpd = make_server('', int(port), application, 3) httpd.serve_forever()
def configure_app(using): # Simulate starting configuration process from scratch milestones._reset_all() app_cfg = AppConfig(minimal=True) app_cfg.renderers = ['kajiki'] app_cfg.default_renderer = 'kajiki' app_cfg.use_dotted_templatenames = True app_cfg.package = FakeAppPackage() app_cfg.use_toscawidgets2 = True app_cfg['tw2.enabled'] = True app_cfg.sa_auth.authmetadata = TestAuthMetadata() app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET' app_cfg.auth_backend = 'ming' app_cfg['mail.debugmailer'] = "dummy" if using == 'sqlalchemy': app_cfg.package.model = FakeSQLAModel() app_cfg.use_sqlalchemy = True app_cfg['sqlalchemy.url'] = 'sqlite://' app_cfg.use_transaction_manager = True app_cfg['tm.enabled'] = True app_cfg.SQLASession = app_cfg.package.model.DBSession elif using == 'ming': app_cfg.package.model = FakeMingModel() app_cfg.use_ming = True app_cfg['ming.url'] = 'mim:///mailtemapltes' app_cfg.MingSession = app_cfg.package.model.DBSession else: raise ValueError('Unsupported backend') app_cfg.model = app_cfg.package.model app_cfg.DBSession = app_cfg.package.model.DBSession # Guarantee that the same form is used between multiple # configurations of TGApps. Otherwise the validated # form would be different from the displayed one. plug(app_cfg, 'tgext.mailer', plug_bootstrap=True, debugmailer='dummy') plug(app_cfg, 'tgext.asyncjob', plug_bootstrap=True, app_globals=app_cfg['app_globals']) # it is important that tgext.mailer and tgext.asyncjob are plugged # before mailtemplates or not plugged at all as mailtemplates plugs them plug(app_cfg, 'mailtemplates', plug_bootstrap=True, default_language='EN') return app_cfg
def run(): global userconfig try: port = userconfig['Web']['porttoserve'] except AttributeError: port = '9375' global httpd config = AppConfig(minimal=True, root_controller=RootController()) config['helpers'] = webhelpers2 config.renderers = ['kajiki'] config.serve_static = True config.paths['static_files'] = 'web/public' application = config.make_wsgi_app() print("Serving on port " + port + "...") httpd = make_server('', int(port), application, 3) httpd.serve_forever()
def configure_app(using): # Simulate starting configuration process from scratch milestones._reset_all() app_cfg = AppConfig(minimal=True) app_cfg.renderers = ['kajiki'] app_cfg.default_renderer = 'kajiki' app_cfg.use_dotted_templatenames = True app_cfg.package = FakeAppPackage() app_cfg.use_toscawidgets2 = True app_cfg.sa_auth.authmetadata = TestAuthMetadata() app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET' app_cfg.auth_backend = 'ming' app_cfg['mail.debugmailer'] = 'dummy' if using == 'sqlalchemy': app_cfg.package.model = FakeSQLAModel() app_cfg.use_sqlalchemy = True app_cfg['sqlalchemy.url'] = 'sqlite://' app_cfg.use_transaction_manager = True elif using == 'ming': app_cfg.package.model = FakeMingModel() app_cfg.use_ming = True app_cfg['ming.url'] = 'mim:///testregistration' else: raise ValueError('Unsupported backend') app_cfg.model = app_cfg.package.model app_cfg.DBSession = app_cfg.package.model.DBSession # CUSTOM registration options app_cfg['registration.email_sender'] = '*****@*****.**' from registration.lib import send_email, get_form # Guarantee that the same form is used between multiple # configurations of TGApps. Otherwise the validated # form would be different from the displayed one. plug_args = {} if '_pluggable_registration_config' in config: plug_args['form_instance'] = get_form() plug(app_cfg, 'tgext.mailer', plug_bootstrap=True, debugmailer='dummy') plug(app_cfg, 'registration', plug_bootstrap=False, **plug_args) return app_cfg
def setUp(self): self.root_controller = self.controller_factory() conf = AppConfig(minimal=True, root_controller=self.root_controller) conf.package = FakePackage() conf.model = conf.package.model conf.use_dotted_templatenames = True conf.renderers = ['json', 'jinja', 'mako'] conf.default_renderer = 'jinja' conf.use_sqlalchemy = True conf.paths = {'controllers': 'tests', 'templates': ['tests']} conf.disable_request_extensions = False conf.prefer_toscawidgets2 = True conf.use_transaction_manager = True conf['sqlalchemy.url'] = 'sqlite:///:memory:' self.app = TestApp(conf.make_wsgi_app()) metadata.create_all()
def start_server(): """ start webserver """ catalog_engine = create_engine(SQLITE_DATA_TARGET) login_engine = create_engine(LOGIN_DATA_TARGET) config = AppConfig(minimal=True, root_controller=RootController(catalog_engine, login_engine)) config.sa_auth.charset = 'utf-8' config.renderers = ['kajiki'] config.default_renderer = 'kajiki' config.serve_static = True config.paths['static_files'] = 'public' config.paths['controllers'] = 'controllers' application = config.make_wsgi_app() print "Serving on port 8080..." httpd = make_server('', 8080, application) httpd.serve_forever()
def setUp(self): self.root_controller = self.controller_factory() conf = AppConfig(minimal=True, root_controller=self.root_controller) conf.package = FakePackage() conf.model = conf.package.model conf.use_dotted_templatenames = True conf.renderers = ['json', 'jinja', 'mako'] conf.default_renderer = 'jinja' conf.use_sqlalchemy = True conf.paths = {'controllers':'tests', 'templates':['tests']} conf.disable_request_extensions = False conf.prefer_toscawidgets2 = True conf.use_transaction_manager = True conf['sqlalchemy.url'] = 'sqlite:///:memory:' self.app = TestApp(conf.make_wsgi_app()) metadata.create_all()
def configure_app(using): # Simulate starting configuration process from scratch milestones._reset_all() app_cfg = AppConfig(minimal=True) app_cfg.renderers = ['kajiki'] app_cfg.default_renderer = 'kajiki' app_cfg.use_dotted_templatenames = True app_cfg.package = FakeAppPackage() app_cfg.use_toscawidgets2 = True app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET' app_cfg['mail.debugmailer'] = "dummy" if using == 'sqlalchemy': app_cfg.auth_backend = 'sqlalchemy' app_cfg.package.model = FakeSQLAModel() app_cfg.use_sqlalchemy = True app_cfg['sqlalchemy.url'] = 'sqlite://' app_cfg.use_transaction_manager = True app_cfg.SQLASession = app_cfg.package.model.DBSession elif using == 'ming': app_cfg.auth_backend = 'ming' app_cfg.package.model = FakeMingModel() app_cfg.use_ming = True app_cfg['ming.url'] = 'mim:///userprofile' app_cfg.MingSession = app_cfg.package.model.DBSession else: raise ValueError('Unsupported backend') app_cfg.model = app_cfg.package.model app_cfg.DBSession = app_cfg.package.model.DBSession app_cfg.sa_auth.authmetadata = TestAuthMetadata() # Guarantee that the same form is used between multiple # configurations of TGApps. Otherwise the validated # form would be different from the displayed one. app_cfg['userprofile.email_sender'] = '[email protected]' plug(app_cfg, 'userprofile', plug_bootstrap=True) return app_cfg
output += " <input type=\"file\" name=\"file1\"><br>" output += " <input type=\"submit\" value=\"Submit\">" output += " </form> " return output @expose() def conteiner(self, numero=None): DBSession.add(Conteiner(numero=numero or '')) DBSession.commit() return "OK" config = AppConfig(minimal=True, root_controller=RootController()) config.renderers = ['kajiki'] config.serve_static = True config.paths['static_files'] = 'img' config['use_sqlalchemy'] = True config['sqlalchemy.url'] = 'sqlite:///devdata.db' from tg.util import Bunch from sqlalchemy.orm import scoped_session, sessionmaker DBSession = scoped_session(sessionmaker(autoflush=True, autocommit=False)) def init_model(engine): DBSession.configure(bind=engine) DeclarativeBase.metadata.create_all( engine) # Create tables if they do not exist
from tg import expose, TGController, AppConfig class RootController(TGController): @expose() def index(self): return "<h1>Hello World</h1>" class RootController(TGController): @expose() def index(self): return 'Hello World' @expose('hello.jinja') def hello(self, person=None): return dict(person=person) config = AppConfig(minimal=True, root_controller=RootController()) config.renderers = ['jinja'] config.serve_static = True config.paths['static_files'] = 'public' import webhelpers2 import webhelpers2.text config['helpers'] = webhelpers2 application = config.make_wsgi_app() print "Serving on port 80..." httpd = make_server('', 80, application) httpd.serve_forever()
'clusters':clusters, 'cluster_counts':cluster_counts, 'degree_distribution':degree_distribution, 'degree':foaf_graph.degree(), 'top10':top10 } foaf_data = json.dumps(infos) data_file.write(foaf_data) return foaf_data @expose(content_type='application/json') def graph(self, **kw): with closing(open('graph_cache.json', 'w')) as graph_file: foaf_graph = retrieve_foaf(FBTOKEN) foaf_graph_json = jg.dumps(foaf_graph) graph_file.write(foaf_graph_json) return foaf_graph_json config = AppConfig(minimal=True, root_controller=RootController()) config.serve_static = True config.paths['static_files'] = './' config.renderers = ['jinja', 'json'] config.default_renderer = 'jinja' application = config.make_wsgi_app() print 'Serving on port 8080...' httpd = make_server('', 8080, application) httpd.serve_forever()
if total_power: pos = None if addr_cache.has_key(row['toponimo']): pos = addr_cache[row['toponimo']] filtered_data.append({ 'location': row['toponimo'].lower(), 'power': total_power / 1000, 'position': None }) return dict(data=filtered_data) @expose() def save_geocode(self, addr, lng, lat): addr_cache[addr.encode('utf-8')] = (lng, lat) addr_cache.sync() return 'OK' config = AppConfig(minimal=True, root_controller=RootController()) config.renderers = ['json'] print "Serving on port 8080..." httpd = make_server('', 8080, config.make_wsgi_app()) httpd.serve_forever()
def index(self): redirect("list/") @expose("list.jinja") def list(self): onlyfiles = [f for f in listdir("public/video") if isfile(join("public/video", f))] return dict(message="this is the list", files=onlyfiles) @expose("view.jinja") def view(self, vId=None): if vId is None: return dict(message="The video ID is invalid") return dict( message=vId, vid_url="/video/" + vId, data_obj=[{"serie": 0, "time": 0, "gamma": 1, "delta": 3, "theta": 1, "beta": 2, "alpha": 1}], ) # return dict(message=vId, vid_url="/video/"+vId, data_obj = [{"serie":0, "time":0, "gamma":1, "delta":3, "theta":1, "beta":2, "alpha":1}] ) config = AppConfig(minimal=True, root_controller=RootController()) config.renderers = ["jinja"] config.serve_static = True config.paths["static_files"] = "public" application = config.make_wsgi_app() print("Serving on port 8080...") httpd = make_server("", 8080, config.make_wsgi_app()) httpd.serve_forever()
@expose('json:', content_type='application/json') def timeline(self, **kw): f = open(TIMELINE_FILE) yield f.read() @expose('json:', content_type='application/json') def clusters(self, **kw): f = open(CLUSTERS_FILE) yield f.read() @expose('json:', content_type='application/json') def force(self, **kw): f = open(FORCE_FILE) yield f.read() config = AppConfig(minimal=True, root_controller=RootController()) #Only change since before is that we register the 'json' renderer #into our list of available renderers, so that we are able to #encode our responses as JSON config.renderers = ['json', 'jinja'] config.default_renderer = 'jinja' config.serve_static = True config['paths']['static_files'] = './' from wsgiref.simple_server import make_server print "Serving on port 8080..." httpd = make_server('', 8080, config.make_wsgi_app()) httpd.serve_forever()
total_power += int(row['POTENZA_da_116_a_350_KW']) * ((116+350)/2.0) if row['POTENZA_da_35_a_116_KW']: total_power += int(row['POTENZA_da_35_a_116_KW']) * ((35+116)/2.0) if row['POTENZA_uguale_350_KW_e_maggiore']: total_power += int(row['POTENZA_uguale_350_KW_e_maggiore']) * 350.0 if total_power: pos = None if addr_cache.has_key(row['toponimo']): pos = addr_cache[row['toponimo']] filtered_data.append({'location': row['toponimo'].lower(), 'power': total_power/1000, 'position': None}) return dict(data=filtered_data) @expose() def save_geocode(self, addr, lng, lat): addr_cache[addr.encode('utf-8')] = (lng, lat) addr_cache.sync() return 'OK' config = AppConfig(minimal=True, root_controller=RootController()) config.renderers = ['json'] print "Serving on port 8080..." httpd = make_server('', 8080, config.make_wsgi_app()) httpd.serve_forever()
# a graph with at least count entries (by default 40) data = [] for i in range(count): data.append(psutil.cpu_percent(interval=0.1)) # Here we encode our Python list as a Javascript # array of numbers, if you try to print the jsdata # you will see that is the Javascript code for an array. # This way we can use it from our javascript script jsdata = json.dumps(data) # If you expose a template, the controller is required # to return a dictionary with inside any data # that has to be available to the template return dict(data=jsdata, num=len(data)) config = AppConfig(minimal=True, root_controller=RootController()) # Major change from step 0 is that we register the Jinja # template engine so that we can render our index.html file config.renderers = ['jinja'] config.default_renderer = 'jinja' config.serve_static = True config['paths']['static_files'] = '.' from wsgiref.simple_server import make_server print "Serving on port 8080..." httpd = make_server('', 8080, config.make_wsgi_app()) httpd.serve_forever()
convert them into boolean, for example, you should use the :func:`paste.deploy.converters.asbool` function, as in:: from paste.deploy.converters import asbool setting = asbool(global_conf.get('the_setting')) """ from tg import AppConfig import trine from trine import model from trine.lib import helpers from trine.lib.app_globals import Globals base_config = AppConfig() base_config.renderers = [] # True to prevent dispatcher from striping extensions # For example /socket.io would be served by "socket_io" method instead of "socket" base_config.disable_request_extensions = False # Set None to disable escaping punctuation characters to "_" when dispatching methods. # Set to a function to provide custom escaping. base_config.dispatch_path_translator = True base_config.prefer_toscawidgets2 = True base_config.package = trine #Enable json in expose base_config.renderers.append('json') #Enable genshi in expose to have a lingua franca for extensions and pluggable apps