~homeworkprod/byceps

3357d485283e4face391e439775b4ff68b3dba1d — Jochen Kupperschmidt 4 years ago 8fdbe1a
Add `site_file` URL rule
3 files changed, 12 insertions(+), 2 deletions(-)

M app.py
M byceps/application.py
M byceps/config.py
M app.py => app.py +9 -1
@@ 6,11 6,13 @@ application instance
:License: Modified BSD, see LICENSE for details.
"""

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_PARTY, STATIC_URL_PREFIX_SITE
from byceps.database import db
from byceps.services.brand.models.brand import Brand
from byceps.services.party.models.party import Party


@@ 35,6 37,7 @@ init_app(app)

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'),


@@ 44,6 47,11 @@ def _generate_static_files_exports():
        if path:
            yield url_path, str(path)

    # 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)


if app.env == 'development':
    # Share static files.

M byceps/application.py => byceps/application.py +2 -1
@@ 14,7 14,7 @@ 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_PARTY, STATIC_URL_PREFIX_SITE
from .database import db
from . import email
from .redis import redis


@@ 140,6 140,7 @@ def _add_static_file_url_rules(app):
        (STATIC_URL_PREFIX_GLOBAL, 'global_file'),
        (STATIC_URL_PREFIX_BRAND, 'brand_file'),
        (STATIC_URL_PREFIX_PARTY, 'party_file'),
        (STATIC_URL_PREFIX_SITE, 'site_file'),
    ]:
        rule = rule_prefix + '/<path:filename>'
        app.add_url_rule(rule,

M byceps/config.py => byceps/config.py +1 -0
@@ 14,6 14,7 @@ from flask import current_app
STATIC_URL_PREFIX_GLOBAL = '/global'
STATIC_URL_PREFIX_BRAND = '/brand'
STATIC_URL_PREFIX_PARTY = '/party'
STATIC_URL_PREFIX_SITE = '/site'

EXTENSION_KEY = 'byceps_config'
KEY_SITE_MODE = 'site_mode'