Passed
Push — master ( ede4b9...d9bb2e )
by Jochen
02:14
created

byceps.blueprints.snippet.views   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A view() 0 15 2
1
"""
2
byceps.blueprints.snippet.views
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2019 Jochen Kupperschmidt
6
:License: Modified BSD, see LICENSE for details.
7
"""
8
9
from flask import abort, g
10
11
from ...services.snippet import mountpoint_service
12
from ...util.framework.blueprint import create_blueprint
13
14
from .templating import (
15
    render_snippet_as_page,
16
    render_snippet_as_partial,
17
    url_for_snippet,
18
)
19
20
21
blueprint = create_blueprint('snippet', __name__)
22
23
blueprint.add_app_template_global(render_snippet_as_partial, 'render_snippet')
24
blueprint.add_app_template_global(url_for_snippet)
25
26
27
@blueprint.route('/<path:url_path>')
28
def view(url_path):
29
    """Show the current version of the snippet that is mounted for the
30
    current site at the given URL path.
31
    """
32
    url_path = '/' + url_path
33
34
    version = mountpoint_service.find_current_snippet_version_for_url_path(
35
        g.site_id, url_path
36
    )
37
38
    if version is None:
39
        abort(404)
40
41
    return render_snippet_as_page(version)
42