Completed
Push — master ( fe6d7a...5e9dbb )
by
unknown
02:04
created

DefaultController.test_config()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
nop 2
1
# coding=utf-8
2
from tracim.views.controllers import Controller
3
from pyramid.config import Configurator
4
from pyramid.response import Response
5
from pyramid.exceptions import NotFound
6
7
8
class DefaultController(Controller):
9
10
    @classmethod
11
    def notfound_view(cls, request):
12
        request.response.status = 404
13
        return {}
14
15
    @classmethod
16
    def test_config(cls, request):
17
        try:
18
            app_config = request.registry.settings['CFG']
19
            project = app_config.WEBSITE_TITLE
20
        except Exception as e:
21
            return Response(e, content_type='text/plain', status=500)
22
        return {'project': project}
23
24
    def bind(self, configurator: Configurator):
25
        configurator.add_static_view('static', 'static', cache_max_age=3600)
26
        configurator.add_view(
27
            self.notfound_view,
28
            renderer='tracim:templates/404.jinja2',
29
            context=NotFound,
30
        )
31
32
        configurator.add_route('test_config', '/')
33
        configurator.add_view(
34
            self.test_config,
35
            route_name='test_config',
36
            renderer='tracim:templates/mytemplate.jinja2',
37
        )
38