Пример #1
0
def wait():
    """Handles joining the waiting list.

    Checks if the user can join the waiting list, and processes the form to
    create the requisite waiting list entry.
    """
    wait_available = purchase_logic.wait_available(login.current_user)

    if not wait_available:
        flask.flash("You cannot join the waiting list at this time.", "info")

        return flask.redirect(flask.url_for("dashboard.dashboard_home"))

    if flask.request.method != "POST":
        return flask.render_template("purchase/wait.html",
                                     wait_available=wait_available)

    flashes = []

    num_tickets = int(flask.request.form["num_tickets"])

    if num_tickets > wait_available:
        flashes.append("You cannot wait for that many tickets")
    elif num_tickets < 1:
        flashes.append("You must wait for at least 1 ticket")

    if flashes:
        flask.flash(
            ("There were errors in your order. Please fix "
             "these and try again"),
            "error",
        )

        for msg in flashes:
            flask.flash(msg, "warning")

        return flask.render_template("purchase/wait.html",
                                     num_tickets=num_tickets,
                                     wait_available=wait_available)

    DB.session.add(models.Waiting(login.current_user, num_tickets))
    DB.session.commit()

    APP.log_manager.log_event(
        "Joined waiting list for {0} tickets".format(num_tickets),
        user=login.current_user,
    )

    flask.flash(
        ("You have been added to the waiting list for {0} ticket{1}.").format(
            num_tickets, "" if num_tickets == 1 else "s"),
        "success",
    )

    return flask.redirect(flask.url_for("dashboard.dashboard_home"))
Пример #2
0
def wait():
    """Handles joining the waiting list.

    Checks if the user can join the waiting list, and processes the form to
    create the requisite waiting list entry.
    """
    wait_available = purchase_logic.wait_available(login.current_user)

    if not wait_available:
        flask.flash('You cannot join the waiting list at this time.', 'info')

        return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    if flask.request.method != 'POST':
        return flask.render_template('purchase/wait.html',
                                     wait_available=wait_available)

    flashes = []

    num_tickets = int(flask.request.form['num_tickets'])

    if num_tickets > wait_available:
        flashes.append('You cannot wait for that many tickets')
    elif num_tickets < 1:
        flashes.append('You must wait for at least 1 ticket')

    if flashes:
        flask.flash(('There were errors in your order. Please fix '
                     'these and try again'), 'error')

        for msg in flashes:
            flask.flash(msg, 'warning')

        return flask.render_template('purchase/wait.html',
                                     num_tickets=num_tickets,
                                     wait_available=wait_available)

    DB.session.add(models.Waiting(login.current_user, num_tickets))
    DB.session.commit()

    APP.log_manager.log_event(
        'Joined waiting list for {0} tickets'.format(num_tickets),
        user=login.current_user)

    flask.flash(
        ('You have been added to the waiting list for {0} ticket{1}.').format(
            num_tickets, '' if num_tickets == 1 else 's'), 'success')

    return flask.redirect(flask.url_for('dashboard.dashboard_home'))
