Пример #1
0
# -*- coding: utf-8 -*-

from web2pytest import web2pytest
import os

if not request.env.web2py_runtime_gae:
    ## if NOT running on Google App Engine use SQLite or other DB
    if web2pytest.is_running_under_test(request, request.application):
        # When running under test, db cannot be ':memory:'
        # because it is recreated in each request and a webclient test
        # can make many requests to validate a single scenario.
        db = DAL('sqlite://%s.sqlite' % request.application,
                 folder=os.path.dirname(
                     web2pytest.testfile_name(request.application)),
                 pool_size=1,
                 check_reserved=['all'])
    else:
        db = DAL('sqlite://storage.sqlite',
                 pool_size=1,
                 check_reserved=['all'])
else:
    ## connect to Google BigTable (optional 'google:datastore://namespace')
    db = DAL('google:datastore')
    ## 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
Пример #2
0
# if SSL/HTTPS is properly configured and you want all HTTP requests to
# be redirected to HTTPS, uncomment the line below:
# -------------------------------------------------------------------------
# request.requires_https()

if not request.env.web2py_runtime_gae:
    # ---------------------------------------------------------------------
    # if NOT running on Google App Engine use SQLite or other DB
    # ---------------------------------------------------------------------
    ## if NOT running on Google App Engine use SQLite or other DB
    if web2pytest.is_running_under_test(request, request.application):
        # When running under test, db cannot be ':memory:'
        # because it is recreated in each request and a webclient test
        # can make many requests to validate a single scenario.
        db = DAL('sqlite://%s.sqlite' % request.application,
                 folder=os.path.dirname(web2pytest.testfile_name()),
                 pool_size=1,
                 check_reserved=['all'],
                 lazy_tables=False)
    else:
        db = DAL(
            myconf.get('db.uri'),
            pool_size=myconf.get('db.pool_size'),
            migrate_enabled=myconf.get('db.migrate'),
            check_reserved=['all'],
            db_codec=myconf.get('db.db_codec'),
            bigint_id=myconf.get('db.bigint_id'),
            lazy_tables=myconf.get('db.lazy_tables'),
            fake_migrate_all=myconf.get('db.fake_migrate_all'),
        )
else:
Пример #3
0
# -*- coding: utf-8 -*-

## ------------------------------------------------------------
## DATABASE CREATION
##
## If application is running under automated tests, create
##    database in a memory disk.
## ------------------------------------------------------------

from web2pytest import web2pytest
import os

if web2pytest.is_running_under_test(request, request.application):
    request._running_under_test = True
    db = DAL('sqlite://%s.sqlite' % request.application,
            folder=os.path.dirname(web2pytest.testfile_name()),
            pool_size=1,
            check_reserved=['all'])
else:
    db = DAL('sqlite://storage.sqlite', pool_size=1, check_reserved=['all'])

current.db = db


## ------------------------------------------------------------
## AUTHENTICATION AND ROLE BASED AUTHORIZATION
## ------------------------------------------------------------

from gluon.tools import Auth
auth = Auth(db)