本文整理汇总了Python中nextgisweb.DBSession.autoflush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.autoflush方法的具体用法?Python DBSession.autoflush怎么用?Python DBSession.autoflush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nextgisweb.DBSession
的用法示例。
在下文中一共展示了DBSession.autoflush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_domain_dicts
# 需要导入模块: from nextgisweb import DBSession [as 别名]
# 或者: from nextgisweb.DBSession import autoflush [as 别名]
def load_domain_dicts(cls, force=False, federal=True, region=True, district=True):
print 'Loading domain dicts...'
from ..compulink_admin.model import Region, District
from csv import DictReader
if (region and not federal) or (district and not region):
print('Not consist params!')
return
db_session = DBSession()
db_session.autoflush = False
with transaction.manager:
if ((db_session.query(FederalDistrict).count() > 0 and federal) or
(db_session.query(Region).count() > 0 and region) or
(db_session.query(District).count() > 0 and district)) and not force:
print ' Domain dictionary already existings! Returning...'
return
with open(path.join(BASE_PATH, 'federal_districts.csv')) as fed_csv, \
open(path.join(BASE_PATH, 'regions.csv')) as reg_csv, \
open(path.join(BASE_PATH, 'districts.csv')) as dist_csv:
fed_reader = DictReader(fed_csv)
reg_reader = DictReader(reg_csv)
dist_reader = DictReader(dist_csv)
feds = {}
if federal:
for fed_row in fed_reader:
federal_dist = FederalDistrict()
federal_dist.name = fed_row['name']
federal_dist.short_name = fed_row['short_name']
federal_dist.persist()
feds[fed_row['id']] = federal_dist
regs = {}
if region:
for reg_row in reg_reader:
region = Region()
region.name = reg_row['name']
region.short_name = reg_row['short_name']
region.region_code = reg_row['region_code']
region.persist()
regs[reg_row['id']] = region
if district:
for dist_row in dist_reader:
district = District()
district.name = dist_row['name']
district.short_name = dist_row['short_name']
district.region = regs[dist_row['region_id']]
district.persist()
db_session.flush()
示例2: load_rt_domain_dicts
# 需要导入模块: from nextgisweb import DBSession [as 别名]
# 或者: from nextgisweb.DBSession import autoflush [as 别名]
def load_rt_domain_dicts(cls, force=False):
print 'Loading RT domain dicts...'
from ..compulink_admin.model import Region
from ..compulink_reporting.model import RtMacroDivision, RtBranch, RtBranchRegion
from csv import DictReader
db_session = DBSession()
db_session.autoflush = False
if (db_session.query(RtMacroDivision).count() > 0 or
db_session.query(RtBranch).count() > 0 or
db_session.query(RtBranchRegion).count() > 0
) and not force:
print ' RT Domain dictionary already existings! Returning...'
return
with open(path.join(BASE_PATH, 'rt_macro_division.csv')) as macro_csv, \
open(path.join(BASE_PATH, 'rt_branch.csv')) as branch_csv, \
open(path.join(BASE_PATH, 'rt_branch_region.csv')) as branch_region_csv:
macro_reader = DictReader(macro_csv)
branch_reader = DictReader(branch_csv)
branch_region_reader = DictReader(branch_region_csv)
macros = {}
branches = {}
for macro_row in macro_reader:
macro = RtMacroDivision()
macro.name = macro_row['name']
macro.persist()
macros[macro_row['id']] = macro
for branch_row in branch_reader:
branch = RtBranch()
branch.name = branch_row['name']
branch.rt_macro_division = macros[branch_row['macro_division_id']]
branch.persist()
branches[branch_row['id']] = branch
for br_reg_row in branch_region_reader:
branch_reg = RtBranchRegion()
branch_reg.rt_branch = branches[br_reg_row['rt_branch_id']]
branch_reg.region = db_session.query(Region).filter(Region.region_code == br_reg_row['region_code']).one()
branch_reg.persist()
db_session.flush()
示例3: init_calendar
# 需要导入模块: from nextgisweb import DBSession [as 别名]
# 或者: from nextgisweb.DBSession import autoflush [as 别名]
def init_calendar():
print('Fill calendar...')
db_session = DBSession()
db_session.autoflush = False
count = db_session.query(Calendar).count()
if count != 0:
print ' Calendar is not empty! Returning...'
return
start_date = date(2014, 1, 1)
max_date = date(2025, 1, 1)
active_date = start_date
quarter_names = {
1: u'1 кв.',
2: u'2 кв.',
3: u'3 кв.',
4: u'4 кв.',
}
month_names = {
1: u'Январь',
2: u'Февраль',
3: u'Март',
4: u'Апрель',
5: u'Май',
6: u'Июнь',
7: u'Июль',
8: u'Август',
9: u'Сентябрь',
10: u'Октябрь',
11: u'Ноябрь',
12: u'Декабрь',
}
week_day_names = {
1: u'Понедельник',
2: u'Вторник',
3: u'Среда',
4: u'Четверг',
5: u'Пятница',
6: u'Суббота',
7: u'Воскресенье',
}
week_day_short_names = {
1: u'Пн',
2: u'Вт',
3: u'Ср',
4: u'Чт',
5: u'Пт',
6: u'Сб',
7: u'Вс',
}
relat_day = relativedelta.relativedelta(days=+1)
while active_date < max_date:
cal = Calendar()
cal.id = active_date.year * 10000 + active_date.month * 100 + active_date.day
cal.full_date = active_date
cal.year_number = active_date.year
cal.semester_number = 1 if active_date.month < 7 else 2
cal.semester_name = u'1 полугодие' if active_date.month<7 else u'2 полугодие'
cal.quarter_number = (active_date.month-1)//3 + 1
cal.quarter_name = quarter_names[cal.quarter_number]
cal.month_number = active_date.month
cal.month_name = month_names[active_date.month]
cal.year_week_number = active_date.isocalendar()[1]
cal.month_week_number = get_week_of_month(active_date)
cal.month_decade_number = (active_date.day < 11) * 1 + \
(11 <= active_date.day <= 20) * 2 + \
(active_date.day > 20) * 3
cal.year_day_number = active_date.timetuple().tm_yday
cal.month_day_number = active_date.day
cal.week_day_number = active_date.weekday() + 1
cal.week_day_name = week_day_names[cal.week_day_number]
cal.week_day_short_name = week_day_short_names[cal.week_day_number]
cal.weekend = cal.week_day_number > 5
cal.persist()
active_date = active_date + relat_day
db_session.flush()