Ejemplo n.º 1
0
def send_drift(gid):
    gift = Gift.query.get_or_404(gid)
    # 对礼物进行检查
    if gift.is_yours_gift(current_user.id):
        flash("自己不能向自己请求书籍")
        return redirect(url_for('web.book_detail', gift.isbn))
    # 对用户进行检查
    can = current_user.can_save_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, gift)
        send_email(gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=gift)
        return redirect(url_for('web.pending'))
    gifter = gift.user.summary
    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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('web.book_detail', isbn=current_gift.isbn))

    if not current_user.can_send_gift():
        return render_template("not_enough_beans.html",
                               beans=current_user.beans)
    gifter = current_gift.user.summary
    if request.method == "POST" and form.validate():
        drift = Drift()
        drift.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=gifter,
                           user_beans=current_user.beans,
                           form=form)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
def send_drift(gid):
    current_gift = Gift.query.filter_by(id=gid).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_satisfied_wish()

    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)

    drift_form = DriftForm(request.form)

    if request.method == 'POST':
        if drift_form.validate():
            save_a_drift(drift_form, current_gift)
            return redirect(url_for('web.drift:pending'))

    gifter = current_gift.user.summary

    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=drift_form)
Ejemplo n.º 11
0
def send_drift(gid):
    # filter_by(id=gid, launched=True)没有下面这条语句好。下面的语句可以多判断一种状态
    current_gift = Gift.query.get_or_404(gid)
    # if current_gift.launched:
    #     flash('这本书正处于交易状态,暂时不可以索要')
    #     return redirect(url_for('web.book_detail', isbn=current_gift.isbn))
    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()
    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)
    drift_form = DriftForm(request.form)
    if request.method == 'POST':
        if drift_form.validate():
            save_drift(drift_form, current_gift)
            return redirect(url_for('web.pending'))

    # gift = Gift.query.filter(Gift.id == gid).first_or_404()
    gifter = current_gift.user.summary
    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=drift_form)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
def send_drift(gid):
    # filter_by(id=gid, launched=True)没有下面这条语句好。下面的语句可以多判断一种状态
    current_gift = Gift.query.get_or_404(gid)
    # if current_gift.launched:
    #     flash('这本书正处于交易状态,暂时不可以索要')
    #     return redirect(url_for('web.book_detail', isbn=current_gift.isbn))
    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()
    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)
    drift_form = DriftForm(request.form)
    if request.method == 'POST':
        if drift_form.validate():
            DriftService.save_a_drift(drift_form, current_gift)
            # flash(drift_form.errors, category='drift_form_error')
            # else:
            # 反范式设计,会存储一部分冗余信息。
            # 1. 减少查询次数
            # 2. 交易记录本身就应该是历史记录,不应该动态改变
            # with db.auto_commit():
            #     drift = Drift()
            #     drift_form.populate_obj(drift)
            #     drift.gift_id = gid
            #     drift.requester_id = current_user.id
            #     drift.requester_nickname = current_user.nickname
            #     drift.gifter_nickname = current_gift.user.nickname
            #     drift.gifter_id = current_gift.user.id
            #     drift.book_title = current_gift.book.title
            #     drift.book_author = current_gift.book.author_str
            #     drift.book_img = current_gift.book.image_large
            #     db.session.add(drift)
            # send_email(current_gift.user.email, '有人想要一本书', 'email/get_gift',
            #            wisher=current_user,
            #            gift=current_gift)
            return redirect(url_for('web.pending'))
    # gift = Gift.query.filter(Gift.id == gid).first_or_404()
    gifter = current_gift.user.summary
    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=drift_form)
Ejemplo n.º 21
0
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_coins.html', coins=current_user.coins)

    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    #id没用, 是relationship来操作另一个表

    return render_template('drift.html', gifter=gifter, user_coins=current_user.coins, form=form)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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_drifts()
    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)
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
def send_drift(gid):
    current_gift = Gift.query.get_or_404(gid)
    if current_gift.send_drift_by_myself(current_user.id):
        flash("这本书是你自己的,不能向自己索要书籍")
    can = current_user.can_send_drift(current_gift)
    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)

    gifter = current_gift.user.summary
    return render_template("drift.html",
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)
Ejemplo n.º 28
0
def send_drift(gid):
    """
    首先要进行条件检测,是否满足能够交易的条件:
    1.自己不能够向自己请求书籍
    2.鱼豆必须足够
    3.每索取两本书,必须要送出一本书
    :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)

    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)