當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。