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


Python DBSESSION.merge方法代码示例

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


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

示例1: upgrade

# 需要导入模块: from autonomie.models import DBSESSION [as 别名]
# 或者: from autonomie.models.DBSESSION import merge [as 别名]
def upgrade():
    for table in "invoice", "cancelinvoice", "manualinv":
        if not column_exists(table, "financial_year"):
            op.add_column(table, sa.Column("financial_year", sa.Integer,
                                                        nullable=False))
    for type_ in (Invoice, CancelInvoice, ManualInvoice):
        for document in type_.query():
            document.financial_year = document.taskDate.year
            DBSESSION.merge(document)
开发者ID:mike-perdide,项目名称:autonomie,代码行数:11,代码来源:1_5_migrating_financ_4a4eba558244.py

示例2: upgrade

# 需要导入模块: from autonomie.models import DBSESSION [as 别名]
# 或者: from autonomie.models.DBSESSION import merge [as 别名]
def upgrade():
    logger = logging.getLogger("alembic.migrate_code_compta")
    op.add_column("company", sa.Column("code_compta", sa.String(30), default=0))
    dbsession = DBSESSION()
    for user in User.query():
        code_compta = user.code_compta
        companies = user.companies
        if code_compta not in [u"0", None, u""]:
            if len(companies) == 1:
                company = companies[0]
                company.code_compta = code_compta
                dbsession.merge(company)
            else:
                logger.warn(u"User {0} has a code_compta and multiple \
companies".format(user.id))
开发者ID:mike-perdide,项目名称:autonomie,代码行数:17,代码来源:1_6_migrate_code_com_29299007fe7d.py

示例3: upgrade

# 需要导入模块: from autonomie.models import DBSESSION [as 别名]
# 或者: from autonomie.models.DBSESSION import merge [as 别名]
def upgrade():
    from autonomie.models.company import Company
    from autonomie.models.files import File
    from autonomie.models 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:w3bcr4ft,项目名称:autonomie,代码行数:59,代码来源:2_3_1_2_3_1_header_and_logo_in_db_40c1f95213d0.py

示例4: upgrade

# 需要导入模块: from autonomie.models import DBSESSION [as 别名]
# 或者: from autonomie.models.DBSESSION import merge [as 别名]
def upgrade():
    from autonomie.models.client import Client
    for table in ("estimation", "invoice", "cancelinvoice"):
        op.add_column(table, sa.Column("address", sa.Text, default=""))
        op.add_column(table,
                sa.Column("client_id",
                          sa.Integer,
                          sa.ForeignKey("customer.id")))

    for obj in (Invoice, CancelInvoice, Estimation):
        for doc in obj.query():
            if doc.project is not None and doc.project.client_id is not None:
                client = Client.get(doc.project.client_id)
                if client is not None:
                    doc.address = client.full_address
                    doc.client_id = client.id
            if len(doc._number) > 10:
                doc._number = doc._number[10:]
            DBSESSION.merge(doc)
开发者ID:mike-perdide,项目名称:autonomie,代码行数:21,代码来源:1_5_address_field_on_23fd141c9484.py


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