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


Python Session.configure方法代码示例

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


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

示例1: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    from ..src import User, Address
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    BaseModel.metadata.create_all(engine)
    with transaction.manager:
        brendan = User(name='Brendan', age=18)
        Session.add(brendan)
        Session.flush()

        brendan_address = Address(city='Paris', owner_id=brendan.id)
        Session.add(brendan_address)
        Session.flush()

        john = User(name='John', age=19, best_friend_id=brendan.id)
        Session.add(john)
        Session.flush()

        antoine = User(name='Antoine', age=20)
        Session.add(antoine)
        Session.flush()
开发者ID:brendan-rius,项目名称:honeygen_pyramid,代码行数:29,代码来源:initializedb.py

示例2: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        model = User(name=u'admin', password=u'admin')
        DBSession.add(model)
        from jinja2.utils import generate_lorem_ipsum
        for id, article in enumerate(range(100), start=1):
            title = generate_lorem_ipsum(
                n=1,         # Одно предложение
                html=False,  # В виде обычного текста
                min=2,       # Минимум 2 слова
                max=5        # Максимум 5
            )
            content = generate_lorem_ipsum()
            article = Article(**{'title': title, 'content': content})
            DBSession.add(article)
开发者ID:IYism,项目名称:lectures.www,代码行数:28,代码来源:initializedb.py

示例3: sqlalchemy_teardown

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def sqlalchemy_teardown(context):
    transaction.abort()
    Session.remove()
    metadata.drop_all()
    Session.configure(bind=None)
    metadata.bind = None
    context.engine.dispose()
    context.sqlalchemy_patcher.stop()
开发者ID:haplo,项目名称:yith-library-server,代码行数:10,代码来源:testing.py

示例4: creator

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
 def creator():
     """ Create all registered models and connect to engine. """
     engine = create_engine('sqlite://')
     BaseObject.metadata.create_all(engine)
     connection = engine.connect()
     Session.registry.clear()
     Session.configure(bind=connection)
     BaseObject.metadata.bind = engine
     return connection
开发者ID:karthikmm,项目名称:nefertari-sqla,代码行数:11,代码来源:fixtures.py

示例5: includeme

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def includeme(config):
    """
    Initialize the model for a Pyramid app.

    Activate this setup using ``config.include('multitenant_rls.models')``.

    """
    settings = config.get_settings()
    engine = engine_from_config(settings)
    Session.configure(bind=engine)

    # use pyramid_tm to hook the transaction lifecycle to the request
    config.include('pyramid_tm')
开发者ID:marplatense,项目名称:multitenant_rls,代码行数:15,代码来源:__init__.py

示例6: setUp

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from .models import (
         Base,
         MyModel,
         )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
开发者ID:IYism,项目名称:lectures.www,代码行数:15,代码来源:tests.py

示例7: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    migrate(bootstrap(config_uri))
    logger.info('Drop and create tables')
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        preload_countries()
        preload_cities()
开发者ID:marplatense,项目名称:test_cliquet,代码行数:17,代码来源:initializedb.py

示例8: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) != 3:
        usage(argv)
    config_uri = argv[1]
    section = argv[2]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, section)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)

    with transaction.manager:
        id, secret = create_client()
        print('client_id:', id)
        print('client_secret:', secret)
开发者ID:marplatense,项目名称:pyramid_oauth2_provider,代码行数:18,代码来源:create_client_credentials.py

示例9: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    with transaction.manager:

        products = [Product(id=1, name='Capsule House'), Product(id=2, name='Electric Rice Cooker'),
                    Product(id=3, name='Electric Rice Cooker'), Product(id=4, name='Silverstar 4'),
                    Product(id=5, name='Hydrojet'), Product(id=6, name='Archeological Evacuation Robot'),
                    Product(id=7, name='Time machine'), Product(id=8, name='Boat'),
                    Product(id=14, name='Motorcycle'), Product(id=19, name='Small Pirate Submarine'),
                    Product(id=21, name='Mines'), Product(id=22, name='Battle Information Building'),
                    Product(id=23, name='Team Reception Building'), Product(id=29, name='Clothing Shop Building'),
                    Product(id=30, name='Accessory Shop Building'), Product(id=36, name='Powersuit'),
                    Product(id=39, name='Mix Shop Building'), Product(id=43, name='Messerschmitt KR'),
                    Product(id=61, name='Airplane'), Product(id=67, name='Hoverbike'),
                    Product(id=69, name='Powersuit'), Product(id=80, name='Submarine'),
                    Product(id=82, name='Flying Vehicle'), Product(id=85, name='West City Police scooter'),
                    Product(id=87, name='Jet-copter'), Product(id=88, name='Skill Shop Building'),
                    Product(id=96, name='Spatiotemporal Delivery Service Building'), Product(id=103, name='Airplane'),
                    Product(id=115, name='Airplane (4 passengers)'), Product(id=116, name='Hot Air Balloon'),
                    Product(id=192, name='Airship'), Product(id=239, name='Large plane (King Castle)'),
                    Product(id=240, name='Large plane'), Product(id=333, name='Penguin 333 fridge'),
                    Product(id=339, name='Airplane'), Product(id=341, name='Flying Vehicle'),
                    Product(id=462, name='Item Shop Building'), Product(id=576, name='VTOL Plane'),
                    Product(id=673, name='Yellow Van'), Product(id=991, name='Airplane'),
                    Product(id=1138, name='Spaceship'), Product(id=2031, name='Caps Fridge'),
                    Product(id=2150, name='West City Taxi'), Product(id=2402, name='Great Saiyaman Watch'),
                    ]
        cities = [City(name='Central City'), City(name='North City'),
                  City(name='East City'), City(name='West City'),
                  City(name='Orange Star City'), City(name='South City')]
        users = []
        prices = []
        for counter, city in enumerate(cities, start=1):
            users.append(User(id='{}[email protected]'.format(city.name.lower().split()[0]),
                              city=city))
            prices.append(Price(city=city, product=products[0], value=counter*10))
        Session.add_all(products + cities + users + prices)
