コード例 #1
0
ファイル: tickets.py プロジェクト: mokele/Website
def tickets_choose():
    form = TicketAmountsForm(request.form)

    if not form.types:
        for tt in TicketType.query.order_by(TicketType.order).all():
            form.types.append_entry()
            form.types[-1].type_id.data = tt.id

    if current_user.is_authenticated():
        prepays = current_user.tickets.filter_by(type=TicketType.bycode("prepay"), paid=True).count()
        fulls = current_user.tickets.join(TicketType).filter(TicketType.code.like("full%")).count()
        if fulls >= prepays:
            prepays = 0
    else:
        prepays = 0
        fulls = 0

    token_tts = TicketToken.types(session.get("ticket_token"))
    token_only = ["full_ucl", "full_hs", "full_make", "full_adafruit", "full_hackaday", "full_boingboing", "full_dp"]

    for f in form.types:
        tt = TicketType.query.get(f.type_id.data)
        f._type = tt

        limit = tt.user_limit(current_user)

        values = range(limit + 1)
        if tt.code == "prepay":
            values = []
        elif tt.code == "full_prepay":
            assert prepays <= limit
            values = [prepays]
        elif tt.code in token_only and tt not in token_tts:
            values = []
        elif tt.code == "full":
            if token_tts:
                values = []

        f.amount.values = values
        f._any = any(values)

    if request.method == "POST" and form.validate():

        basket = []
        for f in form.types:
            if f.amount.data:
                tt = f._type

                if tt.code in token_only and tt not in token_tts:
                    if f.amount.data:
                        flash("Ticket type %s is not currently available")
                    return redirect(url_for("tickets_choose"))

                app.logger.info("Adding %s %s tickets to basket", f.amount.data, tt.name)
                basket += [tt.id] * f.amount.data

        if basket:
            session["basket"] = basket

            if current_user.is_authenticated():
                return redirect(url_for("tickets_info"))
            else:
                return redirect(url_for("signup", next=url_for("tickets_info")))

    return render_template("tickets-choose.html", form=form)
コード例 #2
0
ファイル: tickets.py プロジェクト: HughePaul/Website
def tickets_choose():
    if ticket_cutoff():
        return render_template("tickets-cutoff.html")
    form = TicketAmountsForm(request.form)

    if not form.types:
        for tt in TicketType.query.order_by(TicketType.order).all():
            form.types.append_entry()
            form.types[-1].type_id.data = tt.id

    if current_user.is_authenticated():
        prepays = current_user.tickets. \
            filter_by(type=TicketType.bycode('prepay'), paid=True). \
            count()
        fulls = current_user.tickets.join(TicketType). \
            filter(TicketType.code.like('full%')). \
            count()
        if fulls >= prepays:
            prepays = 0
    else:
        prepays = 0
        fulls = 0

    token_tts = TicketToken.types(session.get('ticket_token'))
    token_only = ['full_ucl', 'full_hs', 'full_make', 'full_adafruit',
                    'full_hackaday', 'full_boingboing', 'full_dp']

    for f in form.types:
        tt = TicketType.query.get(f.type_id.data)
        f._type = tt

        limit = tt.user_limit(current_user)

        values = range(limit + 1)
        if tt.code == 'prepay':
            values = []
        elif tt.code == 'full_prepay':
            assert prepays <= limit
            values = [prepays]
        elif tt.code in token_only and tt not in token_tts:
            values = []
        elif tt.code == 'full':
            if token_tts:
                values = []

        f.amount.values = values
        f._any = any(values)


    if request.method == 'POST' and form.validate():

        basket = []
        for f in form.types:
            if f.amount.data:
                tt = f._type

                if tt.code in token_only and tt not in token_tts:
                    if f.amount.data:
                        flash('Ticket type %s is not currently available')
                    return redirect(url_for('tickets_choose'))

                app.logger.info('Adding %s %s tickets to basket', f.amount.data, tt.name)
                basket += [tt.id] * f.amount.data

        if basket:
            session['basket'] = basket

            if current_user.is_authenticated():
                return redirect(url_for('tickets_info'))
            else:
                return redirect(url_for('signup', next=url_for('tickets_info')))

    return render_template("tickets-choose.html", form=form)