~homeworkprod/byceps

ref: 342e5296ae417372e544ce931b442e98301c17a1 byceps/byceps/blueprints/site/snippet/views.py -rw-r--r-- 1019 bytes
342e5296 — Jochen Kupperschmidt Require body blocks in base templates 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
byceps.blueprints.site.snippet.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import abort, g

from ....services.snippet import mountpoint_service
from ....util.framework.blueprint import create_blueprint

from .templating import (
    render_snippet_as_page,
    render_snippet_as_partial,
    url_for_snippet,
)


blueprint = create_blueprint('snippet', __name__)

blueprint.add_app_template_global(render_snippet_as_partial, 'render_snippet')
blueprint.add_app_template_global(url_for_snippet)


@blueprint.route('/<path:url_path>')
def view(url_path):
    """Show the current version of the snippet that is mounted for the
    current site at the given URL path.
    """
    url_path = '/' + url_path

    version = mountpoint_service.find_current_snippet_version_for_url_path(
        g.site_id, url_path
    )

    if version is None:
        abort(404)

    return render_snippet_as_page(version)