本文整理汇总了Python中models.DBSession.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.refresh方法的具体用法?Python DBSession.refresh怎么用?Python DBSession.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.DBSession
的用法示例。
在下文中一共展示了DBSession.refresh方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach_pictures
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import refresh [as 别名]
def attach_pictures(request):
menu_query = DBSession.query(Menu).filter(Menu.id==request.matchdict['menu_id'])
images_id = menu_query.one().images_id
images_id = images_id.split(' ') if images_id else []
if images_id:
images = DBSession.query(Image).filter(Image.id.in_(images_id)).all()
added_thumbs = []
if "data" in request.params:
data = json.loads(request.params["data"])
for image_info in data:
image, thumb = image_info
if not image or not thumb:
continue
ext = os.path.splitext(image)[-1].lower()
if ext in (".jpg", ".jpeg", ".png"):
new_image = Image(image_url=image, thumb_url=thumb)
added_thumbs.append(thumb)
DBSession.add(new_image)
DBSession.flush()
DBSession.refresh(new_image)
images_id.append(new_image.id)
menu_query.update({
"images_id": ' '.join([str(i) for i in images_id]),
})
return json.dumps(added_thumbs)
示例2: create_menu_item
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import refresh [as 别名]
def create_menu_item(request):
#create the new menu item entry
new_menu_item = MenuItem(name=request.params['name'].encode('utf8'), description=request.params['description'].encode('utf8'), menu_id=request.matchdict['menu_id'], healthy=int(request.params['healthy']))
DBSession.add(new_menu_item)
DBSession.flush()
DBSession.refresh(new_menu_item)
#create corresponding allergens
for allergen in ALLERGENS:
if allergen in request.params:
new_allergen = Allergen(menu_item_id=new_menu_item.id, allergen = allergen)
DBSession.add(new_allergen)
#find the corresponding menu
menuQuery = DBSession.query(Menu).filter(Menu.id==request.matchdict['menu_id'])
menu = menuQuery.one()
menu_items = menu.menus
#update the menu items on the menu
if len(menu_items) > 0: #just append
menu_items = menu_items.split(' ')
menu_items = map(int, menu_items)
menu_items.append(int(new_menu_item.id))
else: #create the first one
menu_items = [int(new_menu_item.id)]
menu_items_string = ' '.join(str(menu_item_id) for menu_item_id in menu_items)
menu.menus = menu_items_string
menuQuery.update({"menus":menu_items_string}, synchronize_session=False)
#update menu name if needed
first_menu_item = DBSession.query(MenuItem).filter(MenuItem.id==menu_items[0]).one()
#if we just inserted the first item in the menu, update the menu name with the first item name
if first_menu_item.id == new_menu_item.id:
menuQuery.update({"name":first_menu_item.name})
#update google calendar
update_gcalendar(menu)
url = request.route_url('edit_menu', cafe_id=int(request.matchdict['cafe_id']), menu_id=request.matchdict['menu_id'])
return HTTPFound(location=url)
示例3: create_menu
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import refresh [as 别名]
def create_menu(request):
#see if there's already a menu created with the same params
m = request.matchdict
menu = DBSession.query(Menu).filter(Menu.cafe_id==request.matchdict['cafe_id'])
if 'date' in request.params:
menu = menu.filter(Menu.date==request.params['date'])
if 'time' in request.params:
menu = menu.filter(Menu.time_sort_key==int(request.params['time']))
menu = menu.first()
#if not, create one
if menu is None:
# verify date
date = request.params['date']
if date is '0000-00-00':
return HTTPFound(location= request.route_url('edit_menus_today'))
menu = Menu(cafe_id=int(m['cafe_id']), name='', date=request.params['date'], time_sort_key=request.params['time'], menus='', sent=False)
DBSession.add(menu)
DBSession.flush()
DBSession.refresh(menu)
url = request.route_url('edit_menu', cafe_id=int(m['cafe_id']), menu_id=menu.id, allergen_list=ALLERGENS, healthy_factor=HEALTHY_FACTOR)
update_gcalendar(menu)
return HTTPFound(location=url)