Esempio n. 1
0
def dashboard():
    """Display the group purchase dashboard."""
    if not login.current_user.purchase_group:
        return flask.render_template("group_purchase/dashboard.html")

    return flask.render_template(
        "group_purchase/dashboard.html",
        ticket_info=purchase_logic.get_group_ticket_info(login.current_user),
    )
def update_request():
    """Update a group purchase request."""
    if flask.request.method != 'POST':
        return flask.redirect(flask.request.referrer or
                              flask.url_for('group_purchase.dashboard'))

    ticket_info = purchase_logic.get_group_ticket_info(login.current_user)

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

    flashes = purchase_logic.validate_tickets(ticket_info, num_tickets)

    if flashes:
        for flash in flashes:
            flask.flash(flash, 'error')

        return flask.redirect(flask.request.referrer or
                              flask.url_for('group_purchase.dashboard'))

    existing_requests = {
        request.ticket_type_slug: request
        for request in login.current_user.group_purchase_requests
    }

    for slug, request in existing_requests.iteritems():
        if slug not in num_tickets or num_tickets[slug] == 0:
            DB.session.delete(request)

    for slug, requested in num_tickets.iteritems():
        if slug in existing_requests:
            existing_requests[slug].number_requested = requested
        else:
            DB.session.add(models.GroupPurchaseRequest(
                slug,
                requested,
                login.current_user.purchase_group,
                login.current_user
            ))

    DB.session.commit()

    APP.log_manager.log_event(
        'Updated Group Purchase Request',
        user=login.current_user,
        purchase_group=login.current_user.purchase_group
    )

    flask.flash('Your ticket request has been updated.', 'success')

    return flask.redirect(flask.url_for('group_purchase.dashboard'))
Esempio n. 3
0
def update_request():
    """Update a group purchase request."""
    if flask.request.method != 'POST':
        return flask.redirect(flask.request.referrer or
                              flask.url_for('group_purchase.dashboard'))

    ticket_info = purchase_logic.get_group_ticket_info(login.current_user)

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

    flashes = purchase_logic.validate_tickets(ticket_info, num_tickets)

    if flashes:
        for flash in flashes:
            flask.flash(flash, 'error')

        return flask.redirect(flask.request.referrer or
                              flask.url_for('group_purchase.dashboard'))

    existing_requests = {
        request.ticket_type_slug: request
        for request in login.current_user.group_purchase_requests
    }

    for slug, request in existing_requests.iteritems():
        if slug not in num_tickets or num_tickets[slug] == 0:
            DB.session.delete(request)

    for slug, requested in num_tickets.iteritems():
        if slug in existing_requests:
            existing_requests[slug].number_requested = requested
        else:
            DB.session.add(models.GroupPurchaseRequest(
                slug,
                requested,
                login.current_user.purchase_group,
                login.current_user
            ))

    DB.session.commit()

    APP.log_manager.log_event(
        'Updated Group Purchase Request',
        user=login.current_user,
        purchase_group=login.current_user.purchase_group
    )

    flask.flash('Your ticket request has been updated.', 'success')

    return flask.redirect(flask.url_for('group_purchase.dashboard'))
Esempio n. 4
0
def dashboard():
    """Display the group purchase dashboard."""
    if not login.current_user.purchase_group:
        return flask.render_template(
            'group_purchase/dashboard.html'
        )

    return flask.render_template(
        'group_purchase/dashboard.html',
        ticket_info=purchase_logic.get_group_ticket_info(login.current_user)
    )