tracim.views.default.default_controller   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 90
dl 0
loc 131
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A DefaultController.test_manager_page() 0 7 2
A DefaultController.bind() 0 52 1
A DefaultController.test_config() 0 8 2
A DefaultController.notfound_view() 0 3 1
A DefaultController.forbidden_view() 0 9 2
A DefaultController.test_user_page() 0 7 2
A DefaultController.test_contributor_page() 0 8 2
A DefaultController.test_admin_page() 0 7 2
1
# coding=utf-8
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from pyramid.request import Request
3
4
from tracim.models.data import UserRoleInWorkspace
5
from tracim.views.controllers import Controller
6
from pyramid.config import Configurator
0 ignored issues
show
introduced by
Imports from package pyramid are not grouped
Loading history...
7
from pyramid.response import Response
8
from pyramid.exceptions import NotFound
9
from pyramid.httpexceptions import HTTPUnauthorized
10
from pyramid.httpexceptions import HTTPForbidden
11
from pyramid.security import forget, authenticated_userid
0 ignored issues
show
Unused Code introduced by
Unused authenticated_userid imported from pyramid.security
Loading history...
12
13
from tracim.lib.utils.auth import require_workspace_role
0 ignored issues
show
introduced by
Imports from package tracim are not grouped
Loading history...
14
15
16
class DefaultController(Controller):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
17
18
    def notfound_view(self, request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
19
        request.response.status = 404
20
        return {}
21
22
    def forbidden_view(self, request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
23
        if request.authenticated_userid is None:
24
            response = HTTPUnauthorized()
25
            response.headers.update(forget(request))
26
27
        # user is logged in but doesn't have permissions, reject wholesale
28
        else:
29
            response = HTTPForbidden()
30
        return response
31
32
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
33
    @require_workspace_role(UserRoleInWorkspace.READER)
34
    def test_config(self, request: Request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
35
        try:
36
            app_config = request.registry.settings['CFG']
37
            project = app_config.WEBSITE_TITLE
38
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
39
            return Response(e, content_type='text/plain', status=500)
40
        return {'project': project}
41
42
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
43
    @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
44
    def test_contributor_page(self, request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
45
        try:
46
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
47
            project = 'contributor'
48
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
49
            return Response(e, content_type='text/plain', status=500)
50
        return {'project': project}
51
52
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
53
    def test_admin_page(self, request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
54
        try:
55
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
56
            project = 'admin'
57
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
58
            return Response(e, content_type='text/plain', status=500)
59
        return {'project': project}
60
61
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
62
    def test_manager_page(self, request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
63
        try:
64
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
65
            project = 'manager'
66
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
67
            return Response(e, content_type='text/plain', status=500)
68
        return {'project': project}
69
70
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
71
    def test_user_page(self, request):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
72
        try:
73
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
74
            project = 'user'
75
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
76
            return Response(e, content_type='text/plain', status=500)
77
        return {'project': project}
78
79
    def bind(self, configurator: Configurator):
80
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop static files
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
81
        configurator.add_static_view('static', 'static', cache_max_age=3600)
82
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Do not rely
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
83
        # on static file for 404 view
84
        configurator.add_view(
85
            self.notfound_view,
86
            renderer='tracim:templates/404.jinja2',
87
            context=NotFound,
88
        )
89
90
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
91
        configurator.add_route('test_config', '/')
92
        configurator.add_view(
93
            self.test_config,
94
            route_name='test_config',
95
            renderer='tracim:templates/mytemplate.jinja2',
96
        )
97
98
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
99
        configurator.add_route('test_contributor', '/test_contributor')
100
        configurator.add_view(
101
            self.test_contributor_page,
102
            route_name='test_contributor',
103
            renderer='tracim:templates/mytemplate.jinja2',
104
        )
105
106
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
107
        configurator.add_route('test_admin', '/test_admin')
108
        configurator.add_view(
109
            self.test_admin_page,
110
            route_name='test_admin',
111
            renderer='tracim:templates/mytemplate.jinja2',
112
        )
113
114
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
115
        configurator.add_route('test_manager', '/test_manager')
116
        configurator.add_view(
117
            self.test_user_page,
118
            route_name='test_manager',
119
            renderer='tracim:templates/mytemplate.jinja2',
120
        )
121
122
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
123
        configurator.add_route('test_user', '/test_user')
124
        configurator.add_view(
125
            self.test_user_page,
126
            route_name='test_user',
127
            renderer='tracim:templates/mytemplate.jinja2',
128
        )
129
130
        configurator.add_forbidden_view(self.forbidden_view)
131