当前位置: 首页>>代码示例>>Python>>正文


Python AppConfig.model方法代码示例

本文整理汇总了Python中tg.configuration.AppConfig.model方法的典型用法代码示例。如果您正苦于以下问题:Python AppConfig.model方法的具体用法?Python AppConfig.model怎么用?Python AppConfig.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tg.configuration.AppConfig的用法示例。


在下文中一共展示了AppConfig.model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sqlalchemy_retry

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_sqlalchemy_retry(self):
        fake_transaction = FakeTransaction()
        import transaction
        prev_transaction_manager = transaction.manager
        transaction.manager = fake_transaction

        from transaction.interfaces import TransientError

        class RootController(TGController):
            attempts = []

            @expose()
            def test(self):
                self.attempts.append(True)
                if len(self.attempts) == 3:
                    return 'HI!'
                raise TransientError()

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = package
        conf.model = package.model
        conf.use_sqlalchemy = True
        conf.use_transaction_manager = True
        conf['sqlalchemy.url'] = 'sqlite://'
        conf['tm.attempts'] = 3

        app = conf.make_wsgi_app()
        app = TestApp(app)

        resp = app.get('/test')
        assert 'HI' in resp

        transaction.manager = prev_transaction_manager
开发者ID:Shamefox,项目名称:tg2,代码行数:36,代码来源:test_configuration.py

示例2: test_sqla_auth_logging_stderr

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_sqla_auth_logging_stderr(self):
        past_config_sa_auth = config.sa_auth
        config.sa_auth = {}

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=None)
        conf.package = package
        conf.model = package.model
        conf.auth_backend = 'sqlalchemy'
        conf.use_sqlalchemy = True
        conf['sqlalchemy.url'] = 'sqlite://'

        alwaysadmin = _AuthenticationForgerPlugin(fake_user_key='FAKE_USER')
        conf['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(),
                           'cookie_secret':'12345',
                           'form_plugin':alwaysadmin,
                           'log_level':'DEBUG',
                           'authenticators':UncopiableList([('alwaysadmin', alwaysadmin)]),
                           'identifiers':[('alwaysadmin', alwaysadmin)],
                           'challengers':[]}

        conf['sa_auth']['log_file'] = 'stderr'
        app = conf.make_wsgi_app()
        conf['sa_auth']['log_file'] = 'stdout'
        app = conf.make_wsgi_app()

        import tempfile
        f = tempfile.NamedTemporaryFile()
        conf['sa_auth']['log_file'] = f.name
        app = conf.make_wsgi_app()

        self.config['sa_auth'] = {}
        self.config.auth_backend = None
        config.sa_auth = past_config_sa_auth
开发者ID:Shamefox,项目名称:tg2,代码行数:36,代码来源:test_configuration.py

示例3: test_setup_sqla_auth

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_setup_sqla_auth(self):
        if PY3: raise SkipTest()

        class RootController(TGController):
            @expose()
            def test(self):
                return str(request.environ)

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = package
        conf.model = package.model
        conf.auth_backend = 'sqlalchemy'
        conf.use_sqlalchemy = True
        conf['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(),
                           'dbsession': None,
                           'user_class': None,
                           'cookie_secret':'12345'}
        conf['sqlalchemy.url'] = 'sqlite://'
        app = conf.make_wsgi_app()
        app = TestApp(app)

        assert 'repoze.who.plugins' in app.get('/test')

        self.config.auth_backend = None
开发者ID:Shamefox,项目名称:tg2,代码行数:27,代码来源:test_configuration.py

示例4: test_sqlalchemy_doom

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_sqlalchemy_doom(self):
        fake_transaction = FakeTransaction()
        import transaction
        prev_transaction_manager = transaction.manager
        transaction.manager = fake_transaction

        class RootController(TGController):
            @expose()
            def test(self):
                fake_transaction.doom()
                return 'HI!'

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = package
        conf.model = package.model
        conf.use_sqlalchemy = True
        conf.use_transaction_manager = True
        conf['sqlalchemy.url'] = 'sqlite://'

        app = conf.make_wsgi_app()
        app = TestApp(app)

        app.get('/test')
        assert fake_transaction.aborted == True

        transaction.manager = prev_transaction_manager
开发者ID:Shamefox,项目名称:tg2,代码行数:29,代码来源:test_configuration.py

示例5: test_sqlalchemy_commit_veto

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_sqlalchemy_commit_veto(self):
        class RootController(TGController):
            @expose()
            def test(self):
                return 'HI!'

            @expose()
            def crash(self):
                raise Exception('crash')

            @expose()
            def forbidden(self):
                response.status = 403
                return 'FORBIDDEN'

            @expose()
            def notfound(self):
                response.status = 404
                return 'NOTFOUND'

        def custom_commit_veto(environ, status, headers):
            if status.startswith('404'):
                return True
            return False

        fake_transaction = FakeTransaction()
        import transaction
        prev_transaction_manager = transaction.manager
        transaction.manager = fake_transaction

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = package
        conf.model = package.model
        conf.use_sqlalchemy = True
        conf.use_transaction_manager = True
        conf['sqlalchemy.url'] = 'sqlite://'
        conf.commit_veto = custom_commit_veto

        app = conf.make_wsgi_app()
        app = TestApp(app)

        app.get('/test')
        assert fake_transaction.aborted == False

        try:
            app.get('/crash')
        except:
            pass
        assert fake_transaction.aborted == True

        app.get('/forbidden', status=403)
        assert fake_transaction.aborted == False

        app.get('/notfound', status=404)
        assert fake_transaction.aborted == True

        transaction.manager = prev_transaction_manager
开发者ID:Shamefox,项目名称:tg2,代码行数:60,代码来源:test_configuration.py

示例6: test_setup_ming_persistance_with_url_alone

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_setup_ming_persistance_with_url_alone(self):
        if PY3: raise SkipTest()

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=None)
        conf.package = package
        conf.model = package.model
        conf.use_ming = True
        conf['ming.url'] = 'mim://inmemdb'

        app = conf.make_wsgi_app()
        assert app is not None
开发者ID:Shamefox,项目名称:tg2,代码行数:14,代码来源:test_configuration.py

示例7: test_setup_ming_persistance_advanced_options

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_setup_ming_persistance_advanced_options(self):
        if PY3: raise SkipTest()

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=None)
        conf.package = package
        conf.model = package.model
        conf.use_ming = True
        conf['ming.url'] = 'mim://inmemdb'
        conf['ming.connection.read_preference'] = 'PRIMARY'

        app = conf.make_wsgi_app()
        assert app is not None
开发者ID:Shamefox,项目名称:tg2,代码行数:15,代码来源:test_configuration.py

示例8: test_setup_sqlalchemy

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_setup_sqlalchemy(self):
        class RootController(TGController):
            @expose()
            def test(self):
                return 'HI!'

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = package
        conf.model = package.model
        conf.use_sqlalchemy = True
        conf['sqlalchemy.url'] = 'sqlite://'
        app = conf.make_wsgi_app()
        app = TestApp(app)

        assert 'HI!' in app.get('/test')
        assert package.model.DBSession.DBSESSION_REMOVED
开发者ID:Shamefox,项目名称:tg2,代码行数:19,代码来源:test_configuration.py

示例9: test_sqla_auth_middleware_only_mine

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    def test_sqla_auth_middleware_only_mine(self):
        past_config_sa_auth = config.sa_auth
        config.sa_auth = {}

        class RootController(TGController):
            @expose()
            def test(self):
                return str(request.environ)

            @expose()
            def forbidden(self):
                response.status = "401"

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = package
        conf.model = package.model
        conf.auth_backend = 'sqlalchemy'
        conf.use_sqlalchemy = True
        conf['sqlalchemy.url'] = 'sqlite://'

        alwaysadmin = _AuthenticationForgerPlugin(fake_user_key='FAKE_USER')
        conf['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(),
                           'cookie_secret':'12345',
                           'form_plugin':alwaysadmin,
                           'authenticators':UncopiableList([('alwaysadmin', alwaysadmin)]),
                           'identifiers':[('alwaysadmin', alwaysadmin)],
                           'challengers':[]}

        app = conf.make_wsgi_app()

        authenticators = [x[0] for x in conf['sa_auth']['authenticators']]
        assert authenticators[0] == 'alwaysadmin'
        assert 'sqlauth' not in authenticators

        challengers = [x[1] for x in conf['sa_auth']['challengers']]
        assert alwaysadmin in challengers

        app = TestApp(app)
        assert 'repoze.who.identity' in app.get('/test', extra_environ={'FAKE_USER':'admin'})
        assert app.get('/forbidden', status=401)

        self.config['sa_auth'] = {}
        self.config.auth_backend = None
        config.sa_auth = past_config_sa_auth
开发者ID:Shamefox,项目名称:tg2,代码行数:47,代码来源:test_configuration.py

示例10: asbool

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
    
    from paste.deploy.converters import asbool
    setting = asbool(global_conf.get('the_setting'))
 
