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


Python DBSESSION.flush方法代码示例

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


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

示例1: migrate_datas

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def migrate_datas():
    logger = logging.getLogger("alembic.autonomie")
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()
    from autonomie.models.config import Config
    import json

    from autonomie.models.files import (
        File,
        FileType,
    )
    json_str = Config.get_value("attached_filetypes", "[]")
    try:
        configured_filetypes = json.loads(json_str)
    except:
        logger.exception(u"Error in json str : %s" % json_str)
        configured_filetypes = []
    if configured_filetypes:
        result = []
        for filetype_label in configured_filetypes:
            if filetype_label:
                filetype = FileType(label=filetype_label)
                session.add(filetype)
                session.flush()
                result.append(filetype)

        for typ_ in result:
            query = File.query().filter_by(label=typ_.label)
            for file_ in query:
                file_.file_type_id = typ_.id
                session.merge(file_)
        session.flush()
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:34,代码来源:4_2_0_add_filetype_table_11a62732db65.py

示例2: migrate_datas

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def migrate_datas():
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()

    from alembic.context import get_bind
    conn = get_bind()

    for row in list(conn.execute('SELECT id, leaders FROM workshop')):
        if not row.leaders:
            continue

        try:
            leaders_list = json.loads(row.leaders)
        except ValueError:
            # This should not happen, but some dumps we use have a bare string
            # in leaders field.
            leaders_list = [row.leaders]

        req = sa.text("""
            UPDATE workshop SET
            description=CONCAT(
              'Formateurs: ',
              IFNULL(:leaders, ''),
              ' ',
              IFNULL(description, '')
            )
            WHERE id=:id_
            """)
        conn.execute(
            req,
            leaders=', '.join(leaders_list),
            id_=row.id,
        )
    mark_changed(session)
    session.flush()
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:37,代码来源:4_2_copy_workshop_leaders_in_description_a9229288927.py

示例3: upgrade

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def upgrade():
    disable_listeners()
    op.add_column('task', sa.Column('date', sa.Date()))
    from autonomie.models.task import Task
    from autonomie_base.models.base import DBSESSION

    session = DBSESSION()
    for task in Task.query().filter(Task.type_!='manualinvoice'):
        task.date = task.taskDate
        session.merge(task)
    session.flush()

    op.execute("alter table groups modify label VARCHAR(255);")
    op.execute("alter table payment modify remittance_amount VARCHAR(255);")
    from autonomie.models.user import User, Group
    for group_id, group_name, group_label in GROUPS:
        group = session.query(Group).filter(Group.name==group_name).first()
        if group is None:
            group = Group(name=group_name, label=group_label)
            session.add(group)
            session.flush()

        users = session.query(User).filter(User.primary_group==group_id)
        for user in users:
            user._groups.append(group)
            session.merge(user)

    label = u"Peut saisir/modifier/supprimer les paiements de ses factures"
    group_name = "payment_admin"
    group = Group.query().filter(Group.name==group_name).first()
    if group is not None:
        group.label = label
        session.merge(group)
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:35,代码来源:3_2_add_base_groups_58df01afdaad.py

示例4: upgrade

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def upgrade():
    from autonomie.models import user
    from autonomie_base.models.base import DBSESSION

    db = DBSESSION()

    for u in db.query(user.User)\
             .filter(user.User.userdatas==None)\
             .filter(user.User.primary_group==3):
        situation = "sortie"
        if u.email:
            userdata = user.UserDatas(
                situation_situation=situation,
                coordonnees_firstname=u.firstname,
                coordonnees_lastname=u.lastname,
                coordonnees_email1=u.email,
                coordonnees_civilite=u'?',
            )
            userdata.user_id = u.id
            for company in u.companies:
                companydata = user.CompanyDatas(
                    title=company.goal,
                    name=company.name,
                )
                userdata.activity_companydatas.append(companydata)
            db.add(userdata)
            db.flush()
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:29,代码来源:2_3_1_add_userdatas_disabled_accounts_42c3d2634645.py

