~sirn/fanboi2

ref: a68873a108d20a6a49a1b6caf374bfb2cf6a94fe fanboi2/fanboi2/views/pages.py -rw-r--r-- 1.1 KiB
a68873a1Kridsada Thanabulpong Coding style cleanups and setup pre-commit hooks (#42) 3 years 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
from pyramid.response import Response

from ..interfaces import IPageQueryService


def robots_show(request):
    """Display robots.txt.

    :param request: A :class:`pyramid.request.Request` object.
    """
    page_query_svc = request.find_service(IPageQueryService)
    page = page_query_svc.internal_page_from_slug("global/robots")
    response = Response(page.body)
    response.content_type = "text/plain"
    return response


def page_show(request):
    """Display a single page.

    :param request: A :class:`pyramid.request.Request` object.
    """
    page_query_svc = request.find_service(IPageQueryService)
    page_slug = request.matchdict["page"]
    page = page_query_svc.public_page_from_slug(page_slug)
    return {"page": page}


def includeme(config):  # pragma: no cover
    config.add_route("page", "/{page:.*}/")

    config.add_view(
        robots_show, request_method="GET", route_name="robots", renderer="string"
    )

    config.add_view(
        page_show, request_method="GET", route_name="page", renderer="pages/show.mako"
    )

    config.scan()