def save_to_wish(isbn): if current_user.can_saveto_list(isbn): with db.auto_commit(): wish = Wish() wish.isbn = isbn wish.uid = current_user.id db.session.add(wish) else: flash('这本书已存在于你的心愿单或者赠送清单,请勿重复添加') # 视图函数必须要返回值 return redirect(url_for('web.book_detail', isbn=isbn)) pass
def save_to_wishes(book_id): note = current_user.can_save_list(book_id) if note['can_save']: with db.auto_commit(): wish = Wish() wish.uid = current_user.id wish.book_id = note['book'].id db.session.add(wish) else: flash('这本书已添加至你的赠送清单或已存在于你的心愿清单,请不要重复添加') flash('成功加入心愿清单!') return redirect(url_for('web.book_detail', number=note['book'].number))