本文整理汇总了Python中nextgisbio.models.DBSession.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.refresh方法的具体用法?Python DBSession.refresh怎么用?Python DBSession.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nextgisbio.models.DBSession
的用法示例。
在下文中一共展示了DBSession.refresh方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_taxon
# 需要导入模块: from nextgisbio.models import DBSession [as 别名]
# 或者: from nextgisbio.models.DBSession import refresh [as 别名]
def create_taxon(request):
new_data = dict(request.POST)
dbsession = DBSession()
taxon = Taxon()
for k, v in new_data.items():
if v == '': v = None
if hasattr(taxon, k): setattr(taxon, k, v)
dbsession.add(taxon)
dbsession.flush()
dbsession.refresh(taxon)
return {'item': taxon.as_json_dict()}
示例2: table_item_save
# 需要导入模块: from nextgisbio.models import DBSession [as 别名]
# 或者: from nextgisbio.models.DBSession import refresh [as 别名]
def table_item_save(request):
person_id = None
if ('person_id' in request.POST) and request.POST['person_id'].isdigit():
person_id = int(request.POST['person_id'])
user_login = request.POST['user_login'] if 'user_login' in request.POST else None
if not user_login:
raise HTTPBadRequest('"user_login" is required parameter')
if not person_id:
users = DBSession.query(User).filter(User.login == user_login).all()
if len(users) > 0:
return {
'Result': 'Error',
'Message': u'Такой логин уже присутствует в системе'
}
with transaction.manager:
if person_id:
person = DBSession.query(Person) \
.options(joinedload('user')) \
.filter(Person.id == person_id) \
.all()[0]
user = person.user
else:
person = Person()
DBSession.add(person)
user = User()
DBSession.add(user)
person.user = user
for attr in request.POST:
table_name, field = attr.split('_')
if field == 'id':
continue
if table_name == 'person':
setattr(person, field, request.POST[attr])
if table_name == 'user':
setattr(user, field, request.POST[attr])
if 'user_active' in request.POST and request.POST['user_active']:
user.active = True
else:
user.active = False
if 'user_password' in request.POST and request.POST['user_password']:
user.password = User.password_hash(request.POST['user_password'])
DBSession.flush()
DBSession.refresh(user)
DBSession.refresh(person)
person_json = person.as_json_dict('person_')
user_json = user.as_json_dict('user_')
item_json = person_json.copy()
item_json.update(user_json)
return {
'Result': 'OK',
'Record': item_json
}