# store sessions and tickets there # --------------------------------------------------------------------- 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 and not configuration.get('app.production'): response.generic_patterns.append('*') # ------------------------------------------------------------------------- # choose a style for forms # ------------------------------------------------------------------------- response.formstyle = 'bootstrap4_inline' response.form_label_separator = '' # ------------------------------------------------------------------------- # (optional) optimize handling of static files # ------------------------------------------------------------------------- # response.optimize_css = 'concat,minify,inline' # response.optimize_js = 'concat,minify,inline' # -------------------------------------------------------------------------
# --------------------------------------------------------------------- # 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 [] # ------------------------------------------------------------------------- # choose a style for forms # ------------------------------------------------------------------------- response.formstyle = myconf.get( 'forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other response.form_label_separator = myconf.get('forms.separator') or '' # ------------------------------------------------------------------------- # (optional) optimize handling of static files # ------------------------------------------------------------------------- # response.optimize_css = 'concat,minify,inline' # response.optimize_js = 'concat,minify,inline' # ------------------------------------------------------------------------- # (optional) static assets folder versioning # ------------------------------------------------------------------------- # response.static_version = '0.0.0' # ------------------------------------------------------------------------- # Here is sample code if you need for
is_test_version = gae_version_id.endswith('test') is_local_version = gae_application_id.startswith('dev~') import logging if request.env.web2py_runtime_gae: logger = logging else: import sys FORMAT = "%(asctime)s %(levelname)s %(process)s %(thread)s %(funcName)s():%(lineno)d %(message)s" logging.basicConfig(stream=sys.stderr) logger = logging.getLogger(request.application) logger.setLevel(logging.INFO) if not request.env.web2py_runtime_gae: ## if NOT running on Google App Engine use SQLite or other DB db = DAL(myconf.get('db.uri'), pool_size=myconf.get('db.pool_size'), migrate_enabled=myconf.get('db.migrate'), check_reserved=['all']) gdb = DAL(myconf.get('gdb.uri'), pool_size=myconf.get('gdb.pool_size'), migrate_enabled=myconf.get('gdb.migrate'), check_reserved=['all']) else: if is_test_version or is_local_version: logger.info("Running locally") db = DAL('google:sql://true-review:true-review/true_review_test', migrate_enabled=True) ## connect to Google BigTable (optional 'google:datastore://namespace') gdb = DAL('google:datastore+ndb//test') else: db = DAL('google:sql://true-review:true-review/true_review_prod',
from gluon.contrib.appconfig import AppConfig from gluon.tools import Auth # ------------------------------------------------------------------------- # if SSL/HTTPS is properly configured and you want all HTTP requests to # be redirected to HTTPS, uncomment the line below: # ------------------------------------------------------------------------- # request.requires_https() config = AppConfig(reload=False) if not request.env.web2py_runtime_gae: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- db = DAL(config.get('db.uri'), pool_size=config.get('db.pool_size'), migrate_enabled=config.get('db.migrate'), check_reserved=['all']) else: # --------------------------------------------------------------------- # connect to Google BigTable (optional 'google:datastore://namespace') # --------------------------------------------------------------------- db = DAL('google:datastore+ndb') # --------------------------------------------------------------------- # store sessions and tickets there # --------------------------------------------------------------------- # session.connect(request, response, db=db) # --------------------------------------------------------------------- # or store session in Memcache, Redis, etc. from gluon.contrib.memdb import MEMDB
if request.global_settings.web2py_version < "2.14.1": raise HTTP(500, "Requires web2py 2.13.3 or newer") # if SSL/HTTPS is properly configured and you want all HTTP requests to # be redirected to HTTPS, uncomment the line below: # request.requires_https() # app configuration made easy. Look inside private/appconfig.ini from gluon.contrib.appconfig import AppConfig # once in production, remove reload=True to gain full speed myconf = AppConfig(reload=True) if not request.env.web2py_runtime_gae: # if NOT running on Google App Engine use SQLite or other DB db = DAL(myconf.get('db.uri'), pool_size=myconf.get('db.pool_size'), migrate_enabled=myconf.get('db.migrate'), check_reserved=['all']) # I like to keep the session in the db. session.connect(request, response, db=db) else: # connect to Google BigTable (optional 'google:datastore://namespace') db = DAL('google:datastore+ndb') # store sessions and tickets there 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()))
## This scaffolding model makes your app work on Google App Engine too ## File is released under public domain and you can use without limitations ######################################################################### ## if SSL/HTTPS is properly configured and you want all HTTP requests to ## be redirected to HTTPS, uncomment the line below: # request.requires_https() ## app configuration made easy. Look inside private/appconfig.ini from gluon.contrib.appconfig import AppConfig ## once in production, remove reload=True to gain full speed myconf = AppConfig(reload=True) if not request.env.web2py_runtime_gae: ## if NOT running on Google App Engine use SQLite or other DB db = DAL(myconf.get('db.uri'), pool_size = myconf.get('db.pool_size'), migrate_enabled = myconf.get('db.migrate'), check_reserved = ['all']) else: ## connect to Google BigTable (optional 'google:datastore://namespace') db = DAL('google:datastore+ndb') ## store sessions and tickets there 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'
# ------------------------------------------------------------------------- # app configuration made easy. Look inside private/appconfig.ini # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- MYCONF = AppConfig(reload=True) if not request.env.web2py_runtime_gae: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- DB = DAL( SETTINGS.db_url_login, pool_size=MYCONF.get('DB.pool_size'), # migrate_enabled=False, migrate=SETTINGS.migrate, lazy_tables=True, fake_migrate_all=SETTINGS.fake_migrate_all, check_reserved=['postgres', 'sqlite']) # DB = DAL(MYCONF.get('DB.uri'), # pool_size=MYCONF.get('DB.pool_size'), # migrate_enabled=False, # fake_migrate_all=True, # migrate_enabled=MYCONF.get('DB.migrate'), # check_reserved=['all']) # ------------------------------------------------------------------------- # by default give a view/generic.extension to all actions from localhost
# --------------------------------------------------------------------- # 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 [] # ------------------------------------------------------------------------- # choose a style for forms # ------------------------------------------------------------------------- response.formstyle = myconf.get('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other response.form_label_separator = myconf.get('forms.separator') or '' # ------------------------------------------------------------------------- # (optional) optimize handling of static files # ------------------------------------------------------------------------- # response.optimize_css = 'concat,minify,inline' # response.optimize_js = 'concat,minify,inline' # ------------------------------------------------------------------------- # (optional) static assets folder versioning # ------------------------------------------------------------------------- # response.static_version = '0.0.0' # ------------------------------------------------------------------------- # Here is sample code if you need for
from general_helpers import represent_validity_units from general_helpers import represent_subscription_units ### Config #### # ------------------------------------------------------------------------- # app configuration made easy. Look inside private/appconfig.ini # ------------------------------------------------------------------------- from gluon.contrib.appconfig import AppConfig # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- myconf = AppConfig() ### Caching ### if myconf.get('cache.cache') == 'redis': from gluon.contrib.redis_utils import RConn from gluon.contrib.redis_cache import RedisCache redis_host = str(myconf.get('cache.redis_host')) redis_port = str(myconf.get('cache.redis_port')) rconn = RConn(redis_host, redis_port) cache.redis = RedisCache(redis_conn=rconn, debug=True, with_lock=True) # use redis as cache cache.ram = cache.disk = cache.redis #### Custom validators begin ##### class IS_IBAN(object): def __init__(self, error_message=T('Invalid IBAN')):
folder='/home/www-data/waf2py_community/applications/Waf2Py/databases') db2 = DAL( 'sqlite://waf_logs.sqlite', folder='/home/www-data/waf2py_community/applications/Waf2Py/databases') # ------------------------------------------------------------------------- # app configuration made easy. Look inside private/appconfig.ini # ------------------------------------------------------------------------- from gluon.contrib.appconfig import AppConfig myconf = AppConfig(reload=False) # choose a style for forms # ------------------------------------------------------------------------- #response.formstyle = myconf.get('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other response.formstyle = 'bootstrap4_stacked' response.form_label_separator = myconf.get('forms.separator') or ': ' def widget(**kwargs): return lambda field, value, kwargs=kwargs: SQLFORM.widgets[ field.type].widget(field, value, **kwargs) db.define_table( 'examples', Field('conf_name', 'string', length=30, requires=IS_NOT_EMPTY()), Field('data_conf', 'text', requires=IS_NOT_EMPTY()), Field('description', 'text', requires=IS_NOT_EMPTY()), Field('autor', 'string', length=15, requires=IS_NOT_EMPTY()), )
# if SSL/HTTPS is properly configured and you want all HTTP requests to # be redirected to HTTPS, uncomment the line below: # ------------------------------------------------------------------------- # request.requires_https() # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- configuration = AppConfig(reload=True) if not request.env.web2py_runtime_gae: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- db = DAL( configuration.get("db.uri"), pool_size=configuration.get("db.pool_size"), migrate_enabled=configuration.get("db.migrate"), check_reserved=["all"], ) else: # --------------------------------------------------------------------- # connect to Google BigTable (optional 'google:datastore://namespace') # --------------------------------------------------------------------- db = DAL("google:datastore+ndb") # --------------------------------------------------------------------- # store sessions and tickets there # --------------------------------------------------------------------- session.connect(request, response, db=db) # --------------------------------------------------------------------- # or store session in Memcache, Redis, etc.
from gluon.custom_import import track_changes track_changes(DEBUG) # set utc as standard time for app request.now = request.utcnow if request.global_settings.web2py_version < "2.14.1": raise HTTP(500, "Requires web2py 2.14.1 or newer") # request.requires_https() # application configuration using private/appconfig.ini from gluon.contrib.appconfig import AppConfig myconf = AppConfig(reload=DEBUG) current.myconf = myconf myconf_env = myconf.get('environment.type') current.myconf_env = myconf_env # set db connection if not request.env.web2py_runtime_gae: # if NOT running on Google App Engine use SQLite or other DB db = DAL(myconf.get(myconf_env + 'db.uri'), pool_size=myconf.get(myconf_env + 'db.pool_size'), migrate_enabled=myconf.get(myconf_env + 'db.migrate'), check_reserved=['mysql', 'postgres'], # ['all']) lazy_tables=True) else: # connect to Google BigTable (optional 'google:datastore://namespace') db = DAL('google:datastore+ndb') # store sessions and tickets there session.connect(request, response, db=db)
# ------------------------------------------------------------------------- # once in production, comment out the following line # ------------------------------------------------------------------------- from gluon.custom_import import track_changes track_changes(True) # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- configuration = AppConfig() ### Caching ### if configuration.get('cache.cache') == 'redis': from gluon.contrib.redis_utils import RConn from gluon.contrib.redis_cache import RedisCache rconn = RConn() cache.redis = RedisCache(redis_conn=rconn, debug=True) # use redis as cache cache.ram = cache.disk = cache.redis #### Custom validators begin ##### class IS_IBAN(object): def __init__(self, error_message=T('Please enter a valid IBAN')): self.error_message = error_message
is_test_version = gae_version_id.endswith('test') is_local_version = gae_application_id.startswith('dev~') import logging if request.env.web2py_runtime_gae: logger = logging else: import sys FORMAT = "%(asctime)s %(levelname)s %(process)s %(thread)s %(funcName)s():%(lineno)d %(message)s" logging.basicConfig(stream=sys.stderr) logger = logging.getLogger(request.application) logger.setLevel(logging.INFO) if not request.env.web2py_runtime_gae: ## if NOT running on Google App Engine use SQLite or other DB db = DAL(myconf.get('db.uri'), pool_size=myconf.get('db.pool_size'), migrate_enabled=myconf.get('db.migrate'), check_reserved=['all']) gdb = DAL(myconf.get('gdb.uri'), pool_size=myconf.get('gdb.pool_size'), migrate_enabled=myconf.get('gdb.migrate'), check_reserved=['all']) else: if is_test_version or is_local_version: logger.info("Running locally") db = DAL('google:sql://true-review:true-review/true_review_test', migrate_enabled=True) ## connect to Google BigTable (optional 'google:datastore://namespace') gdb = DAL('google:datastore+ndb//test') else:
# ------------------------------------------------------------------------- # if SSL/HTTPS is properly configured and you want all HTTP requests to # be redirected to HTTPS, uncomment the line below: # ------------------------------------------------------------------------- # request.requires_https() # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- configuration = AppConfig(reload=True) if not request.env.web2py_runtime_gae: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- db = DAL(configuration.get('db.uri'), pool_size=configuration.get('db.pool_size'), migrate_enabled=configuration.get('db.migrate'), check_reserved=['all']) else: # --------------------------------------------------------------------- # connect to Google BigTable (optional 'google:datastore://namespace') # --------------------------------------------------------------------- db = DAL('google:datastore+ndb') # --------------------------------------------------------------------- # store sessions and tickets there # --------------------------------------------------------------------- session.connect(request, response, db=db) # --------------------------------------------------------------------- # or store session in Memcache, Redis, etc. # from gluon.contrib.memdb import MEMDB
from gluon.contrib.appconfig import AppConfig from gluon.tools import Auth if request.global_settings.web2py_version < "2.15.5": raise HTTP(500, "Requires web2py 2.15.5 or newer") configuration = AppConfig(reload=True) if not request.env.web2py_runtime_gae: db = DAL(configuration.get('db.uri'), pool_size=configuration.get('db.pool_size'), migrate_enabled=configuration.get('db.migrate'), check_reserved=['all']) else: db = DAL('google:datastore+ndb') session.connect(request, response, db=db) response.generic_patterns = [] if request.is_local and not configuration.get('app.production'): response.generic_patterns.append('*') response.formstyle = 'bootstrap4_inline' response.form_label_separator = '' auth = Auth(db, host_names=configuration.get('host.names')) auth.settings.extra_fields['auth_user'] = [] auth.define_tables(username=False, signature=False)
# ------------------------------------------------------------------------- # app configuration made easy. Look inside private/appconfig.ini # ------------------------------------------------------------------------- from gluon.contrib.appconfig import AppConfig # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- myconf = AppConfig(reload=True) if not request.env.web2py_runtime_gae: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- db = DAL( myconf.get("db.uri"), pool_size=myconf.get("db.pool_size"), migrate_enabled=myconf.get("db.migrate"), check_reserved=["all"], ) else: # --------------------------------------------------------------------- # connect to Google BigTable (optional 'google:datastore://namespace') # --------------------------------------------------------------------- db = DAL("google:datastore+ndb") # --------------------------------------------------------------------- # store sessions and tickets there # --------------------------------------------------------------------- session.connect(request, response, db=db) # --------------------------------------------------------------------- # or store session in Memcache, Redis, etc.
# ------------------------------------------------------------------------- # app configuration made easy. Look inside private/appconfig.ini # ------------------------------------------------------------------------- from gluon.contrib.appconfig import AppConfig # ------------------------------------------------------------------------- # once in production, remove reload=True to gain full speed # ------------------------------------------------------------------------- myconf = AppConfig(reload=True) if not request.env.web2py_runtime_gae: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- db = DAL(myconf.get('db.uri'), pool_size=myconf.get('db.pool_size'), migrate_enabled=myconf.get('db.migrate'), check_reserved=['all'], #fake_migrate_all=True ) else: # --------------------------------------------------------------------- # connect to Google BigTable (optional 'google:datastore://namespace') # --------------------------------------------------------------------- db = DAL('google:datastore+ndb') # --------------------------------------------------------------------- # store sessions and tickets there # --------------------------------------------------------------------- session.connect(request, response, db=db) # ---------------------------------------------------------------------
# connect to Google BigTable (optional 'google:datastore://namespace') # --------------------------------------------------------------------- db = DAL('google:datastore+ndb', lazy_tables=True) # --------------------------------------------------------------------- # store sessions and tickets in Memcache # --------------------------------------------------------------------- from gluon.contrib.gae_memcache import MemcacheClient from gluon.contrib.memdb import MEMDB cache.memcache = MemcacheClient(request) cache.ram = cache.disk = cache.memcache session.connect(request, response, db=MEMDB(cache.memcache.client)) else: # --------------------------------------------------------------------- # if NOT running on Google App Engine use SQLite or other DB # --------------------------------------------------------------------- db = DAL(appconfig.get('db.uri'), pool_size=appconfig.get('db.pool_site'), migrate_enabled=appconfig.get('db.migrate'), check_reserved=appconfig.get('db.migrate') and ['all'] or None, lazy_tables=appconfig.get('db.lazy')) # host names must be a list of allowed host names (glob syntax allowed) auth = Auth(db, host_names=appconfig.get('host.names')) # ------------------------------------------------------------------------- # create all tables needed by auth, maybe add a list of extra fields # ------------------------------------------------------------------------- # auth.settings.extra_fields['auth_user'] = [] auth.define_tables(username=False, signature=False)