def send_drift(gid): form = DriftForm(request.form) gift = Gift.query.get_or_404(gid) if gift.is_yourself_gift(current_user.id): flash('你不能想自己请求礼物') return redirect(url_for('book.book_detail', isbn=gift.isbn)) if not current_user.can_send_drift(): return render_template('drift/not_enough_beans.html', beans=current_user.beans) if (request.method == 'POST') and form.validate(): save_drift(form, gift) send_mail(gift.user.email, '有人向你请求一本书', 'email/get_gift.html', wisher=current_user, gift=gift) return redirect(url_for('drift.pending')) return render_template('drift/drift.html', presenter=gift.user.summary, user_beans=current_user.beans, form=form)
def send_drift(gid): #该方法是索要书籍 current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('这本书是自己的,不能向自己索要书籍') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) #赠送书籍页面保存信息 #交易通知的方式,邮箱,短信 send_mail(current_gift.user.email, '有人想要这本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary #id没用, 是relationship来操作另一个表 return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): # gid = 是被赠送的书本的id,也就是礼物的id current_gift = Gift.query.get_or_404(gid) # 通过gid去查到集体是那一本书 # 判断自己是不是赠送这本书的人 if current_gift.is_yourself_gift(current_user.id): flash(message='这本书是你自己的,不能向你自己索要书籍') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) # 判断鱼斗是否满足条件 # 要求每收到两本书就要送出一本书 can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_email(to=current_gift.user.email, subject='有人想要一本书', template='email/get_gift.html', gift=current_gift, wisher=current_user) flash(message='邮件已发送') return redirect(url_for('web.pending')) return render_template('drift.html', gifter=current_gift.user.summary, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash("这本书是你自己的,不能向自己索要书籍哦~") return redirect(url_for("web.book_detail", isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template("not_enough_beans.html", beans=current_user.beans) form = DriftForm(request.form) if request.method == "POST" and form.validate(): save_drift(form, current_gift) # 发送邮件提醒 send_email(current_gift.user.email, "有人向你请求一本书", "email/get_gift.html", wisher=current_user, gift=current_gift) return redirect(url_for("web.pending")) gifter = current_gift.user.summary yushu_book = YuShuBook() yushu_book.search_by_isbn(current_gift.isbn) book = BookViewModel(yushu_book.first) return render_template("drift.html", gifter=gifter, book=book, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_gift): flash('please do not require the book that you posted') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, 'Some One Want Your Book', 'email/get_gift.html', wisher=current_gift, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash("这本是你自己的书, 请勿向自己索要书籍") return redirect(url_for("web.book_detail", isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template("not_enough_beans.html", beans=current_user.beans) form = DriftForm(request.form) if request.method == "POST" and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, "有人想要一本书", "email/get_gift.html", wisher=current_user, gift=current_gift) return redirect(url_for("web.pending")) gifter = current_gift.user.summary return render_template("drift.html", gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash( 'This book belong to you already, you can not ask yourself for this book.' ) return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) #send_mail() # send_mail(current_gift.user.email, 'Someone ask for a book', 'email/get_gift.html', wisher=current_user, # gift=current_gift) return redirect(url_for('web.pending')) donor = current_gift.user.summary return render_template('drift.html', donor=donor, user_beans=current_user.beans, form=form)
def send_drift(gid): form = DriftForm(request.form) gift = Gift.query.filter_by(id=gid).first() if not gift: flash('没有人赠送该本书籍,请确认') my_gift = Gift.query.filter_by(id=gid, uid=current_user.id).first() if my_gift: flash('这部书是您自己赠送的,不能向他人请求') can_send_drift = current_user.can_send_drift() if not can_send_drift: return render_template('not_enough_beans.html', beans=current_user.beans) if request.method == 'POST' and form.validate(): drift = Drift() drift.generate_drift(form, gift, current_user) with db.auto_commit(): # 当前用户鱼豆-1 同时赠送者鱼豆+1 current_user.beans -= 1 gift.user.beans += 1 db.session.add(drift) html = render_template('email/get_gift.html', gift=gift, wishername=current_user.nickname) send_mail(gift.user.email, html) flash('您发送一封邮件给' + gift.user.nickname + ',请等待对方回复') return redirect(url_for('web.pending')) return render_template('drift.html', gifter=gift.user.summary, form=form, user_beans=current_user.beans)
def send_drift(gid): gift = Gift.query.get_or_404(gid) if gift.is_myself_gift(current_user.id): return redirect(url_for('web.book_detail', isbn=gift.isbn)) if not current_user.can_send_drift(): return render_template('not_enough_beans.html', beans=current_user.beans) wtform = DriftForm(request.form) if request.method == 'POST' and wtform.validate(): drift = Drift() drift.save_to_drift(wtform, gift, current_user.id, current_user.nickname) send_mail(gift.user.email, '有人想要您上传的图书: 《' + gift.book['title'] + '》', 'email/get_gift.html', wisher=current_user, gift=gift) return redirect(url_for('web.pending')) user = User.query.filter_by(id=gift.uid).first_or_404() viewmodel = UsersSummary(user) return render_template('drift.html', gifter=viewmodel.first, user_beans=current_user.beans, form=wtform)
def send_drift(gid): """ 点击「向他们请求此书」跳转到此函数,发起一个索要书的申请 """ current_gift = Gift.query.get_or_404(gid) gifter = current_gift.user if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): sava_drift(form, current_gift) send_email(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) # 后面这些是 **kwargs return redirect(url_for('web.pending')) return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): ''' 向他人请求此书 1 判断能否请求 2 判断书籍的id 与 归属 3 请求的详情页面 4 发送邮件申请 :param gid: :return: ''' current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('这本书属于你,不能向自己所要哦!!') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) else: can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): # gid:礼物id # filter_by(id=gid, launched=True)没有下面这条语句好。下面的语句可以多判断一种状态 current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的^_^, 不能向自己索要书籍噢') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) # can = current_user.can_satisfied_wish() can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_email(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): # 1.自己不能索要自己的书 # 2.鱼豆数量要满足 # 3.每索要2本书,就要赠送一本书 from app.models.gift import Gift current_gift = Gift.query.get_or_404(gid) if current_gift.in_yourself_gift(current_user.id): flash('这本书是你自己的,不能向自己索要书籍哦') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enoformugh_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) # 发通知(短信/邮件) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('不能请求索要自己的书籍!') return redirect(url_for('web.book_detail')) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', user_beans=current_user.beans) gifter = current_gift.user.summary form = DriftForm(request.form) if request.method == 'POST' and form.validate(): flag = save_drift(form, current_gift) if flag: send_mail(current_gift.user.email, '有人想要你的书《' + current_gift.book['title'] + '》', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) else: flash('数据保存出错') return render_template('404.html') return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): """ 发送鱼漂,请求书籍 :param gid: :return: """ current_gift = Gift.query.get_or_404(gid) # 自己不能向自己请求书籍 if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的^_^,不能向自己索要书籍嗷~~') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) # 判断鱼豆以及索取和赠送关系是否满足条件 can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) # 输入的参数校验 form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): form = DriftForm(request.form) current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的') return redirect(url_for('views.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) if request.method == 'POST' and form.validate(): save_dirft(form, current_gift) try: flash("提交成功") except: flash("请确认信息全部填写") send_email(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的^-^,不能向自己索要书籍噢') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): """ 向他人请求此书 1、此书不能是你自己的书 2、鱼豆>=1 3、赠送书籍次数>=索要书籍次数*2 """ current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('不能向自己索要书籍哦') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) gifter = current_gift.user.summary form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) # send_mail(current_gift.user.email, '鱼漂图书请求', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): '''发起一次交易请求。''' current_gift = Gift.query.get_or_404(gid) # 防止用户自己向自己发起交易 if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的,不能向自己索要书籍喔~') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) # 判断拾光豆等条件是否满足 if not current_user.can_send_drift(): return render_template('web/not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_email(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('web/drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_your_own_book(current_user.id): flash('这本书是你自己的...') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) has_given_enough_books = current_user.can_send_drift() if not has_given_enough_books: flash('鱼豆不足或者你需要送出一本书!') return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_email(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) return render_template('drift.html', gifter=current_gift.user.summary, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('This book is yours. Cannot request book from yourself') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) # form validation form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) # remind the user: email send_mail(current_gift.user.email, 'Someone Wants A Book', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) # get current user summary gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): # 发起索要图书请求 # 1.检查是不是自己的 # 2.检查鱼豆是否大于1 # 3.是否满足,成功索要两本书,必须成功送出一本书 gift = Gift.query.filter_by(id=gid).first_or_404() if gift.is_myself_gift(current_user.id): flash('这本书是你自己的^_^, 不能向自己索要书籍噢') return redirect(url_for('web.book_detail', isbn=gift.isbn)) if not current_user.can_send_drift(): return render_template('not_enough_beans.html', beans=current_user.beans) wtform = DriftForm(request.form) # 步入正文 if request.method == 'POST' and wtform.validate(): drift = Drift() drift.save_to_drift(wtform, gift, current_user.id, current_user.nickname) send_mail(gift.user.email, '有人想要您上传的图书: 《' + gift.book['title'] + '》', 'email/get_gift.html', wisher=current_user, gift=gift) return redirect(url_for('web.pending')) user = User.query.filter_by(id=gift.uid).first_or_404() viewmodel = UsersSummary(user) return render_template('drift.html', gifter=viewmodel.first, user_beans=current_user.beans, form=wtform)
def send_drift(gid): my_gift = Gift.query.get_or_404(gid) if my_gift.is_your_gift(current_user.id): flash("这本书就是你的,无法自我请求") return redirect(url_for('web.book_detail', isbn=my_gift.isbn)) if not current_user.can_send_drift(): return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, my_gift) return redirect(url_for('web.pending')) gifter = my_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): gift = Gift.query.get(gid) if gift: if gift.is_your_gift(current_user.id): flash("此书是你自己的书阿!!!!!!") return redirect(url_for('web.book_detail', isbn=gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.args) if request.method.lower() == 'post' and form.validate(): save_drift(form, gift) gifter = gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): """ 向他人请求书籍,如果满足3个条件就可以填写数据完成交易: 1 自己不能向自己请求书籍(判断当前的礼物是不是自己的) 2 自己鱼豆的数量必须大于1(让用户多上传) 3 每索取两本图书,自己必须送出一本图书(让用户之间多交易) 4 满足以上条件,则进行保存 :param gid:传入gid :return:跳转到交易成功页面 """ mygift = Gift.query.get_or_404(gid) title = Gift.book(mygift.isbn)['title'] if request.method == "GET": if mygift.uid == current_user.id: flash('亲,自己不能向自己赠送书籍哦,请不要调皮!') return redirect(url_for('web.book_detail', isbn=mygift.isbn)) if current_user.beans <= 1: flash('亲,您的鱼豆数量小于1,每上传一本书籍可以增加0.5个鱼豆哦!') return redirect(url_for('web.book_detail', isbn=mygift.isbn)) if current_user.can_send_drift(): # 不采用viewmodel,利用直接返回字典的方式来进行查询 gifter = mygift.user.summary # 如果用户能发起交易,则跳转到鱼漂页面 return render_template('drift.html', gifter=gifter, user_beans=current_user.beans) else: # 否则判断为鱼豆不够,不能发起交易 return render_template('not_enough_beans.html', beans=current_user.beans) if request.method == "POST": drift_form = DriftForm(request.form) flag = drift_form.validate() if drift_form.validate(): save_drift(drift_form, mygift) # 成功请求书籍以后,向书籍的所有者发送一封电子邮件 send_email(mygift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=mygift, title=title) flash('已有一封邮件发送到赠书者的邮箱,请耐心等待哦!') return redirect(url_for('web.pending')) return redirect(url_for('web.index'))
def send_drift(gid): current_gift = Gift.query.first_or_404() if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的,不能像自己索要书籍哦') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) return redirect(url_for('web.pending')) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_own_gift(current_user.id): flash("这是你自己的书,不需要索要") return redirect(url_for("web.book_detail", isbn= current_gift.isbn)) if Drift.query.filter_by(requester_id=current_user.id, gifter_id = current_gift.uid, isbn = current_gift.isbn).first(): flash("你已向对方发送过请求了,请不要重复发送") return redirect(url_for("web.book_detail", isbn=current_gift.isbn)) if not current_user.can_send_drift(): return render_template("not_enough_beans.html", beans = current_user.beans) form = DriftForm(request.form) if request.method == "POST" and form.validate(): save_drift(form, current_gift) send_mail(current_gift.user.email, "有人想要一本书", "email/get_gift.html", wisher= current_user, gift = current_gift) return redirect(url_for("web.pending")) gifterSummary = current_gift.user.summary return render_template("drift.html", gifter = gifterSummary, user_beans = current_user.beans, form=form)
def send_drift(gid): """ 1. 获取当前索要的礼物的信息 2. 自己不能向自己请求书籍 is_yourself_gift 3. 鱼豆必须足够(大于等于1) 4. 每次索取一本书自己必须送出一本书 """ current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的,不能向自己索要书籍') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, beans=current_user.beans)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) # 检测是否能够发起交易: # 1 自己不能向自己索要书籍 # 2 鱼豆数量必须足够 # 3 每索取两本书, 必须送出一本书 if current_gift.is_yourself_gift(current_user.id): flash('这本书是你自己的, 不能向自己索要书籍哦.') return redirect(url_for('web.book_detail', id=current_gift.book_id)) can = current_user.can_send_drift() if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): from app.mylib.email import send_mail save_drift(form, current_gift) send_mail(current_gift.user.email, '有人想要一本书', 'email/get_gift.html', wisher=current_user, gift=current_gift) gifter = current_gift.user.summary return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_gift.id): flash("这本书是你自己的,不能向自己索要书籍") return redirect(url_for("web.book_detail", isbn=current_gift.isbn)) can = current_user.can_send_drift() if not can: return render_template("not_enough_beans.html", beans=current_user.beans) form = DriftForm(request.form) if request.method == "POST": if form.validate(): save_drift(form, current_gift) send_email( current_gift.user.email, "有人想要一本书", "email/get_gift.html", wisher=current_user, gift=current_gift, ) wish = Wish.query.filter_by(uid=current_user.id, isbn=current_gift.isbn).first() if not wish: with db.auto_commit(): wish = Wish() wish.isbn = current_gift.isbn wish.uid = current_user.id db.session.add(wish) return redirect(url_for("web.pending")) gifter = current_gift.user.summary return render_template("drift.html", gifter=gifter, user_beans=current_user.beans, form=form)
def send_drift(gid): current_gift = Gift.query.get_or_404(gid) if current_gift.is_yourself_gift(current_user.id): #判断 自己不能赠送给自己 flash('这本书是你自己的^^,不能向自己索要书籍哦') return redirect(url_for('web.book_detail', isbn=current_gift.isbn)) can = current_user.can_send_drift() #判断 鱼豆必须足够(大于等于1)/每索取两本书,自己必须送出一本书 if not can: return render_template('not_enough_beans.html', beans=current_user.beans) form = DriftForm(request.form) if request.method == 'POST' and form.validate(): #保存到数据库 save_drift(form, current_gift) flash("提交成功!") gifter = current_gift.user.summary #获得赠送者的相关信息 return render_template('drift.html', gifter=gifter, user_beans=current_user.beans, form=form)