~homeworkprod/byceps

e45429167ba7db42936ae92feb8c19c135743e02 — Jochen Kupperschmidt 4 years ago c68c1ee
Provide brand ID on `g` thread-local
M byceps/blueprints/authentication/views.py => byceps/blueprints/authentication/views.py +3 -5
@@ 147,14 147,12 @@ def login():
            abort(403)

    if not in_admin_mode:
        brand_id = g.party.brand_id

        terms_version = terms_service.find_current_version(brand_id)
        terms_version = terms_service.find_current_version(g.brand_id)

        if not terms_version:
            raise Exception(
                'No terms of service defined for brand "{}", denying login.'
                .format(brand_id))
                .format(g.brand_id))

        if not terms_service.has_user_accepted_version(user.id, terms_version.id):
            verification_token = verification_token_service \


@@ 252,7 250,7 @@ def request_password_reset():
                    'noch nicht bestätigt.', screen_name)
        return redirect_to('user.request_email_address_confirmation_email')

    password_reset_service.prepare_password_reset(user, g.party.brand_id)
    password_reset_service.prepare_password_reset(user, g.brand_id)

    flash_success(
        'Ein Link zum Setzen eines neuen Passworts für den Benutzernamen "{}" '

M byceps/blueprints/board/views.py => byceps/blueprints/board/views.py +5 -12
@@ 49,9 49,8 @@ blueprint.add_app_template_filter(render_html, 'bbcode')
@templated
def category_index():
    """List categories."""
    brand_id = g.party.brand_id

    categories = board_category_service.get_categories_with_last_updates(brand_id)
    categories = board_category_service.get_categories_with_last_updates(
        g.brand_id)

    user = g.current_user



@@ 70,9 69,7 @@ def category_index():
@templated
def category_view(slug, page):
    """List latest topics in the category."""
    brand_id = g.party.brand_id

    category = board_category_service.find_category_by_slug(brand_id, slug)
    category = board_category_service.find_category_by_slug(g.brand_id, slug)
    if category is None:
        abort(404)



@@ 148,13 145,11 @@ def topic_view(topic_id, page):

    is_last_page = not postings.has_next

    brand_id = g.party.brand_id

    creator_ids = {posting.creator_id for posting in postings.items}
    badges_by_user_id = badge_service.get_badges_for_users(creator_ids,
                                                           featured_only=True)
    badges_by_user_id = _select_global_and_brand_badges(badges_by_user_id,
                                                        brand_id)
                                                        g.brand_id)

    context = {
        'topic': topic,


@@ 303,9 298,7 @@ def topic_moderate_form(topic_id):
    """Show a form to moderate the topic."""
    topic = _get_topic_or_404(topic_id)

    brand_id = g.party.brand_id

    categories = board_category_service.get_categories_excluding(brand_id,
    categories = board_category_service.get_categories_excluding(g.brand_id,
        topic.category_id)

    return {

M byceps/blueprints/news/views.py => byceps/blueprints/news/views.py +2 -5
@@ 21,10 21,9 @@ blueprint = create_blueprint('news', __name__)
@templated
def index(page):
    """Show a page of news items."""
    brand_id = g.party.brand_id
    items_per_page = _get_items_per_page_value()

    items = news_service.get_items_paginated(brand_id, page, items_per_page)
    items = news_service.get_items_paginated(g.brand_id, page, items_per_page)

    return {
        'items': items,


@@ 36,9 35,7 @@ def index(page):
@templated
def view(slug):
    """Show a single news item."""
    brand_id = g.party.brand_id

    item = news_service.find_item_by_slug(brand_id, slug)
    item = news_service.find_item_by_slug(g.brand_id, slug)

    if item is None:
        abort(404)

M byceps/blueprints/newsletter/views.py => byceps/blueprints/newsletter/views.py +2 -4
@@ 21,9 21,8 @@ blueprint = create_blueprint('newsletter', __name__)
@respond_no_content
def subscribe():
    user = _get_current_user_or_404()
    brand_id = g.party.brand_id

    newsletter_service.subscribe(user.id, brand_id)
    newsletter_service.subscribe(user.id, g.brand_id)

    flash_success('Du hast dich zum Newsletter angemeldet.')



@@ 32,9 31,8 @@ def subscribe():
@respond_no_content
def unsubscribe():
    user = _get_current_user_or_404()
    brand_id = g.party.brand_id

    newsletter_service.unsubscribe(user.id, brand_id)
    newsletter_service.unsubscribe(user.id, g.brand_id)

    flash_success('Du hast dich vom Newsletter abgemeldet.')


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

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


@blueprint.route('/info')


@@ 43,8 44,7 @@ def info():
@templated
def archive():
    """Show archived parties."""
    brand_id = g.party.brand_id
    archived_parties = party_service.get_archived_parties_for_brand(brand_id)
    archived_parties = party_service.get_archived_parties_for_brand(g.brand_id)

    party_ids = {party.id for party in archived_parties}
    attendees_by_party_id = attendance_service.get_attendees_by_party(party_ids)

M byceps/blueprints/terms/views.py => byceps/blueprints/terms/views.py +1 -3
@@ 25,9 25,7 @@ blueprint = create_blueprint('terms', __name__)
@templated
def view_current():
    """Show the current version of this brand's terms and conditions."""
    brand_id = g.party.brand_id

    version = terms_service.get_current_version(brand_id)
    version = terms_service.get_current_version(g.brand_id)

    return {
        'version': version,

M byceps/blueprints/user/views.py => byceps/blueprints/user/views.py +6 -10
@@ 97,9 97,8 @@ def view_current():
        abort(404)

    if get_site_mode().is_public():
        brand_id = g.party.brand_id
        subscribed_to_newsletter = newsletter_service.is_subscribed(user.id,
                                                                    brand_id)
        subscribed_to_newsletter = newsletter_service.is_subscribed(
            user.id, g.brand_id)
    else:
        subscribed_to_newsletter = None



@@ 134,8 133,7 @@ def create_form(erroneous_form=None):
        flash_error('Das Erstellen von Benutzerkonten ist deaktiviert.')
        abort(403)

    brand_id = g.party.brand_id
    terms_version = terms_service.get_current_version(brand_id)
    terms_version = terms_service.get_current_version(g.brand_id)

    form = erroneous_form if erroneous_form \
        else UserCreateForm(terms_version_id=terms_version.id)


@@ 173,16 171,14 @@ def create():
            'Diese E-Mail-Adresse ist bereits einem Benutzerkonto zugeordnet.')
        return create_form(form)

    brand_id = g.party.brand_id

    terms_version = terms_service.find_version(terms_version_id)
    if terms_version.brand_id != brand_id:
    if terms_version.brand_id != g.brand_id:
        abort(400, 'Die AGB-Version gehört nicht zu dieser Veranstaltung.')

    try:
        user = user_creation_service.create_user(screen_name, email_address,
                                                 password, first_names,
                                                 last_name, brand_id,
                                                 last_name, g.brand_id,
                                                 terms_version.id,
                                                 subscribe_to_newsletter)
    except user_creation_service.UserCreationFailed:


@@ 237,7 233,7 @@ def request_email_address_confirmation_email():
    verification_token = verification_token_service \
        .find_or_create_for_email_address_confirmation(user.id)
    user_service.send_email_address_confirmation_email(
        user, verification_token, g.party.brand_id)
        user, verification_token, g.brand_id)

    flash_success(
        'Der Link zur Bestätigung der für den Benutzernamen "{}" '

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.brand_id = g.party.brand_id

    with appcontext_pushed.connected_to(handler, app):
        yield