diff --git a/app/main/errors.py b/app/main/errors.py index fbd99b13aab12886f6e2faf1e7e718cf79a7da5d..625555bebabd0a963ff807842e7e95ecc05781b2 100644 --- a/app/main/errors.py +++ b/app/main/errors.py @@ -9,7 +9,7 @@ def forbidden(e): response = jsonify({'error': 'forbidden'}) response.status_code = 403 return response - return render_template('403.html.j2'), 403 + return render_template('403.html.j2', title='Forbidden'), 403 @main.app_errorhandler(404) @@ -19,7 +19,7 @@ def page_not_found(e): response = jsonify({'error': 'not found'}) response.status_code = 404 return response - return render_template('404.html.j2'), 404 + return render_template('404.html.j2', title='Not Found'), 404 @main.app_errorhandler(500) @@ -29,4 +29,4 @@ def internal_server_error(e): response = jsonify({'error': 'internal server error'}) response.status_code = 500 return response - return render_template('500.html.j2'), 500 + return render_template('500.html.j2', title='Internal Server Error'), 500 diff --git a/app/main/views.py b/app/main/views.py index 0a46a7c701a8af5148f39b14c428d54cccf563d2..f801f2ade9efedc8485720c06d4809c34ece1802 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -1,4 +1,6 @@ from flask import render_template +from ..models import User +from ..tables import AdminUserTable, AdminUserItem from . import main from ..decorators import admin_required from flask_login import login_required @@ -13,4 +15,8 @@ def index(): @login_required @admin_required def for_admins_only(): - return "For administrators!" + users = User.query.order_by(User.username).all() + items = [AdminUserItem(u.username, u.email, u.role_id, u.confirmed) for u in users] + table = AdminUserTable(items) + return render_template('main/admin.html.j2', title='Administration Tools', + table=table.__html__()) diff --git a/app/tables.py b/app/tables.py new file mode 100644 index 0000000000000000000000000000000000000000..44c6401e74c638fac7cac634a42321788e7b47d3 --- /dev/null +++ b/app/tables.py @@ -0,0 +1,29 @@ +from flask_table import Table, Col + + +class AdminUserTable(Table): + """ + Declares the table describing colum by column. + """ + classes = ['highlight', 'responsive-table'] + username = Col('Username') + email = Col('Email') + role_id = Col('Role') + confirmed = Col('Confrimed Status') + + +class AdminUserItem(object): + """ + Describes one item like one row per table. + """ + + def __init__(self, username, email, role_id, confirmed): + self.username = username + self.email = email + self.role_id = role_id + self.confirmed = confirmed + + if self.role_id == 1: + self.role_id = 'User' + elif self.role_id == 2: + self.role_id = 'Admin' diff --git a/app/templates/403.html.j2 b/app/templates/403.html.j2 index 95c46fda69b832159c60cc1e2074ef3e1258e486..70f7d846a9eada674af5515946744574a28fde89 100644 --- a/app/templates/403.html.j2 +++ b/app/templates/403.html.j2 @@ -1,9 +1,7 @@ {% extends "base.html.j2" %} -{% block title %}Opaque - Forbidden{% endblock %} - {% block page_content %} <div class="page-header"> - <h1>Forbidden</h1> + <p>This site is forbidden for you.</p> </div> {% endblock %} diff --git a/app/templates/404.html.j2 b/app/templates/404.html.j2 index 75f18cd52a781f76d0085bd2a6dda6b9e948ff1b..85a2a8423e5535223be4adc026ce219bc87ce8d8 100644 --- a/app/templates/404.html.j2 +++ b/app/templates/404.html.j2 @@ -1,9 +1,7 @@ {% extends "base.html.j2" %} -{% block title %}Opaque - Page Not Found{% endblock %} - {% block page_content %} <div class="page-header"> - <h1>Not Found</h1> + <p>Site has not been found.</p> </div> {% endblock %} diff --git a/app/templates/500.html.j2 b/app/templates/500.html.j2 index 43b7a9411a1cf6edbb0f75386ce86e493f621105..3e869656022b37ecb9bbeecb2cd52acb2456d3f0 100644 --- a/app/templates/500.html.j2 +++ b/app/templates/500.html.j2 @@ -1,9 +1,7 @@ {% extends "base.html.j2" %} -{% block title %}Opaque - Internal Server Error{% endblock %} - {% block page_content %} <div class="page-header"> - <h1>Internal Server Error</h1> + <p>Internal Server Error. We are Sorry!</p> </div> {% endblock %} diff --git a/app/templates/base.html.j2 b/app/templates/base.html.j2 index a736b9ab4b51ae66989e5d2eb6b5495eab4e60c8..469eb8197cee3453906c5c982a500ac23c47ce03 100644 --- a/app/templates/base.html.j2 +++ b/app/templates/base.html.j2 @@ -60,6 +60,9 @@ </li> <li><a href="{{ url_for('main.index') }}"><i class="material-icons">opacity</i>Opaque</a></li> <li><a href="{{ url_for('auth.settings') }}"><i class="material-icons">settings</i>Settings</a></li> + {% if current_user.is_administrator() %} <!-- Shows only for admins --> + <li><a href="{{ url_for('main.for_admins_only') }}"><i class="material-icons">build</i>Administration</a></li> + {% endif %} </ul> </header> diff --git a/app/templates/main/admin.html.j2 b/app/templates/main/admin.html.j2 index 35511c07c1fb4a8367d8da857871ca6ffd9b5304..1420ca4c5c85222de0bc1883c3cacdd4c1af62bb 100644 --- a/app/templates/main/admin.html.j2 +++ b/app/templates/main/admin.html.j2 @@ -1,11 +1,11 @@ {% extends "base.html.j2" %} {% block page_content %} -<h1>Administration tools</h1> <div class="col s12"> <div class="card large"> <div class="card-content"> <span class="card-title">User list</span> + {{ table }} </div> </div> </div> diff --git a/requirements.txt b/requirements.txt index 1553a5fe932269d373c3a7c31f3c9387696d587c..18b0f129f82557bd06338f7d2af230d52db1f2fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ Flask-Migrate==2.5.2 Flask-SQLAlchemy==2.4.0 Flask-WTF==0.14.2 python-dotenv==0.10.3 +Flask-Table==0.5.0