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


Python models.DBSESSION类代码示例

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


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

示例1: upgrade

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,代码行数:9,代码来源:1_5_migrating_financ_4a4eba558244.py

示例2: add_customer

def add_customer(company, customer_name, customer_code, customer_lastname):
    customer = Customer()
    customer.name = customer_name #u"Institut médical Dupont & Dupond"
    customer.contactLastName = customer_lastname # "Dupont"
    customer.code = customer_code #"IMDD"
    customer.company = company

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

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

示例3: upgrade

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,代码行数:15,代码来源:1_6_migrate_code_com_29299007fe7d.py

示例4: add_user

def add_user(login, password, group, firstname="", lastname=""):
    user = User(login=login, firstname=firstname, lastname=lastname)
    user.set_password(password)

    user.primary_group = group

    session = DBSESSION()
    session.add(user)

    session.flush()

    group_name = GROUPS[group]
    print "Added %s: %s/%s" % (group_name, login, password)

    return user
开发者ID:mike-perdide,项目名称:autonomie,代码行数:15,代码来源:fake_database.py

示例5: run_migrations_online

def run_migrations_online():
    if DBSESSION.bind is None:
        raise ValueError(
"\nYou must do Autonomie migrations using the 'autonomie-migrate' script"
"\nand not through 'alembic' directly."
            )

    transaction.begin()
    connection = DBSESSION.connection()

    context.configure(
        connection=connection,
        target_metadata=DBBASE.metadata,
        )

    try:
        context.run_migrations()
    except:
        traceback.print_exc()
        transaction.abort()
    else:
        transaction.commit()
    finally:
        #connection.close()
        pass
开发者ID:mike-perdide,项目名称:autonomie,代码行数:25,代码来源:env.py

示例6: upgrade

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,代码行数:57,代码来源:2_3_1_2_3_1_header_and_logo_in_db_40c1f95213d0.py

示例7: upgrade

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,代码行数:19,代码来源:1_5_address_field_on_23fd141c9484.py

示例8: add_admin

def add_admin(arguments, env):
    """
        Add an admin user to the database
    """
    login = get_value(arguments, 'user', 'admin.majerti')
    password = get_value(arguments, 'pwd', get_pwd())
    firstname = get_value(arguments, 'firstname', 'Admin')
    lastname = get_value(arguments, 'lastname', 'Majerti')
    email = get_value(arguments, 'email', '[email protected]')
    user = User(login=login,
                firstname=firstname,
                primary_group=1,  #is an admin
                lastname=lastname,
                email=email
            )
    user.set_password(password)
    db = DBSESSION()
    db.add(user)
    db.flush()
    print u"Creating account %s with password %s" % (login, unicode(password))
    return user
开发者ID:w3bcr4ft,项目名称:autonomie,代码行数:21,代码来源:add_admin.py

示例9: upgrade

def upgrade():
    from autonomie.models import DBSESSION
    session = DBSESSION()
    from autonomie.models.activity import ActivityAction
    from alembic.context import get_bind
    for name in "subaction_id", "action_id":
        col = sa.Column(name, sa.Integer, sa.ForeignKey("activity_action.id"))
        op.add_column("activity", col)

    label_request = "select id, action_label, subaction_label from activity"

    conn = get_bind()
    result = conn.execute(label_request)

    already_added = {}

    for id, action_label, subaction_label in result:
        if (action_label, subaction_label) not in already_added.keys():
            found = False
            for key, value in already_added.items():
                if action_label == key[0]:
                    action_id = value[0]
                    found = True
            if not found:
                action = ActivityAction(label=action_label)
                session.add(action)
                session.flush()
                action_id = action.id
            subaction = ActivityAction(label=subaction_label, parent_id=action_id)
            session.add(subaction)
            session.flush()
            subaction_id = subaction.id
            already_added[(action_label, subaction_label)] = (action_id, subaction_id)
        else:
            action_id, subaction_id = already_added[(action_label, subaction_label)]

        op.execute("update activity set action_id={0}, subaction_id={1} \
where id={2}".format(action_id, subaction_id, id))
开发者ID:yledoare,项目名称:autonomie,代码行数:38,代码来源:1_9_1_add_a_configur_1b3d5402f3e4.py