Пример #3
0
def purchase_home():
    """First step of the purchasing flow.

    Checks if the user can purchase tickets, and processes the purchase form.
    """
    if login.current_user.purchase_group:
        if login.current_user == login.current_user.purchase_group.leader:
            if APP.config['TICKETS_ON_SALE']:
                return flask.redirect(flask.url_for('group_purchase.checkout'))
            else:
                flask.flash(
                    (
                        'You cannot currently purchase tickets because you are '
                        'leading a purchase group. You will be able to '
                        'purchase tickets on behalf of your group when general '
                        'release starts.'
                    ),
                    'info'
                )
                return flask.redirect(flask.url_for('dashboard.dashboard_home'))
        else:
            flask.flash(
                (
                    'You cannot currently purchase tickets because you are a '
                    'member of a purchase group. Your group leader {0} will be '
                    'able to purchase tickets on behalf of your group when '
                    'general release starts.'
                ).format(login.current_user.purchase_group.leader.full_name),
                'info'
            )
            return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    ticket_info = purchase_logic.get_ticket_info(
        login.current_user
    )
    if models.Waiting.query.count() > 0 or not ticket_info.ticket_types:
        flask.flash(
            'You are not able to purchase tickets at this time.',
            'info'
        )

        if purchase_logic.wait_available(login.current_user):
            flask.flash(
                (
                    'Please join the waiting list, and you will be allocated '
                    'tickets as they become available'
                ),
                'info'
            )
            return flask.redirect(flask.url_for('purchase.wait'))
        else:
            return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    num_tickets = {
        ticket_type.slug: 0
        for ticket_type, _ in ticket_info.ticket_types
    }

    if flask.request.method == 'POST':
        for ticket_type, _ in ticket_info.ticket_types:
            num_tickets[ticket_type.slug] = int(
                flask.request.form['num_tickets_{0}'.format(ticket_type.slug)]
            )

        flashes = purchase_logic.validate_tickets(
            ticket_info,
            num_tickets
        )

        payment_method, payment_term = purchase_logic.check_payment_method(
            flashes
        )

        voucher = None
        if (
                'voucher_code' in flask.request.form and
                flask.request.form['voucher_code'] != ''
        ):
            (result, response, voucher) = validators.validate_voucher(
                flask.request.form['voucher_code'])
            if not result:
                flashes.append(
                    (
                        '{} Please clear the discount code field to continue '
                        'without using a voucher.'
                    ).format(response['message'])
                )

        postage, address = purchase_logic.check_postage(flashes)

        if flashes:
            flask.flash(
                (
                    'There were errors in your order. Please fix '
                    'these and try again'
                ),
                'error'
            )
            for msg in flashes:
                flask.flash(msg, 'warning')

            return flask.render_template(
                'purchase/purchase_home.html',
                form=flask.request.form,
                num_tickets=num_tickets,
                ticket_info=ticket_info
            )


        tickets = purchase_logic.create_tickets(
            login.current_user,
            ticket_info,
            num_tickets
        )

        if voucher is not None:
            (success, tickets, error) = voucher.apply(tickets,
                                                      login.current_user)
            if not success:
                flask.flash('Could not use voucher - ' + error, 'error')


        roundup_price = purchase_logic.check_roundup_donation(flashes)

        if roundup_price is not 0:
            roundup_donation = None

            roundup_donation = models.RoundupDonation(
                    roundup_price,
                    login.current_user,
            )

            if roundup_donation is not None:
                # Tack on the roundup donation fee to their ticket(s)
                # Entry
                tickets = roundup_donation.apply(tickets)
                DB.session.add(roundup_donation);


        DB.session.add_all(tickets)
        DB.session.commit()

        APP.log_manager.log_event(
            'Purchased Tickets',
            tickets=tickets,
            user=login.current_user
        )

        # return flask.render_template(
        #    'purchase/purchase_home.html',
        #    num_tickets=num_tickets,
        #    ticket_info=ticket_info
        # )
        return payment_logic.do_payment(
         tickets,
         postage,
         payment_method,
         payment_term,
         address
        )
    else:
        return flask.render_template(
            'purchase/purchase_home.html',
            num_tickets=num_tickets,
            ticket_info=ticket_info
        )
