~homeworkprod/byceps

b075ac20bc84afcf543522478baff3c9a1f502fa — Jochen Kupperschmidt 3 years ago a07ce7e
Move setting of party and brand ID thread-locals to core blueprint's pre-request hook implementation
2 files changed, 14 insertions(+), 15 deletions(-)

M byceps/blueprints/core/views.py
M byceps/blueprints/party/views.py
M byceps/blueprints/core/views.py => byceps/blueprints/core/views.py +14 -1
@@ 11,6 11,7 @@ from datetime import date, datetime
from flask import g, render_template

from ... import config
from ...services.party import service as party_service
from ...util.framework.blueprint import create_blueprint
from ...util.navigation import Navigation



@@ 61,10 62,22 @@ def is_current_page(nav_item_path, current_page=None):

@blueprint.before_app_request
def provide_site_mode():
    # site mode
    site_mode = config.get_site_mode()

    g.site_mode = site_mode

    # current party and brand
    if site_mode.is_public():
        party_id = config.get_current_party_id()

        party = party_service.find_party(party_id)
        if party is None:
            raise Exception('Unknown party ID "{}".'.format(party_id))

        g.party_id = party.id
        g.brand_id = party.brand_id

    # current user
    is_admin_mode = site_mode.is_admin()
    g.current_user = authentication_blueprint_service \
        .get_current_user(is_admin_mode)

M byceps/blueprints/party/views.py => byceps/blueprints/party/views.py +0 -14
@@ 8,7 8,6 @@ byceps.blueprints.party.views

from flask import g

from ...config import get_current_party_id
from ...services.party import service as party_service
from ...services.ticketing import attendance_service
from ...util.framework.blueprint import create_blueprint


@@ 18,19 17,6 @@ from ...util.framework.templating import templated
blueprint = create_blueprint('party', __name__)


@blueprint.before_app_request
def before_request():
    party_id = get_current_party_id()

    party = party_service.find_party(party_id)

    if party is None:
        raise Exception('Unknown party ID "{}".'.format(party_id))

    g.party_id = party.id
    g.brand_id = party.brand_id


@blueprint.route('/info')
@templated
def info():