~homeworkprod/byceps

e5d7558adeb6016d1fb98708764df566cfcc510d — Jochen Kupperschmidt 4 years ago e454291
Provide party ID on `g` thread-local
M byceps/blueprints/orga_team/views.py => byceps/blueprints/orga_team/views.py +1 -1
@@ 26,7 26,7 @@ blueprint = create_blueprint('orga_team', __name__)
@templated
def index():
    """List all organizers for the current party."""
    memberships = orga_team_service.get_memberships_for_party(g.party.id)
    memberships = orga_team_service.get_memberships_for_party(g.party_id)

    users_by_id = _get_users_by_id(memberships)


M byceps/blueprints/party/views.py => byceps/blueprints/party/views.py +1 -0
@@ 28,6 28,7 @@ def before_request():
        raise Exception('Unknown party ID "{}".'.format(party_id))

    g.party = party.to_tuple()
    g.party_id = party.id
    g.brand_id = party.brand_id



M byceps/blueprints/seating/views.py => byceps/blueprints/seating/views.py +2 -2
@@ 21,7 21,7 @@ blueprint = create_blueprint('seating', __name__)
@templated
def index():
    """List areas."""
    areas = seating_area_service.get_areas_for_party(g.party.id)
    areas = seating_area_service.get_areas_for_party(g.party_id)

    return {
        'areas': areas,


@@ 32,7 32,7 @@ def index():
@templated
def view_area(slug):
    """View area."""
    area = seating_area_service.find_area_for_party_by_slug(g.party.id, slug)
    area = seating_area_service.find_area_for_party_by_slug(g.party_id, slug)
    if area is None:
        abort(404)


M byceps/blueprints/shop/orders/views.py => byceps/blueprints/shop/orders/views.py +1 -2
@@ 42,7 42,6 @@ def index():
def view(order_id):
    """Show a single order (if it belongs to the current user and party)."""
    current_user = g.current_user
    current_party = g.party

    order = order_service.find_order_with_details(order_id)



@@ 55,7 54,7 @@ def view(order_id):
        # Order was not placed by the current user.
        abort(404)

    if order.party_id != current_party.id:
    if order.party_id != g.party_id:
        # Order was not placed by the current user.
        abort(404)


M byceps/blueprints/shop_order/views.py => byceps/blueprints/shop_order/views.py +5 -5
@@ 32,7 32,7 @@ blueprint = create_blueprint('shop_order', __name__)
def order_form(erroneous_form=None):
    """Show a form to order articles."""
    article_compilation = article_service \
        .get_article_compilation_for_orderable_articles(g.party.id)
        .get_article_compilation_for_orderable_articles(g.party_id)

    if article_compilation.is_empty():
        flash_error('Es sind keine Artikel verfügbar.')


@@ 60,7 60,7 @@ def order_form(erroneous_form=None):
def order():
    """Order articles."""
    article_compilation = article_service \
        .get_article_compilation_for_orderable_articles(g.party.id)
        .get_article_compilation_for_orderable_articles(g.party_id)

    if article_compilation.is_empty():
        flash_error('Es sind keine Artikel verfügbar.')


@@ 112,7 112,7 @@ def order_single_form(article_id, erroneous_form=None):
            'article': None,
        }

    if order_service.has_user_placed_orders(user.id, g.party.id):
    if order_service.has_user_placed_orders(user.id, g.party_id):
        flash_error('Du kannst keine weitere Bestellung aufgeben.')
        return {
            'form': form,


@@ 151,7 151,7 @@ def order_single(article_id):

    user = g.current_user._user

    if order_service.has_user_placed_orders(user.id, g.party.id):
    if order_service.has_user_placed_orders(user.id, g.party_id):
        flash_error('Du kannst keine weitere Bestellung aufgeben.')
        return order_single_form(article.id)



@@ 192,7 192,7 @@ def _get_article_or_404(article_id):
def _submit_order(orderer, cart):
    payment_method = PaymentMethod.bank_transfer

    return order_service.create_order(g.party.id, orderer, payment_method, cart)
    return order_service.create_order(g.party_id, orderer, payment_method, cart)


def _flash_order_success(order):

M byceps/blueprints/snippet/templating.py => byceps/blueprints/snippet/templating.py +1 -1
@@ 57,7 57,7 @@ def render_snippet_as_partial(name, *, ignore_if_unknown=False):
    return the result.
    """
    current_version = snippet_service \
        .find_current_version_of_snippet_with_name(g.party.id, name)
        .find_current_version_of_snippet_with_name(g.party_id, name)

    if current_version is None:
        if ignore_if_unknown:

M byceps/blueprints/snippet/views.py => byceps/blueprints/snippet/views.py +1 -1
@@ 63,4 63,4 @@ def _find_current_snippet_version(name):
    `None` if it does not exist.
    """
    return snippet_service.find_current_version_of_snippet_with_name(
        g.party.id, name)
        g.party_id, name)

M byceps/blueprints/user/views.py => byceps/blueprints/user/views.py +2 -2
@@ 49,10 49,10 @@ def view(user_id):
    badges_with_awarding_quantity = badge_service.get_badges_for_user(user.id)

    orga_team_membership = orga_team_service.find_membership_for_party(user.id,
        g.party.id)
        g.party_id)

    current_party_tickets = ticket_service.find_tickets_used_by_user(user.id,
        g.party.id)
        g.party_id)

    attended_parties = attendance_service.get_attended_parties(user.id)
    attended_parties.sort(key=attrgetter('starts_at'), reverse=True)

M byceps/blueprints/user_badge/views.py => byceps/blueprints/user_badge/views.py +2 -2
@@ 43,8 43,8 @@ def view(slug):
    recipients = user_service.find_users(recipient_ids)

    # Find out which user is an organizer of this party.
    orga_ids = orga_team_service.select_orgas_for_party(recipient_ids,
                                                        g.party.id)
    orga_ids = orga_team_service.select_orgas_for_party(
        recipient_ids, g.party_id)

    # Update organizer flags.
    recipients = {r._replace(is_orga=(r.id in orga_ids)) for r in recipients}

M tests/helpers.py => tests/helpers.py +1 -0
@@ 28,6 28,7 @@ def app_context(*, config_filename=CONFIG_FILENAME_TEST_PARTY):
def current_party_set(app, party):
    def handler(sender, **kwargs):
        g.party = party.to_tuple()
        g.party_id = g.party.id
        g.brand_id = g.party.brand_id

    with appcontext_pushed.connected_to(handler, app):