示例5: upgrade

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def upgrade():

    from autonomie_base.models.base import DBSESSION


    session = DBSESSION()
    from alembic.context import get_bind

    request = "select id, type_, name, creationDate, updateDate from task"
    conn = get_bind()
    result = conn.execute(request)
    index = 0
    max_id = -1
    for id_, type_, name, creationDate, updateDate in result:
        creationDate = format_date(creationDate)
        updateDate = format_date(updateDate)
        index += 1
        node = Node(
                id=id_,
                created_at=creationDate,
                updated_at=updateDate,
                name=name,
                type_=type_
                )
        session.add(node)
        if index % 50 == 0:
            session.flush()
        if id_ > max_id:
            max_id = id_

    request = "select id, name, creationDate, updateDate from project ORDER BY id DESC"
    result = conn.execute(request).fetchall()

    # We disable foreign key constraints check
    op.execute("SET FOREIGN_KEY_CHECKS=0;")
    index = 0
    for id_, name, creationDate, updateDate in result:
        new_id = id_ + max_id
        creationDate = format_date(creationDate)
        updateDate = format_date(updateDate)
        index += 1
        node = Node(
                id=new_id,
                created_at=creationDate,
                updated_at=updateDate,
                name=name,
                type_='project'
                )
        session.add(node)

        # We update the foreignkeys
        for table in ('estimation', 'invoice', 'cancelinvoice', 'phase', 'project_customer'):
            op.execute("update {0} set project_id={1} where project_id={2}".format(table, new_id, id_))

        # We update the project id
        op.execute("update project set id={0} where id={1};".format(new_id, id_))
        if index % 50 == 0:
            session.flush()
    op.execute("SET FOREIGN_KEY_CHECKS=1;")
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:61,代码来源:1_8_add_a_base_node__1ca3a6ef9c9d.py

示例6: migrate_datas

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def migrate_datas():
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()
    from alembic.context import get_bind
    conn = get_bind()
    from autonomie.models.config import Config
    Config.set('accounting_label_maxlength', 35)
    session.flush()
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:10,代码来源:4_2_0_initialise_la_config_de_la_taille_de__4f8d19c47c76.py

示例7: migrate_datas

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def migrate_datas():
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()
    from autonomie.models.accounting.operations import AccountingOperationUpload
    for entry in AccountingOperationUpload.query():
        entry.filetype = "analytical_balance"
        session.merge(entry)
        session.flush()
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:10,代码来源:4_1_compte_de_resultats_13a25f46e412.py

示例8: upgrade

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def upgrade():
    from autonomie.models.company import Company
    from autonomie.models.files import File
    from autonomie_base.models.base import DBSESSION
    from alembic.context import get_bind
    from autonomie.models.config import ConfigFiles

    for i in ('header_id', 'logo_id',):
        col = sa.Column(i, sa.Integer, sa.ForeignKey('file.id'))
        op.add_column('company', col)

    query = "select id, header, logo from company;"
    conn = get_bind()
    result = conn.execute(query)

    session = DBSESSION()

    for id_, header, logo in result:
        company = Company.get(id_)
        basepath = u"%scompany/%s" % (BASEFILEPATH, id_,)

        if header:
            header_path = u"%s/header/%s" % (basepath, header)
            try:
                file_datas = load_file_struct(header_path, header)
            except:
                print("Error while loading a header")
                print(id_)
                file_datas = None
            if file_datas:
                company.header = file_datas
                session.add(company.header_file)
                session.flush()

        if logo:
            logo_path = u"%s/logo/%s" % (basepath, logo)
            try:
                file_datas = load_file_struct(logo_path, logo)
            except:
                print("Error while loading a logo")
                print(id_)
                file_datas = None
            if file_datas:
                company.logo = file_datas
                company = session.merge(company)
                session.flush()

    filepath = u"%s/main/logo.png" % BASEFILEPATH
    if os.path.isfile(filepath):
        ConfigFiles.set('logo.png', load_file_struct(filepath, 'logo.png'))

    filepath = u"%s/main/accompagnement_header.png" % BASEFILEPATH
    if os.path.isfile(filepath):
        ConfigFiles.set(
            'accompagnement_header.png',
            load_file_struct(filepath, 'accompagnement_header.png')
        )
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:59,代码来源:2_3_1_2_3_1_header_and_logo_in_db_40c1f95213d0.py

