~homeworkprod/byceps

35b259078a130b07669525ee1effd0a05d45564b — Jochen Kupperschmidt 2 years ago 3357d48
Qualify access to static URL prefix constants via module
2 files changed, 9 insertions(+), 12 deletions(-)

M app.py
M byceps/application.py
M app.py => app.py +5 -6
@@ 11,8 11,7 @@ from pathlib import Path
from werkzeug.wsgi import SharedDataMiddleware

from byceps.application import create_app, init_app
from byceps.config import STATIC_URL_PREFIX_BRAND, STATIC_URL_PREFIX_GLOBAL, \
    STATIC_URL_PREFIX_PARTY, STATIC_URL_PREFIX_SITE
from byceps import config
from byceps.database import db
from byceps.services.brand.models.brand import Brand
from byceps.services.party.models.party import Party


@@ 39,9 38,9 @@ def _generate_static_files_exports():
    """Yield static files exports."""
    # global, brand-specific, and party-specific files
    for url_path, config_key in [
        (STATIC_URL_PREFIX_GLOBAL, 'PATH_GLOBAL'),
        (STATIC_URL_PREFIX_BRAND, 'PATH_BRAND'),
        (STATIC_URL_PREFIX_PARTY, 'PATH_PARTY'),
        (config.STATIC_URL_PREFIX_GLOBAL, 'PATH_GLOBAL'),
        (config.STATIC_URL_PREFIX_BRAND, 'PATH_BRAND'),
        (config.STATIC_URL_PREFIX_PARTY, 'PATH_PARTY'),
    ]:
        path = app.config.get(config_key)
        if path:


@@ 50,7 49,7 @@ def _generate_static_files_exports():
    # site-specific files
    site_id = app.config.get('SITE_ID')
    site_files_path = Path('sites') / site_id / 'static'
    yield STATIC_URL_PREFIX_SITE, str(site_files_path)
    yield config.STATIC_URL_PREFIX_SITE, str(site_files_path)


if app.env == 'development':

M byceps/application.py => byceps/application.py +4 -6
@@ 13,8 13,6 @@ import jinja2

from .blueprints.snippet.init import add_routes_for_snippets
from . import config, config_defaults
from .config import STATIC_URL_PREFIX_BRAND, STATIC_URL_PREFIX_GLOBAL, \
    STATIC_URL_PREFIX_PARTY, STATIC_URL_PREFIX_SITE
from .database import db
from . import email
from .redis import redis


@@ 137,10 135,10 @@ def _get_blueprints(app):
def _add_static_file_url_rules(app):
    """Add URL rules to for static files."""
    for rule_prefix, endpoint in [
        (STATIC_URL_PREFIX_GLOBAL, 'global_file'),
        (STATIC_URL_PREFIX_BRAND, 'brand_file'),
        (STATIC_URL_PREFIX_PARTY, 'party_file'),
        (STATIC_URL_PREFIX_SITE, 'site_file'),
        (config.STATIC_URL_PREFIX_GLOBAL, 'global_file'),
        (config.STATIC_URL_PREFIX_BRAND, 'brand_file'),
        (config.STATIC_URL_PREFIX_PARTY, 'party_file'),
        (config.STATIC_URL_PREFIX_SITE, 'site_file'),
    ]:
        rule = rule_prefix + '/<path:filename>'
        app.add_url_rule(rule,