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


Python orm.db_session方法代码示例

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


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

示例1: help

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def help(bot, update):
    """ Handler for the /help command """
    from_user = update.message.from_user
    chat_id = update.message.chat_id

    with db_session:
        admin = get_admin(from_user)

    text = help_text

    if admin:
        text += admin_help_text
        if admin.super_admin:
            text += super_admin_help_text

    bot.sendMessage(chat_id,
                    text=text,
                    parse_mode=ParseMode.HTML,
                    disable_web_page_preview=True) 
开发者ID:jslim18,项目名称:cerebros_bot,代码行数:21,代码来源:bot.py

示例2: user_locale

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def user_locale(func):
    @wraps(func)
    @db_session
    def wrapped(bot, update, *pargs, **kwargs):
        user = _user_chat_from_update(update)[0]

        with db_session:
            us = UserSetting.get(id=user.id)

        if us and us.lang != 'en':
            _.push(us.lang)
        else:
            _.push('en_US')

        result = func(bot, update, *pargs, **kwargs)
        _.pop()
        return result
    return wrapped 
开发者ID:jh0ker,项目名称:mau_mau_bot,代码行数:20,代码来源:internationalization.py

示例3: main

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def main():
    config_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.home() / '.config' / 'whereisit.toml'
    with open(config_path) as f:
        config = toml.load(f)

    import logging
    logging.getLogger('aiohttp.client').setLevel(logging.ERROR)

    db_path = Path.home() / '.local' / 'share' / config['database']['path']
    orm.sql_debug(config['database'].get('debug', False))
    database.bind("sqlite", str(db_path), create_db=True)
    database.generate_mapping(create_tables=True)

    with orm.db_session():
        orm.select(t for t in database.Tracking
                   if t.id not in list(config['trackings'].keys())).delete(bulk=True)

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    with contextlib.closing(asyncio.get_event_loop()) as loop:
        tracker = Tracker(loop=loop, db=database, config=config)
        loop.create_task(tracker.run())
        loop.run_forever() 
开发者ID:drrlvn,项目名称:whereisit,代码行数:24,代码来源:main.py

示例4: test_common_pony

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def test_common_pony():
    db = orm.Database()

    class Account(db.Entity):
        name = orm.Required(str)
        msgn_id = orm.Required(int)
        auth_code = orm.Required(str)

    db.bind('sqlite', ':memory:', create_db=True)
    db.generate_mapping(create_tables=True)
    orm.sql_debug(True)

    @orm.db_session
    def test():
        Account(name="haje01", msgn_id=3498, auth_code="1234")
        a = Account(name="haje02", msgn_id=2345, auth_code="1234")
        assert len(orm.select(a for a in Account)) == 2
        assert len(orm.select(a for a in Account if a.msgn_id == 2345)) == 1
        a.delete()
        assert len(orm.select(a for a in Account)) == 1

    test() 
开发者ID:haje01,项目名称:chabi,代码行数:24,代码来源:test_common.py

示例5: test_facebook_loginout

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def test_facebook_loginout(app):
    db.bind('sqlite', 'muorigin.sqlite', create_db=True)
    db.generate_mapping(create_tables=True)
    app.wsgi_app = orm.db_session(app.wsgi_app)

    with app.test_client() as c:
        r = do_login(c)
        assert '200 OK' == r.status
        data = r.data.decode('utf8')
        assert 'successfully logged in' in data

        r = do_login(c)
        assert '200 OK' == r.status
        data = r.data.decode('utf8')
        assert 'already logged in' in data

        r = do_logout(c)
        assert '200 OK' == r.status
        data = r.data.decode('utf8')
        assert 'successfully logged out' in data

        r = do_logout(c)
        assert '200 OK' == r.status
        data = r.data.decode('utf8')
        assert 'not logged in' in data 
开发者ID:haje01,项目名称:chabi,代码行数:27,代码来源:test_facebook.py

示例6: populate_persons

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def populate_persons(n=50):
    from faker import Faker
    from pony.orm import db_session
    from fbcm.models import Player

    fake = Faker()
    with db_session:
        for _ in range(n):
            try:
                Player(
                    id=fake.numerify('#' * 10),
                    name=fake.first_name(),
                    lastname=fake.last_name(),
                )
            except Exception:
                continue 
开发者ID:stsewd,项目名称:fbcm,代码行数:18,代码来源:manage.py

示例7: populate_championships

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def populate_championships():
    from pony.orm import db_session
    from fbcm.models import Championship
    from fbcm.views import add_default_stages

    with db_session:
        c = Championship(
            name="El Campeonato",
            description="""
                Campeonato de fútbol que será jugado en algún momento del 2017.
            """,
            points_winner=2,
            points_draw=1,
            points_loser=0
        )
        add_default_stages(c) 
开发者ID:stsewd,项目名称:fbcm,代码行数:18,代码来源:manage.py