Пример #4
0
def wait():
    """Handles joining the waiting list.

    Checks if the user can join the waiting list, and processes the form to
    create the requisite waiting list entry.
    """
    wait_available = purchase_logic.wait_available(login.current_user)

    if not wait_available:
        flask.flash('You cannot join the waiting list at this time.', 'info')

        return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    if flask.request.method != 'POST':
        return flask.render_template(
            'purchase/wait.html',
            wait_available=wait_available
        )

    flashes = []

    num_tickets = int(flask.request.form['num_tickets'])

    if num_tickets > wait_available:
        flashes.append('You cannot wait for that many tickets')
    elif num_tickets < 1:
        flashes.append('You must wait for at least 1 ticket')

    if flashes:
        flask.flash(
            (
                'There were errors in your order. Please fix '
                'these and try again'
            ),
            'error'
        )

        for msg in flashes:
            flask.flash(msg, 'warning')

        return flask.render_template(
            'purchase/wait.html',
            num_tickets=num_tickets,
            wait_available=wait_available
        )

    DB.session.add(
        models.Waiting(
            login.current_user,
            num_tickets
        )
    )
    DB.session.commit()

    APP.log_manager.log_event(
        'Joined waiting list for {0} tickets'.format(
            num_tickets
        ),
        user=login.current_user
    )

    flask.flash(
        (
            'You have been added to the waiting list for {0} ticket{1}.'
        ).format(
            num_tickets,
            '' if num_tickets == 1 else 's'
        ),
        'success'
    )

    return flask.redirect(flask.url_for('dashboard.dashboard_home'))
