本文整理汇总了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)
示例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))
示例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')
)
示例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)