| Total Complexity | 4 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from flask import redirect |
||
|
|
|||
| 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
|
|||
| 13 | form_base_class = SecureForm |
||
| 14 | |||
| 15 | @staticmethod |
||
| 16 | def is_accessible(): |
||
| 17 | return current_user.is_authenticated |
||
| 18 | |||
| 19 | |||
| 20 | class AuthAdminUserModelView(AuthAdminModelView): |
||
| 21 | column_exclude_list = ['password'] |
||
| 22 | |||
| 23 | |||
| 24 | class AuthAdminIndexView(AdminIndexView): |
||
|
1 ignored issue
–
show
|
|||
| 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 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.