示例10: upgrade

def upgrade():
    from autonomie.models import DBSESSION
    from autonomie.models.workshop import WorkshopAction
    from alembic.context import get_bind

    session = DBSESSION()
    conn = get_bind()

    col = sa.Column("activity_id", sa.Integer(), sa.ForeignKey("company_activity.id"))
    op.add_column("company_datas", col)
    col = sa.Column("archived", sa.Boolean(), default=False, server_default="0")
    op.add_column("customer", col)

    # Migration de accompagnement_header.png en activity_header.png
    op.execute(
        'update config_files set config_files.key="activity_header_img.png" where \
config_files.key="accompagnement_header.png";'
    )

    # Le bas de page des pdfs est celui par defaut pour les ateliers et rdv
    from autonomie.models.config import Config

    val = Config.get("coop_pdffootertext").value
    if val:
        for key in ("activity", "workshop"):
            config_key = "%s_footer" % key
            config = Config.set(config_key, val)

    # Migration de la taille des libelles pour les actions des rendez-vous
    op.execute("alter table activity_action modify label VARCHAR(255)")
    # Migration des intitules des ateliers
    # 1- Ajout des nouvelles foreignkey
    for name in "info1_id", "info2_id", "info3_id":
        col = sa.Column(name, sa.Integer, sa.ForeignKey("workshop_action.id"))
        op.add_column("workshop", col)

    # 2- création des options en fonction des valeurs en durs
    request = "select id, info1, info2, info3 from workshop"
    result = conn.execute(request)

    already_added = {}

    for id, info1, info2, info3 in result:
        info1 = info1.lower()
        info2 = info2.lower()
        info3 = info3.lower()
        info1_id = info2_id = info3_id = None
        if (info1, info2, info3) not in already_added.keys():

            for key, value in already_added.items():
                if key[0] == info1 and info1:
                    info1_id = value[0]
                    if key[1] == info2 and info2:
                        info2_id = value[1]

            if info1_id is None and info1:
                w = WorkshopAction(label=info1)
                session.add(w)
                session.flush()
                info1_id = w.id

            if info2_id is None and info2:
                w = WorkshopAction(label=info2, parent_id=info1_id)
                session.add(w)
                session.flush()
                info2_id = w.id

            if info3:
                w = WorkshopAction(label=info3, parent_id=info2_id)
                session.add(w)
                session.flush()
                info3_id = w.id
            already_added[(info1, info2, info3)] = (info1_id, info2_id, info3_id)
        else:
            info1_id, info2_id, info3_id = already_added[(info1, info2, info3)]

        request = "update workshop "
        if info1_id:
            request += "set info1_id={0}".format(info1_id)
            if info2_id:
                request += ", info2_id={0}".format(info2_id)
                if info3_id:
                    request += ", info3_id={0}".format(info3_id)
            request += " where id={0}".format(id)
            op.execute(request)
开发者ID:w3bcr4ft,项目名称:autonomie,代码行数:85,代码来源:2_7_1_add_columns_36b1d9c38c43.py

示例11: upgrade