"""

from tg.configuration import AppConfig

import outages
from outages import model
from outages.lib import app_globals, helpers 

base_config = AppConfig()
base_config.renderers = []

base_config.package = outages

#Enable json in expose
base_config.renderers.append('json')
#Set the default renderer
base_config.default_renderer = 'mako'
base_config.renderers.append('mako')
#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = outages.model
base_config.DBSession = outages.model.DBSession


base_config.use_toscawidgets = False
base_config.use_toscawidgets2 = True
开发者ID:gregjurman,项目名称:outages-moksha,代码行数:32,代码来源:app_cfg.py

示例11:

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
base_config.package = saip

#Enable json in expose
base_config.renderers.append('json')
#Set the default renderer
base_config.default_renderer = 'genshi'
base_config.renderers.append('genshi')
# if you want raw speed and have installed chameleon.genshi
# you should try to use this renderer instead.
# warning: for the moment chameleon does not handle i18n translations
#base_config.renderers.append('chameleon_genshi')

#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = saip.model
base_config.DBSession = saip.model.DBSession

# Configure the authentication backend

# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP 
base_config.sa_auth.cookie_secret = "ChangeME" 

base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth.dbsession = model.DBSession
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.Usuario
# what is the class you want to use to search for groups in the database
base_config.sa_auth.group_class = model.Rol
# what is the class you want to use to search for permissions in the database
base_config.sa_auth.permission_class = model.Permiso
开发者ID:rparrapy,项目名称:SAIP,代码行数:32,代码来源:app_cfg.py

示例12:

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
base_config.renderers = []

base_config.package = spam

# Set the default renderer
base_config.default_renderer = "mako"
base_config.renderers.append("mako")
base_config.renderers.append("json")
# if you want raw speed and have installed chameleon.genshi
# you should try to use this renderer instead.
# warning: for the moment chameleon does not handle i18n translations
# base_config.renderers.append('chameleon_genshi')

# Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = spam.model
base_config.DBSession = spam.model.DBSession


# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP
base_config.sa_auth.cookie_secret = "ChangeME"

# Configure the authentication backend
base_config.auth_backend = "sqlalchemy"
base_config.sa_auth.dbsession = model.DBSession
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.User
# what is the class you want to use to search for groups in the database
base_config.sa_auth.group_class = model.Group
# what is the class you want to use to search for permissions in the database
base_config.sa_auth.permission_class = model.Permission
开发者ID:MrPetru,项目名称:spam,代码行数:33,代码来源:app_cfg.py

示例13:

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
base_config.renderers = []

base_config.package = mc27

#Enable json in expose
base_config.renderers.append('json')
#Set the default renderer
base_config.default_renderer = 'genshi'
base_config.renderers.append('genshi')
# if you want raw speed and have installed chameleon.genshi
# you should try to use this renderer instead.
# warning: for the moment chameleon does not handle i18n translations
#base_config.renderers.append('chameleon_genshi')
#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = mc27.model
base_config.DBSession = mc27.model.DBSession
# Configure the authentication backend

# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP 
base_config.sa_auth.cookie_secret = "ChangeME" 

base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth.dbsession = model.DBSession

# what is the class you want to use to search for users in the database
#base_config.sa_auth.user_class = model.User
base_config.sa_auth.user_class = model.MCUser
# what is the class you want to use to search for groups in the database
#base_config.sa_auth.group_class = model.Group
base_config.sa_auth.group_class = model.MCGroup
开发者ID:kamroot,项目名称:mc27,代码行数:33,代码来源:app_cfg.py

示例14: AppConfig

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
from narcissus import model
from narcissus.lib import app_globals, helpers 

base_config = AppConfig()
base_config.renderers = []

base_config.package = narcissus

#Enable json in expose
base_config.renderers.append('json')
#Set the default renderer
base_config.default_renderer = 'mako'
base_config.renderers.append('mako')
#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = narcissus.model
base_config.DBSession = narcissus.model.DBSession
# Configure the authentication backend

# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP 
base_config.sa_auth.cookie_secret = "ChangeME" 

base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth.dbsession = model.DBSession
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.User
# what is the class you want to use to search for groups in the database
base_config.sa_auth.group_class = model.Group
# what is the class you want to use to search for permissions in the database
base_config.sa_auth.permission_class = model.Permission
开发者ID:N6UDP,项目名称:narcissus,代码行数:32,代码来源:app_cfg.py

示例15: ApplicationAuthMetadata

# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import model [as 别名]
base_config.renderers.append('json')
# Enable genshi in expose to have a lingua franca
# for extensions and pluggable apps.
# You can remove this if you don't plan to use it.
base_config.renderers.append('genshi')

# Set the default renderer
base_config.default_renderer = 'mako'
base_config.renderers.append('mako')

# Configure Sessions, store data as JSON to avoid pickle security issues
base_config['session.enabled'] = True
base_config['session.data_serializer'] = 'json'
# Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = githandler.model
base_config.DBSession = githandler.model.DBSession
# Configure the authentication backend
base_config.auth_backend = 'sqlalchemy'
# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP
base_config.sa_auth.cookie_secret = "18cf2684-c4c8-4566-8caa-80cae73fcb27"
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.User

from tg.configuration.auth import TGAuthMetadata


# This tells to TurboGears how to retrieve the data for your user
class ApplicationAuthMetadata(TGAuthMetadata):
    def __init__(self, sa_auth):
        self.sa_auth = sa_auth
开发者ID:eteamin,项目名称:github-handler,代码行数:33,代码来源:app_cfg.py


注:本文中的tg.configuration.AppConfig.model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。