Пример #5
0
def checkout():
    """Allow the group leader to purchase tickets on behalf of the group."""
    if not login.current_user.purchase_group:
        flask.flash(
            (
                'You are not currently a member of a purchase group. Please '
                'use the "Buy Tickets" link to purchase tickets individually.'
            ),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))
    elif login.current_user != login.current_user.purchase_group.leader:
        flask.flash(
            (
                'Only your group leader {0} can purchase tickets on behalf of '
                'your purchase group.'
            ).format(login.current_user.purchase_group.leader.full_name),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))
    elif not APP.config['TICKETS_ON_SALE']:
        flask.flash(
            (
                'You will only be able to purchase tickets on behalf of your '
                'purchase group when general release starts.'
            ),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))
    elif login.current_user.purchase_group.purchased:
        flask.flash(
            (
                'The tickets have already been purchased for your purchase '
                'group.'
            ),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    guest_tickets_available = purchase_logic.guest_tickets_available()

    if models.Waiting.query.count() > 0 or (
            guest_tickets_available <
            login.current_user.purchase_group.total_guest_tickets_requested
    ):
        flask.flash(
            (
                'No tickets are available for your group.'
            ),
            'info'
        )

        if purchase_logic.wait_available(login.current_user):
            flask.flash(
                (
                    'If you and your group members still want to try to obtain '
                    'tickets, you should all join the waiting list.'
                ),
                'info'
            )
            return flask.redirect(flask.url_for('purchase.wait'))
        else:
            return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    if flask.request.method != 'POST':
        return flask.render_template('group_purchase/checkout.html')

    tickets = [
        models.Ticket(
            request.requester,
            request.ticket_type.slug,
            request.ticket_type.price
        )
        for request in login.current_user.purchase_group.requests
        for _ in xrange(request.number_requested)
    ]

    DB.session.add_all(tickets)

    login.current_user.purchase_group.purchased = True

    DB.session.commit()

    APP.log_manager.log_event(
        'Completed Group Purchase',
        user=login.current_user,
        tickets=tickets,
        purchase_group=login.current_user.purchase_group
    )

    expiry_time = util.format_timedelta(APP.config['TICKET_EXPIRY_TIME'])

    for user in set(
            request.requester
            for request in login.current_user.purchase_group.requests
            if request.requester != login.current_user
    ):
        APP.email_manager.send_template(
            user.email,
            'Group Purchase Completed - Complete Payment Now!',
            'group_purchase_completed.email',
            name=user.forenames,
            group_leader=login.current_user.full_name,
            url=flask.url_for('purchase.complete_payment', _external=True),
            expiry_time=expiry_time
        )

    flask.flash('The tickets for your group have been reserved', 'success')
    flask.flash('You can now proceed to pay for your own tickets.', 'info')
    flask.flash(
        (
            'Your group members have been emailed to remind them to pay for '
            'their tickets.'
        ),
        'info'
    )
    flask.flash(
        'Any tickets not paid for within {0} will be cancelled.'.format(
            expiry_time
        ),
        'warning'
    )

    return flask.redirect(flask.url_for('purchase.complete_payment'))
Пример #6
0
def checkout():
    """Allow the group leader to purchase tickets on behalf of the group."""
    if not login.current_user.purchase_group:
        flask.flash(
            (
                'You are not currently a member of a purchase group. Please '
                'use the "Buy Tickets" link to purchase tickets individually.'
            ),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))
    elif login.current_user != login.current_user.purchase_group.leader:
        flask.flash(
            (
                'Only your group leader {0} can purchase tickets on behalf of '
                'your purchase group.'
            ).format(login.current_user.purchase_group.leader.full_name),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))
    elif not APP.config['TICKETS_ON_SALE']:
        flask.flash(
            (
                'You will only be able to purchase tickets on behalf of your '
                'purchase group when general release starts.'
            ),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))
    elif login.current_user.purchase_group.purchased:
        flask.flash(
            (
                'The tickets have already been purchased for your purchase '
                'group.'
            ),
            'info'
        )
        return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    guest_tickets_available = purchase_logic.guest_tickets_available()

    if models.Waiting.query.count() > 0 or (
            guest_tickets_available <
            login.current_user.purchase_group.total_guest_tickets_requested
    ):
        flask.flash(
            (
                'No tickets are available for your group.'
            ),
            'info'
        )

        if purchase_logic.wait_available(login.current_user):
            flask.flash(
                (
                    'If you and your group members still want to try to obtain '
                    'tickets, you should all join the waiting list.'
                ),
                'info'
            )
            return flask.redirect(flask.url_for('purchase.wait'))
        else:
            return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    if flask.request.method != 'POST':
        return flask.render_template('group_purchase/checkout.html')

    tickets = [
        models.Ticket(
            request.requester,
            request.ticket_type.slug,
            request.ticket_type.price
        )
        for request in login.current_user.purchase_group.requests
        for _ in xrange(request.number_requested)
    ]

    DB.session.add_all(tickets)

    login.current_user.purchase_group.purchased = True

    DB.session.commit()

    APP.log_manager.log_event(
        'Completed Group Purchase',
        user=login.current_user,
        tickets=tickets,
        purchase_group=login.current_user.purchase_group
    )

    expiry_time = util.format_timedelta(APP.config['TICKET_EXPIRY_TIME'])

    for user in set(
            request.requester
            for request in login.current_user.purchase_group.requests
            if request.requester != login.current_user
    ):
        APP.email_manager.send_template(
            user.email,
            'Group Purchase Completed - Complete Payment Now!',
            'group_purchase_completed.email',
            name=user.forenames,
            group_leader=login.current_user.full_name,
            url=flask.url_for('purchase.complete_payment', _external=True),
            expiry_time=expiry_time
        )

    flask.flash('The tickets for your group have been reserved', 'success')
    flask.flash('You can now proceed to pay for your own tickets.', 'info')
    flask.flash(
        (
            'Your group members have been emailed to remind them to pay for '
            'their tickets.'
        ),
        'info'
    )
    flask.flash(
        'Any tickets not paid for within {0} will be cancelled.'.format(
            expiry_time
        ),
        'warning'
    )

    return flask.redirect(flask.url_for('purchase.complete_payment'))
