Completed
Push — master ( cd0c61...ee130d )
by Jochen
05:47
created

view_current_version_by_name()   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
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, url_for
10
11
from ...services.snippet import mountpoint_service
12
from ...util.framework.blueprint import create_blueprint
13
14
from .templating import render_snippet_as_page, render_snippet_as_partial
15
16
17
blueprint = create_blueprint('snippet', __name__)
18
19
blueprint.add_app_template_global(render_snippet_as_partial, 'render_snippet')
20
21
22
@blueprint.app_template_global()
23
def url_for_snippet(name):
24
    return url_for(f'snippet.{name}')
25
26
27
def view_current_version_by_name(name):
28
    """Show the current version of the snippet that is mounted with that
29
    name.
30
    """
31
    # Note: endpoint suffix != snippet name
32
    version = mountpoint_service.find_current_snippet_version_for_mountpoint(
33
        g.site_id, name
34
    )
35
36
    if version is None:
37
        abort(404)
38
39
    return render_snippet_as_page(version)
40