def upgrade():
    from autonomie.models.task.invoice import ManualInvoice
    # Fix an error in table names for some installations
    class OldManualInvoice(DBBASE):
        """
            Modèle pour les factures manuelles (ancienne version)
        """
        __tablename__ = 'manualinvoice'
        id = Column('id', BigInteger, primary_key=True)
        officialNumber = Column('sequence_id', BigInteger)
        description = Column('libelle', String(255))
        montant_ht = Column("montant_ht", Integer)
        tva = Column("tva", Integer)
        payment_ok = Column("paiement_ok", Integer)
        statusDate = Column("paiement_date", Date())
        paymentMode = Column("paiement_comment", String(255))
        taskDate = Column("date_emission", Date(),
                                    default=datetime.datetime.now)
        created_at = Column("created_at", DateTime,
                                        default=datetime.datetime.now)
        updated_at = Column("updated_at", DateTime,
                                        default=datetime.datetime.now,
                                        onupdate=datetime.datetime.now)
        client_id = Column('client_id', Integer,
                                ForeignKey('customer.code'))

        company_id = Column('compagnie_id', Integer,
                                ForeignKey('company.id'))


    if not table_exists("manualinvoice"):
        force_rename_table('manual_invoice', 'manualinvoice')
    from autonomie.models import DBSESSION
    for manualinv in OldManualInvoice.query().all():
        m = ManualInvoice()
        m.montant_ht = manualinv.montant_ht
        m.tva = manualinv.tva
        m.client_id = manualinv.client_id
        m.company_id = manualinv.company_id
        m.description = manualinv.description
        m.CAEStatus = 'valid'
        if manualinv.payment_ok == '1' or manualinv.montant_ht < 0:
            m.CAEStatus = "resulted"
        if manualinv.montant_ht < 0:
            if manualinv.paymentMode == u"chèque":
                payment_mode = "CHEQUE"
            elif manualinv.paymentMode == u"virement":
                payment_mode = "VIREMENT"
            else:
                payment_mode = None
            if payment_mode:
                # We don't care about amounts since there is only one payment
                payment = Payment(mode=payment_mode, date=manualinv.statusDate,
                                amount=0)
                m.payments.append(payment)
        m.statusDate = manualinv.statusDate
        m.taskDate = manualinv.taskDate
        m.creationDate = manualinv.created_at
        m.updateDate = manualinv.updated_at
        m.phase_id = 0
        m.name = u"Facture manuelle %s" % manualinv.officialNumber
        m.officialNumber = manualinv.officialNumber
        m.owner_id = 0
        DBSESSION.add(m)
开发者ID:yledoare,项目名称:autonomie,代码行数:64,代码来源:1_5_moving_manualinv_2a7a5275c441.py

示例12: upgrade

def upgrade():
    from autonomie.models.activity import Attendance, Activity
    from autonomie.models import DBSESSION
    from alembic.context import get_bind

    session = DBSESSION()

    # Migrating attendance relationship
    query = "select event.id, event.status, rel.account_id, rel.activity_id from activity_participant rel inner join activity on rel.activity_id=activity.id LEFT JOIN event on event.id=activity.id"
    conn = get_bind()
    result = conn.execute(query)

    handled = []

    for event_id, status, user_id, activity_id in result:
        if status == 'planned':
            user_status = 'registered'

        elif status == 'excused':
            user_status = 'excused'
            status = 'cancelled'

        elif status == 'closed':
            user_status = 'attended'

        elif status == 'absent':
            user_status = 'absent'
            status = 'cancelled'

        # create attendance for each participant
        if (user_id, activity_id) not in handled:
            a = Attendance()
            a.status = user_status
            a.account_id = user_id
            a.event_id = activity_id
            session.add(a)
            session.flush()

            # Update the event's status regarding the new norm
            query = "update event set status='{0}' where id='{1}';".format(
                status, event_id,)
            op.execute(query)
            handled.append((user_id, activity_id,))

    # Migrating activity to add duration and use datetimes
    op.add_column('activity', sa.Column('duration', sa.Integer, default=0))
    op.alter_column(
        'event',
        'date',
        new_column_name='datetime',
        type_=sa.DateTime()
    )

    query = "select id, conseiller_id from activity;"
    result = conn.execute(query)

    values = []
    for activity_id, conseiller_id in result:
        values.append("(%s, %s)" % (activity_id, conseiller_id))
    if values != []:
        query = "insert into activity_conseiller (`activity_id`, `account_id`) \
VALUES {0}".format(','.join(values))
        op.execute(query)

    op.execute("alter table activity drop foreign key `activity_ibfk_2`;")

    op.drop_column('activity', 'conseiller_id')
    op.drop_table('activity_participant')
开发者ID:w3bcr4ft,项目名称:autonomie,代码行数:68,代码来源:2_2_activity_status__15d4152bd5d6.py


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