开发者ID:marplatense,项目名称:multitenant_rls,代码行数:49,代码来源:initializedb.py

示例10: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])

    # settings
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    # recreate database
    create_tables(DBSession)
    alembic_cfg = Config(config_uri)
    command.upgrade(alembic_cfg, "head")

    # add postgres extension
    dialect = engine.dialect.name
    if dialect == 'postgresql':
        if not add_extension(engine, "hstore", "uuid-ossp"):
            logger.warn("You have not SUPERUSER role for Postgres!")
            logger.warn("Extensions passed...")
        from ..includes.home.models.postgres import Base as BasePostgres
        from ..includes.catalog.models import Base as BaseCatalog
        BasePostgres.metadata.create_all(engine)
        BaseCatalog.metadata.create_all(engine)

    def add_fixtures(fixtures):
        for item in fixtures:
            fixture.add(**item)
            transaction.commit()

    # fill database
    add_fixtures(fixtures)
    add_user({'login': 'admin', 'password': '123',
              'email': '[email protected]', 'name': u'Владимир',
              'surname': u'Хонин', 'middlename': u'Андреевич'})
    add_admin_permission()
    add_group_permissions()
开发者ID:uralbash,项目名称:ps_example,代码行数:42,代码来源:initializedb.py

示例11: initialize_sql

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def initialize_sql(engine, settings):
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
开发者ID:marplatense,项目名称:pyramid_oauth2_provider,代码行数:6,代码来源:models.py

示例12: setUpMigrate

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def setUpMigrate():
    """ Runs migrations before each test """
    engine = create_engine('sqlite://', echo=True)
    Session.configure(bind=engine)
    db_init(engine)
    db_upgrade(engine)
开发者ID:redpie,项目名称:pyramid_sqlalchemy,代码行数:8,代码来源:testing.py

示例13: main

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    with transaction.manager:

        model = User(
            login = u'admin',
            password = u'1234qwer4321',
            date_of_registration = datetime.now()
        )
        DBSession.add(model)


        model = Journal(
            name = u'AIP Conference Proceedings',
            publishing_country = u'USA'
        )
        DBSession.add(model)


        model = University(
            name = u'Ural Federal University named after the first President of Russia B. N. Yeltsin',
            country = u'Russia',
            city = u'Yekaterinburg'
        )
        DBSession.add(model)


        university = DBSession.query(University.id).\
            filter(University.name == u'Ural Federal University named after the first President of Russia B. N. Yeltsin').all()
        model1 = Author(
            full_name = u'Шибаев Вячеслав Алексеевич',
            university_id = university[0][0]
        )
        model2 = Author(
            full_name = u'Берестова Светлана Александрована',
            university_id = university[0][0]
        )
        model3 = Author(
            full_name = u'Митюшов Евгений Александрович',
            university_id = university[0][0]
        )
        model4 = Author(
            full_name = u'Хлебников Николай Александрович',
            university_id = university[0][0]
        )
        DBSession.add_all([model1, model2, model3, model4])



        journal = DBSession.query(Journal.id).\
            filter(Journal.name == u'AIP Conference Proceedings').all()
        user = DBSession.query(User.id).\
            filter(User.login == u'admin').all()
        model = Article(
            name = u'Mathematical modelling of the spatial network of bone implants obtained by 3D-prototyping',
            keywords = u'biomaterials, implants, 3D-printing',
            abstract = u'''
             In this paper, the mathematical model suitable for bone implants 3D-prototyping is proposed. The composite
             material with the spatial configuration of reinforcement with matrix of hydroxyapatite and titanium alloys
             fibers is considered. An octahedral cell is chosen as an elementary volume. The distribution of reinforcing
             fibers is described by textural parameters. Textural parameters are integrated characteristics that
             summarize information on the direction of reinforcing fibers and their volume fractions. Textural
             parameters, properties of matrix and reinforcing fibers allow calculating effective physical and mechanical
             properties of the composite material. The impact of height and width of the octahedral reinforcement cells
             on textural parameters of the composite material is investigated in this work. The impact of radius of
             fibers is also analyzed. It is shown that the composite becomes quasi-isotropic under certain geometrical
             parameters of cell.
            ''',
            file = 'VAShibaev.pdf',
            journal_id = journal[0][0],
            year_of_publishing = 2017,
            number_of_journal = 1,
            start_page = 92,
            end_page = 96,
            user_id = user[0][0]
        )
        DBSession.add(model)



        article = DBSession.query(Article.id).\
            filter(Article.name == u'Mathematical modelling of the spatial network of bone ' +
                                   u'implants obtained by 3D-prototyping').all()
        author1 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Шибаев Вячеслав Алексеевич').all()
        author2 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Берестова Светлана Александрована').all()
        author3 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Митюшов Евгений Александрович').all()
        author4 = DBSession.query(Author.id).\
#.........这里部分代码省略.........
开发者ID:VAShibaev,项目名称:CourseWork,代码行数:103,代码来源:initializedb.py


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