本文整理汇总了Python中autonomie_base.models.base.DBSESSION类的典型用法代码示例。如果您正苦于以下问题:Python DBSESSION类的具体用法?Python DBSESSION怎么用?Python DBSESSION使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSESSION类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_types
def get_types(cls, active=True, keys=()):
query = DBSESSION().query(cls)
if keys:
query = query.options(load_only(*keys))
if active:
query = query.filter_by(active=True)
return query
示例2: deferred_categories_widget
def deferred_categories_widget(node, kw):
query = DBSESSION().query(
IncomeStatementMeasureTypeCategory.label,
IncomeStatementMeasureTypeCategory.label,
)
choices = query.filter_by(active=True).all()
return deform.widget.CheckboxChoiceWidget(values=choices)
示例3: query_existing_business_indicators
def query_existing_business_indicators(
cls, business_id, file_type_id, task_id=None
):
"""
Build a query for indicators related to a given business
Excludes indicators related to task_id
:param int business_id: The business id
:param int file_type_id: The type of file the indicators are related to
:param int task_id: The id of the task to exclude from the query
"""
from autonomie.models.task import Task
tasks_id_query = DBSESSION().query(Task.id).filter_by(
business_id=business_id
)
if task_id is not None:
tasks_id_query = tasks_id_query.filter(Task.id != task_id)
query = SaleFileRequirement.query().filter_by(
file_type_id=file_type_id
)
return query.filter(
or_(
SaleFileRequirement.node_id == business_id,
SaleFileRequirement.node_id.in_(tasks_id_query)
)
)
示例4: query
def query(self):
"""
Return the main query for our list view
"""
logger.debug("Queryiing")
query = DBSESSION().query(distinct(User.id), User)
return query.outerjoin(User.companies)
示例5: upgrade
def upgrade():
op.add_column('payment', sa.Column('created_at', sa.DateTime()))
op.add_column('payment', sa.Column('updated_at', sa.DateTime()))
op.add_column('payment', sa.Column('bank_id', sa.Integer(), nullable=True))
op.add_column('payment', sa.Column('exported', sa.Boolean(), default=False))
op.add_column('payment', sa.Column(
'tva_id',
sa.Integer(),
sa.ForeignKey('tva.id'),
nullable=True,
))
op.add_column(
'payment',
sa.Column('remittance_amount', sa.Integer(), nullable=True)
)
op.add_column(
'tva',
sa.Column('compte_a_payer', sa.String(125), default='')
)
from autonomie_base.models.base import DBSESSION
from autonomie.models.task import Payment
session = DBSESSION()
for payment in Payment.query():
payment.remittance_amount = payment.amount
payment.exported = True
payment.created_at = payment.updated_at = payment.date
session.merge(payment)
示例6: find_by_login
def find_by_login(cls, login, active=True):
query = DBSESSION().query(cls)
query = query.options(load_only('pwd_hash'))
query = query.filter_by(login=login)
if active:
query = query.filter_by(active=True)
return query.first()
示例7: get_cancelinvoices
def get_cancelinvoices(cls, instance, valid=False):
from autonomie.models.task import CancelInvoice
query = DBSESSION().query(CancelInvoice)
query = query.filter(CancelInvoice.company_id == instance.id)
if valid:
query = query.filter(CancelInvoice.status == 'valid')
return query
示例8: connection
def connection(request, settings):
""" sets up a SQLAlchemy engine and returns a connection
to the database.
:param settings: the settings of the test (given by the testing fixture)
:returns: a sqlalchemy connection object
"""
# the following setup is based on `kotti.resources.initialize_sql`,
# except that it explicitly binds the session to a specific connection
# enabling us to use savepoints independent from the orm, thus allowing
# to `rollback` after using `transaction.commit`...
initialize_test_database(settings)
from autonomie_base.models.base import DBSESSION, DBBASE
engine = engine_from_config(settings, prefix='sqlalchemy.')
_connection = engine.connect()
DBSESSION.registry.clear()
DBSESSION.configure(bind=_connection)
DBBASE.metadata.bind = engine
def drop_db():
"""
drop the test database
"""
print("DROPPING DB")
if __current_test_ini_file().endswith('travis.ini'):
return
db_settings = get_test_options_from_settings(settings)
launch_cmd(db_settings['drop'])
request.addfinalizer(drop_db)
return _connection
示例9: authenticate
def authenticate(cls, user_cls, login, password):
result = DBSESSION().query(user_cls).filter(
user_cls.login == login
).first()
if result is not None and result.auth(password):
return result.id
return None
示例10: migrate_datas
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,代码行数:35,代码来源:4_2_copy_workshop_leaders_in_description_a9229288927.py
示例11: migrate_datas
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()
示例12: get_estimations
def get_estimations(cls, instance, valid=False):
from autonomie.models.task import Estimation
query = DBSESSION().query(Estimation)
query = query.filter(Estimation.company_id == instance.id)
if valid:
query = query.filter(Estimation.status == 'valid')
return query
示例13: migrate_datas
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,代码行数:8,代码来源:4_2_0_initialise_la_config_de_la_taille_de__4f8d19c47c76.py
示例14: active_company_ids
def active_company_ids(self):
"""
Return only enabled companies ids
"""
from autonomie.models.company import Company
query = DBSESSION().query(COMPANY_EMPLOYEE.c.company_id)
query = query.filter(COMPANY_EMPLOYEE.c.account_id == self.id)
query = query.join(Company).filter(Company.active == True)
return [c[0] for c in query]
示例15: has_userdatas
def has_userdatas(self):
"""
Return True if the current object has userdatas associated to it
"""
from autonomie.models.user.userdatas import UserDatas
query = DBSESSION().query(UserDatas.id)
query = query.filter(UserDatas.user_id == self.id)
count = query.count()
return count >= 1