示例9: add_expense_type

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def add_expense_type(type_, **kwargs):
    if type_ == 'km':
        e = ExpenseKmType(**kwargs)
    elif type_ == 'tel':
        e = ExpenseTelType(**kwargs)
    else:
        e = ExpenseType(**kwargs)
    session = DBSESSION()
    session.add(e)
    session.flush()
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:12,代码来源:fake_database.py

示例10: add_customer

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def add_customer(**kw): #company, customer_name, customer_code, customer_lastname):
    customer = Customer(**kw)

    session = DBSESSION()
    session.add(customer)
    session.flush()

    print u"Added customer to %s: %s" % (
        customer.company.name,
        customer.name)
    return customer
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:13,代码来源:fake_database.py

示例11: add_phase

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def add_phase(project, phase_name):
    phase = Phase(name=phase_name)
    phase.project = project

    session = DBSESSION()
    session.add(phase)
    session.flush()

    print u"Added phase to %s: %s" % (project.name, phase_name)

    return phase
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:13,代码来源:fake_database.py

示例12: add_project

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def add_project(customer, company, project_name, project_code):
    project = Project(name=project_name, code=project_code)
    project.customers.append(customer)
    project.company = company

    session = DBSESSION()
    session.add(project)
    session.flush()

    print u"Added project to %s for %s: %s" % (company.name, customer.name,
                                                            project_name)
    return project
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:14,代码来源:fake_database.py

示例13: add_company

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def add_company(user, company_name, goal=""):
    company = Company()
    company.name = company_name
    company.goal = goal or u"Entreprise de %s" % user.login

    user.companies.append(company)

    session = DBSESSION()
    session.add(company)

    session.flush()

    print "Added company for %s: %s" % (user.login, company_name)

    return company
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:17,代码来源:fake_database.py

示例14: upgrade

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def upgrade():
    from autonomie.models.task import (
        TaskLine,
        TaskLineGroup,
        Task,
        Estimation,
        CancelInvoice,
        Invoice,
    )
    from autonomie_base.models.base import (
        DBSESSION,
    )

    session = DBSESSION()

    index = 0
    query = Task.query()
    query = query.with_polymorphic([Invoice, CancelInvoice, Estimation])
    query = query.filter(
        Task.type_.in_(['invoice', 'estimation', 'cancelinvoice'])
    )
    for task in query:
        group = TaskLineGroup(task_id=task.id, order=0)

        for line in task.lines:

            tline = TaskLine(
                group=group,
                order=line.rowIndex,
                description=line.description,
                cost=line.cost,
                tva=line.tva,
                quantity=line.quantity,
            )

            if hasattr(line, 'product_id'):
                tline.product_id = line.product_id
            session.add(tline)

            if index % 100 == 0:
                session.flush()

    op.alter_column(
        table_name='estimation_payment',
        column_name='rowIndex',
        new_column_name='order',
        type_=sa.Integer,
    )
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:50,代码来源:3_0_migrate_task_lines_2192101f133b.py

示例15: add_user

# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import flush [as 别名]
def add_user(login, password, group, firstname="", lastname="", email=""):
    user = User(login=login,
                firstname=firstname,
                lastname=lastname,
                email=email)
    user.set_password(password)

    user.groups.append(group)

    session = DBSESSION()
    session.add(user)

    session.flush()

    print "Added %s: %s/%s" % (group, login, password)

    return user
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:19,代码来源:fake_database.py


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