Пример #7
0
def purchase_home():
    """First step of the purchasing flow.

    Checks if the user can purchase tickets, and processes the purchase form.
    """
    if login.current_user.purchase_group:
        if login.current_user == login.current_user.purchase_group.leader:
            if APP.config['TICKETS_ON_SALE']:
                return flask.redirect(flask.url_for('group_purchase.checkout'))
            else:
                flask.flash(
                    ('You cannot currently purchase tickets because you are '
                     'leading a purchase group. You will be able to '
                     'purchase tickets on behalf of your group when general '
                     'release starts.'), 'info')
                return flask.redirect(
                    flask.url_for('dashboard.dashboard_home'))
        else:
            flask.flash(
                ('You cannot currently purchase tickets because you are a '
                 'member of a purchase group. Your group leader {0} will be '
                 'able to purchase tickets on behalf of your group when '
                 'general release starts.').format(
                     login.current_user.purchase_group.leader.full_name),
                'info')
            return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    ticket_info = purchase_logic.get_ticket_info(login.current_user)
    if models.Waiting.query.count() > 0 or not ticket_info.ticket_types:
        flask.flash('You are not able to purchase tickets at this time.',
                    'info')

        if purchase_logic.wait_available(login.current_user):
            flask.flash(
                ('Please join the waiting list, and you will be allocated '
                 'tickets as they become available'), 'info')
            return flask.redirect(flask.url_for('purchase.wait'))
        else:
            return flask.redirect(flask.url_for('dashboard.dashboard_home'))

    num_tickets = {
        ticket_type.slug: 0
        for ticket_type, _ in ticket_info.ticket_types
    }

    if flask.request.method == 'POST':
        for ticket_type, _ in ticket_info.ticket_types:
            num_tickets[ticket_type.slug] = int(
                flask.request.form['num_tickets_{0}'.format(ticket_type.slug)])

        flashes = purchase_logic.validate_tickets(ticket_info, num_tickets)

        payment_method, payment_term = purchase_logic.check_payment_method(
            flashes)

        voucher = None
        if ('voucher_code' in flask.request.form
                and flask.request.form['voucher_code'] != ''):
            (result, response, voucher) = validators.validate_voucher(
                flask.request.form['voucher_code'])
            if not result:
                flashes.append(
                    ('{} Please clear the discount code field to continue '
                     'without using a voucher.').format(response['message']))

        postage, address = purchase_logic.check_postage(flashes)

        if flashes:
            flask.flash(('There were errors in your order. Please fix '
                         'these and try again'), 'error')
            for msg in flashes:
                flask.flash(msg, 'warning')

            return flask.render_template('purchase/purchase_home.html',
                                         form=flask.request.form,
                                         num_tickets=num_tickets,
                                         ticket_info=ticket_info)

        tickets = purchase_logic.create_tickets(login.current_user,
                                                ticket_info, num_tickets)

        if voucher is not None:
            (success, tickets, error) = voucher.apply(tickets,
                                                      login.current_user)
            if not success:
                flask.flash('Could not use voucher - ' + error, 'error')

        roundup_price = purchase_logic.check_roundup_donation(flashes)

        if roundup_price is not 0:
            roundup_donation = None

            roundup_donation = models.RoundupDonation(
                roundup_price,
                login.current_user,
            )

            if roundup_donation is not None:
                # Tack on the roundup donation fee to their ticket(s)
                # Entry
                tickets = roundup_donation.apply(tickets)
                DB.session.add(roundup_donation)

        DB.session.add_all(tickets)
        DB.session.commit()

        APP.log_manager.log_event('Purchased Tickets',
                                  tickets=tickets,
                                  user=login.current_user)

        # return flask.render_template(
        #    'purchase/purchase_home.html',
        #    num_tickets=num_tickets,
        #    ticket_info=ticket_info
        # )
        return payment_logic.do_payment(tickets, postage, payment_method,
                                        payment_term, address)
    else:
        return flask.render_template('purchase/purchase_home.html',
                                     num_tickets=num_tickets,
                                     ticket_info=ticket_info)
