def connect_to_db(config): if request.env.web2py_runtime_gae: from gluon.contrib.gae_memcache import MemcacheClient from gluon.contrib.memdb import MEMDB cache.memcache = MemcacheClient(request) cache.ram = cache.disk = cache.memcache db = DAL('gae') session.connect(request, response, MEMDB(cache.memcache)) else: db = DAL(config.connect_uri) return db
db_type = db_string.split(":", 1)[0] db_location = db_string.split("@", 1)[1] raise (HTTP( 503, "Cannot connect to %s Database: %s" % (db_type, db_location))) current.db = db db.set_folder("upload") # Sessions Storage if settings.get_base_session_memcache(): # Store sessions in Memcache from gluon.contrib.memcache import MemcacheClient cache.memcache = MemcacheClient(request, [settings.get_base_session_memcache()]) from gluon.contrib.memdb import MEMDB session.connect(request, response, db=MEMDB(cache.memcache)) #################################################################### # Instantiate Classes from Modules # # - store instances in current to be accessible from other modules # #################################################################### from gluon.tools import Mail mail = Mail() current.mail = mail from gluon.storage import Messages messages = Messages(T) current.messages = messages # Import the S3 Framework
## if NOT running on Google App Engine use SQLite or other DB db = DAL('sqlite://storage.sqlite') # db = DAL('sqlite://storage.sqlite',lazy_tables=True) to be tested else: ## connect to Google BigTable (optional 'google:datastore://namespace') db = DAL('google:datastore+ndb', lazy_tables=True) # lets try new one below #db = DAL('google:datastore', lazy_tables=True) # lets try new one below #db = DAL('google:datastore+ndb') ## store sessions and tickets there #session.connect(request, response, db=db) # session.connect(request, response, db=db) ## or store session in Memcache, Redis, etc. from gluon.contrib.memdb import MEMDB from google.appengine.api.memcache import Client session.connect(request, response, db=MEMDB(Client())) ## by default give a view/generic.extension to all actions from localhost ## none otherwise. a pattern can be 'controller/function.extension' #response.generic_patterns = ['*'] if request.is_local else [] response.generic_patterns = ['*'] response.formstyle = 'bootstrap3_inline' # or 'bootstrap3_stacked' #response.formstyle = 'bootstrap3_stacked' ## (optional) optimize handling of static files # response.optimize_css = 'concat,minify,inline' # response.optimize_js = 'concat,minify,inline' import os from gluon.tools import Auth, Crud, Service, PluginManager, prettydate, Mail auth = Auth(db, hmac_key=Auth.get_or_create_key())