示例8: register_players_on_teams

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def register_players_on_teams(num_players=11, num_teams=16):
    from pony.orm import db_session
    from fbcm.models import Team, Player, Position
    #  import random

    with db_session:
        teams = Team.select()[:num_teams]

        for page, team in enumerate(teams, 1):
            players = Player.select().page(page, pagesize=num_players)
            for number, player in enumerate(players):
                player.set(
                    number=number,
                    position=Position.select_random(1)[:1][0]
                )
            team.set(
                players=players
            ) 
开发者ID:stsewd,项目名称:fbcm,代码行数:20,代码来源:manage.py

示例9: add_believer

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def add_believer(bot, update):
    global state
    with db_session:
        admin = get_admin(update.message.from_user)
    if not admin:
        return
    state[update.message.chat_id] = ADD_BELIEVER
    bot.sendMessage(update.message.chat_id,
                    text="Forward me a message of the user that is reporting "
                         "the trustworthy bitcoin trader or use /cancel to cancel",
                    reply_to_message_id=update.message.message_id) 
开发者ID:jslim18,项目名称:cerebros_bot,代码行数:13,代码来源:bot.py

示例10: remove_believer

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def remove_believer(bot, update):
    global state
    with db_session:
        admin = get_admin(update.message.from_user)
    if not admin:
        return
    state[update.message.chat_id] = REMOVE_BELIEVER
    bot.sendMessage(update.message.chat_id,
                    text="Please send the Report # of the report you wish "
                         "to remove or send /cancel to cancel",
                    reply_markup=ForceReply(selective=True),
                    reply_to_message_id=update.message.message_id) 
开发者ID:jslim18,项目名称:cerebros_bot,代码行数:14,代码来源:bot.py

示例11: edit_believer

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def edit_believer(bot, update):
    global state
    with db_session:
        admin = get_admin(update.message.from_user)
    if not admin:
        return
    state[update.message.chat_id] = EDIT
    bot.sendMessage(update.message.chat_id,
                    text="Please send the Report # of the report you wish "
                         "to edit or send /cancel to cancel",
                    reply_markup=ForceReply(selective=True),
                    reply_to_message_id=update.message.message_id) 
开发者ID:jslim18,项目名称:cerebros_bot,代码行数:14,代码来源:bot.py

示例12: add_admin

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def add_admin(bot, update):
    global state
    with db_session:
        admin = get_admin(update.message.from_user)
    if not admin or not admin.super_admin:
        return
    state[update.message.chat_id] = ADD_ADMIN
    bot.sendMessage(update.message.chat_id,
                    text="Forward me a message of the user you want to add"
                         " as admin or send /cancel to cancel",
                    reply_to_message_id=update.message.message_id) 
开发者ID:jslim18,项目名称:cerebros_bot,代码行数:13,代码来源:bot.py

示例13: download_db

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def download_db(bot, update):
    chat_id = update.message.chat_id
    global state
    with db_session:
        admin = get_admin(update.message.from_user)
    if not admin or not admin.super_admin:
        return
    bot.sendChatAction(chat_id, action=ChatAction.UPLOAD_DOCUMENT)
    bot.sendDocument(chat_id, document=open(DB_NAME, 'rb'),
                     filename='trustworthy.sqlite',
                     reply_to_message_id=update.message.message_id) 
开发者ID:jslim18,项目名称:cerebros_bot,代码行数:13,代码来源:bot.py

示例14: customer_register

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def customer_register():
    form = CustomerForm(request.form)

    if form.validate_on_submit():
        with db_session:
            customer = Customer(email=form.email.data,
                                   password=form.password.data,
                                   name=form.name.data,
                                   country=form.country.data,
                                   address=form.address.data)
        return redirect(url_for('customer_show', customer_id=customer.id))

    return render_template('customer/register.html', form=form) 
开发者ID:kyzima-spb,项目名称:flask-pony,代码行数:15,代码来源:views.py

示例15: game_locales

# 需要导入模块: from pony import orm [as 别名]
# 或者: from pony.orm import db_session [as 别名]
def game_locales(func):
    @wraps(func)
    @db_session
    def wrapped(bot, update, *pargs, **kwargs):
        user, chat = _user_chat_from_update(update)
        player = gm.player_for_user_in_chat(user, chat)
        locales = list()

        if player:
            for player in player.game.players:
                us = UserSetting.get(id=player.user.id)

                if us and us.lang != 'en':
                    loc = us.lang
                else:
                    loc = 'en_US'

                if loc in locales:
                    continue

                _.push(loc)
                locales.append(loc)

        result = func(bot, update, *pargs, **kwargs)

        while _.code:
            _.pop()

        return result
    return wrapped 
开发者ID:jh0ker,项目名称:mau_mau_bot,代码行数:32,代码来源:internationalization.py


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