Пример #8
0
def checkout():
    """Allow the group leader to purchase tickets on behalf of the group."""
    if not login.current_user.purchase_group:
        flask.flash(
            ("You are not currently a member of a purchase group. Please "
             'use the "Buy Tickets" link to purchase tickets individually.'),
            "info",
        )
        return flask.redirect(flask.url_for("dashboard.dashboard_home"))
    elif login.current_user != login.current_user.purchase_group.leader:
        flask.flash(
            ("Only your group leader {0} can purchase tickets on behalf of "
             "your purchase group.").format(
                 login.current_user.purchase_group.leader.full_name),
            "info",
        )
        return flask.redirect(flask.url_for("dashboard.dashboard_home"))
    elif not APP.config["TICKETS_ON_SALE"]:
        flask.flash(
            ("You will only be able to purchase tickets on behalf of your "
             "purchase group when general release starts."),
            "info",
        )
        return flask.redirect(flask.url_for("dashboard.dashboard_home"))
    elif login.current_user.purchase_group.purchased:
        flask.flash(
            ("The tickets have already been purchased for your purchase "
             "group."),
            "info",
        )
        return flask.redirect(flask.url_for("dashboard.dashboard_home"))

    guest_tickets_available = purchase_logic.guest_tickets_available()

    if models.Waiting.query.count() > 0 or (
            guest_tickets_available <
            login.current_user.purchase_group.total_guest_tickets_requested):
        flask.flash(("No tickets are available for your group."), "info")

        if purchase_logic.wait_available(login.current_user):
            flask.flash(
                ("If you and your group members still want to try to obtain "
                 "tickets, you should all join the waiting list."),
                "info",
            )
            return flask.redirect(flask.url_for("purchase.wait"))
        else:
            return flask.redirect(flask.url_for("dashboard.dashboard_home"))

    if flask.request.method != "POST":
        return flask.render_template("group_purchase/checkout.html")

    tickets = [
        models.Ticket(request.requester, request.ticket_type.slug,
                      request.ticket_type.price)
        for request in login.current_user.purchase_group.requests
        for _ in xrange(request.number_requested)
    ]

    DB.session.add_all(tickets)

    login.current_user.purchase_group.purchased = True

    DB.session.commit()

    APP.log_manager.log_event(
        "Completed Group Purchase",
        user=login.current_user,
        tickets=tickets,
        purchase_group=login.current_user.purchase_group,
    )

    expiry_time = util.format_timedelta(APP.config["TICKET_EXPIRY_TIME"])

    for user in set(request.requester
                    for request in login.current_user.purchase_group.requests
                    if request.requester != login.current_user):
        APP.email_manager.send_template(
            user.email,
            "Group Purchase Completed - Complete Payment Now!",
            "group_purchase_completed.email",
            name=user.forenames,
            group_leader=login.current_user.full_name,
            url=flask.url_for("purchase.complete_payment", _external=True),
            expiry_time=expiry_time,
        )

    flask.flash("The tickets for your group have been reserved", "success")
    flask.flash("You can now proceed to pay for your own tickets.", "info")
    flask.flash(
        ("Your group members have been emailed to remind them to pay for "
         "their tickets."),
        "info",
    )
    flask.flash(
        "Any tickets not paid for within {0} will be cancelled.".format(
            expiry_time),
        "warning",
    )

    return flask.redirect(flask.url_for("purchase.complete_payment"))
