~sirn/fanboi2

ref: baf63a21556905a6c27516a8d5641d31120d1fe3 fanboi2/fanboi2/views/pages.py -rw-r--r-- 1.1 KiB
baf63a21Kridsada Thanabulpong Add scope column to banwords. 1 year, 9 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
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()