Passed
Branch master (28df20)
by Markus
02:40
created

chaoswg.admin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 29
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A init_admin() 0 13 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AuthAdminModelView.is_accessible() 0 3 1
A AuthAdminIndexView.index() 0 5 2
1
from flask import redirect
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 flask_admin import Admin, AdminIndexView, expose
3
from flask_admin.menu import MenuLink
4
from flask_admin.contrib.peewee import ModelView
5
from flask_admin.form import SecureForm
6
from flask_login import current_user
7
8
from chaoswg.models import User, Task, Room, History
9
10
11
# Custom flask-admin classes for authentication
12
class AuthAdminModelView(ModelView):
1 ignored issue
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...
13
    form_base_class = SecureForm
14
15
    @staticmethod
16
    def is_accessible():
17
        return current_user.is_authenticated
18
19
20
class AuthAdminUserModelView(AuthAdminModelView):
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...
21
    column_exclude_list = ['password']
22
23
24
class AuthAdminIndexView(AdminIndexView):
1 ignored issue
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...
25
    @expose('/')
26
    def index(self):
27
        if not current_user.is_authenticated:
28
            return redirect('/login')
29
        return super(AuthAdminIndexView, self).index()
30
31
32
def init_admin(app):
33
    """
34
    initializes the flask-admin interface
35
    :param app:
36
    :return:
37
    """
38
    admin = Admin(app, index_view=AuthAdminIndexView(), name='ChaosWG Manager Admin',
39
                  template_mode='bootstrap3')
40
    admin.add_link(MenuLink(name='Back Home', url='/tasks'))
41
    admin.add_view(AuthAdminModelView(Task))
42
    admin.add_view(AuthAdminUserModelView(User))
43
    admin.add_view(AuthAdminModelView(Room))
44
    admin.add_view(AuthAdminModelView(History))
45