Пример #9
0
def purchase_home():
    """First step of the purchasing flow.

    Checks if the user can purchase tickets, and processes the purchase form.
    """
    if login.current_user.purchase_group:
        if login.current_user == login.current_user.purchase_group.leader:
            if APP.config["TICKETS_ON_SALE"]:
                return flask.redirect(flask.url_for("group_purchase.checkout"))
            else:
                flask.flash(
                    ("You cannot currently purchase tickets because you are "
                     "leading a purchase group. You will be able to "
                     "purchase tickets on behalf of your group when general "
                     "release starts."),
                    "info",
                )
                return flask.redirect(
                    flask.url_for("dashboard.dashboard_home"))
        else:
            flask.flash(
                ("You cannot currently purchase tickets because you are a "
                 "member of a purchase group. Your group leader {0} will be "
                 "able to purchase tickets on behalf of your group when "
                 "general release starts.").format(
                     login.current_user.purchase_group.leader.full_name),
                "info",
            )
            return flask.redirect(flask.url_for("dashboard.dashboard_home"))

    ticket_info = purchase_logic.get_ticket_info(login.current_user)
    if models.Waiting.query.count() > 0 or not ticket_info.ticket_types:
        flask.flash("You are not able to purchase tickets at this time.",
                    "info")

        if purchase_logic.wait_available(login.current_user):
            flask.flash(
                ("Please join the waiting list, and you will be allocated "
                 "tickets as they become available"),
                "info",
            )
            return flask.redirect(flask.url_for("purchase.wait"))
        else:
            return flask.redirect(flask.url_for("dashboard.dashboard_home"))

    num_tickets = {
        ticket_type.slug: 0
        for ticket_type, _ in ticket_info.ticket_types
    }
    addons_selected = {addon.slug: False for addon, _ in ticket_info.addons}

    if flask.request.method == "POST":
        for ticket_type, _ in ticket_info.ticket_types:
            num_tickets[ticket_type.slug] = int(
                flask.request.form["num_tickets_{0}".format(ticket_type.slug)])
        for addon, _ in ticket_info.addons:
            try:
                addons_selected[addon.slug] = (
                    flask.request.form["addon_{0}".format(
                        addon.slug)] == "Yes")
            except KeyError:
                pass

        flashes = purchase_logic.validate_tickets(ticket_info, num_tickets,
                                                  addons_selected)

        payment_method, payment_term = purchase_logic.check_payment_method(
            flashes)

        voucher = None
        if ("voucher_code" in flask.request.form
                and flask.request.form["voucher_code"] != ""):
            (result, response, voucher) = validators.validate_voucher(
                flask.request.form["voucher_code"])
            if not result:
                flashes.append(
                    ("{} Please clear the discount code field to continue "
                     "without using a voucher.").format(response["message"]))

        postage, address = purchase_logic.check_postage(flashes)

        if flashes:
            flask.flash(
                ("There were errors in your order. Please fix "
                 "these and try again"),
                "error",
            )
            for msg in flashes:
                flask.flash(msg, "warning")

            return flask.render_template(
                "purchase/purchase_home.html",
                form=flask.request.form,
                num_tickets=num_tickets,
                addons_selected=addons_selected,
                ticket_info=ticket_info,
            )

        tickets, addons = purchase_logic.create_tickets(
            login.current_user, ticket_info, num_tickets, addons_selected)

        if voucher is not None:
            (success, tickets, error) = voucher.apply(tickets,
                                                      login.current_user)
            if not success:
                flask.flash("Could not use voucher - " + error, "error")

        roundup_price = purchase_logic.check_roundup_donation(flashes)

        if roundup_price is not 0:
            roundup_donation = None

            roundup_donation = models.RoundupDonation(roundup_price,
                                                      login.current_user)

            if roundup_donation is not None:
                # Tack on the roundup donation fee to their ticket(s)
                # Entry
                tickets = roundup_donation.apply(tickets)
                DB.session.add(roundup_donation)

        DB.session.add_all(tickets)
        DB.session.add_all(addons)
        DB.session.commit()

        APP.log_manager.log_event("Purchased Tickets",
                                  tickets=tickets,
                                  user=login.current_user)

        # return flask.render_template(
        #    'purchase/purchase_home.html',
        #    num_tickets=num_tickets,
        #    ticket_info=ticket_info
        # )
        return payment_logic.do_payment(tickets, postage, payment_method,
                                        payment_term, address)
    else:
        return flask.render_template(
            "purchase/purchase_home.html",
            num_tickets=num_tickets,
            ticket_info=ticket_info,
        )