-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6383cb
commit a01c910
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from flask import abort, Blueprint, render_template | ||
from flask_login import current_user | ||
from functools import wraps | ||
from app.db.db_methods import get_all_users, get_user | ||
|
||
users = Blueprint('users', __name__, template_folder='templates', static_folder='static') | ||
|
||
|
||
def admin_required(route_func): | ||
@wraps(route_func) | ||
def my_wrapper(*args, **kwargs): | ||
if current_user and current_user.is_admin: | ||
return route_func(*args, **kwargs) | ||
abort(403) | ||
return my_wrapper | ||
|
||
|
||
@users.route('/', methods=["GET"]) | ||
@admin_required | ||
def index(): | ||
users = list(get_all_users()) | ||
usernames = [(user['name'], user['username']) for user in users] | ||
return render_template('user_list.html', usernames=usernames) | ||
|
||
@users.route('/<username>', methods=["GET"]) | ||
@admin_required | ||
def user_info(username): | ||
user_info = get_user(username) | ||
return f"{user_info}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>User List</title> | ||
</head> | ||
<body> | ||
<h1>Список пользователей</h1> | ||
<ul> | ||
{% for name, username in usernames %} | ||
<p><a href="{{ url_for('users.user_info', username=username) }}">{{ name }}</a></p> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |