-
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.
Merge branch '506_bluprint_users' into 531_page_with_admin_pages
- Loading branch information
Showing
9 changed files
with
586 additions
and
1 deletion.
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,91 @@ | ||
import json | ||
from flask import abort, Blueprint, render_template, request, jsonify | ||
from flask_login import current_user | ||
from functools import wraps | ||
from app.db.db_methods import get_all_users, get_user | ||
from utils import checklist_filter, format_check_for_table | ||
from db import db_methods | ||
|
||
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("/data") | ||
@admin_required | ||
def users_data(): | ||
filters = request.args.get("filter", "{}") | ||
try: | ||
filters = json.loads(filters) | ||
filters = filters if filters else {} | ||
except Exception as e: | ||
# logger.warning("Can't parse filters") | ||
# logger.warning(repr(e)) | ||
filters = {} | ||
filter_query = {} | ||
if f_username := filters.get("username", None): | ||
filter_query["username"] = {"$regex": f_username} | ||
|
||
if f_name := filters.get("name", None): | ||
filter_query["name"] = {"$regex": f_name} | ||
|
||
if f_formats := filters.get("all_formats", None): | ||
filter_query["formats"] = {"$regex": f_formats} | ||
|
||
if f_criteria := filters.get("all_criteria", None): | ||
filter_query["criteria"] = {"$regex": f_criteria} | ||
|
||
if f_check_counts := filters.get("check_counts", None): | ||
try: | ||
f_check_counts_value, f_check_counts_cond = int(f_check_counts.split()[1]), f_check_counts.split()[0] | ||
if f_check_counts_cond == '>': | ||
filter_query["$expr"] = {"$gte": [{"$size": "$presentations"}, f_check_counts_value]} | ||
elif f_check_counts_cond == "<": | ||
filter_query["$expr"] = {"$lte": [{"$size": "$presentations"}, f_check_counts_value]} | ||
except ValueError: | ||
pass | ||
|
||
limit = request.args.get("limit", "") | ||
limit = int(limit) if limit.isnumeric() else 10 | ||
|
||
offset = request.args.get("offset", "") | ||
offset = int(offset) if offset.isnumeric() else 0 | ||
|
||
sort = request.args.get("sort", "") | ||
sort = 'username' if not sort else sort | ||
|
||
order = request.args.get("order", "") | ||
order = 'username' if not order else order | ||
|
||
rows, count = db_methods.get_user_cursor(filter=filter_query, limit=limit, offset=offset, sort=sort, order=order) | ||
|
||
response = { | ||
"total": count, | ||
"rows": [{ | ||
"username": item["username"], | ||
"name": item["name"], | ||
"all_formats": item["formats"], | ||
"all_criteria": item["criteria"], | ||
"check_counts": len(item["presentations"]), | ||
|
||
} for item in rows] | ||
} | ||
return jsonify(response) | ||
|
||
|
||
@users.route('/', methods=["GET"]) | ||
@admin_required | ||
def index(): | ||
return render_template('user_list.html') | ||
|
||
@users.route('/<username>', methods=["GET"]) | ||
@admin_required | ||
def user_info(username): | ||
user_info = get_user(username) | ||
return render_template('one_user_info.html', user_info=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,65 @@ | ||
{# Accepts: header dependicies, results, id, filename #} | ||
|
||
|
||
{% extends "root.html" %} | ||
|
||
{% block title %}Информация о пользователях{% endblock %} | ||
|
||
{% block main %} | ||
<style> | ||
.fht-cell { | ||
margin: 0 0.2rem 0.2rem; | ||
} | ||
|
||
/* .user-list-table th td { border: #54585d; } */ | ||
|
||
#user-list-table { | ||
table-layout: fixed; | ||
word-wrap: break-word; | ||
} | ||
|
||
#user-list-table.table-bordered, | ||
#user-list-table.table-bordered > thead > tr > th, | ||
#user-list-table.table-bordered > tbody > tr > td { | ||
border: 1px solid #a1a1a1; | ||
} | ||
</style> | ||
|
||
<div class="header row">{% include "header.html" %}</div> | ||
<div class="holder row"> | ||
<div class="container-fluid table-responsive-xl"> | ||
<h3 id="user_title" class="texteous ins"> | ||
Страница пользователя: <b>{{ user_info.username }}</b> | ||
</h3> | ||
<a href="{{ url_for('check_list', filter_user=user_info.username) }}" | ||
class="col text-center link">Список всех загрузок пользователя</a> | ||
<table id="one-user-table" class="table bg-white" | ||
data-filter-control="true" | ||
data-pagination="true" | ||
data-page-list="[5, 10, 25, 50, All]" | ||
data-ajax="ajaxRequest" | ||
data-query-params="queryParams" | ||
data-show-refresh="false" | ||
data-auto-refresh="true" | ||
data-auto-refresh-interval="10" | ||
data-show-auto-refresh="false" | ||
data-side-pagination="server" | ||
data-icon-size="lg" | ||
data-buttons="buttons" | ||
data-show-filter-control-switch="true" | ||
data-show-button-icons="false" | ||
data-show-button-text="true"> | ||
<thead> | ||
<tr> | ||
<th data-field="username" data-filter-control="input" data-sortable="true">Username</th> | ||
<th data-field="name" data-filter-control="input" data-sortable="true">Name</th> | ||
<th data-field="all_formats" data-filter-control="input" data-sortable="true">Formats</th> | ||
<th data-field="all_criteria" data-filter-control="input" data-sortable="true">Criteria</th> | ||
<th data-field="check_counts" data-filter-control="input" data-sortable="true" title="insert operator and value with space (f.e > 1000)">Count of checks</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
{% endblock main %} |
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,65 @@ | ||
{# Accepts: header dependicies, results, id, filename #} | ||
|
||
|
||
{% extends "root.html" %} | ||
|
||
{% block title %}Информация о пользователях{% endblock %} | ||
|
||
{% block main %} | ||
<style> | ||
.fht-cell { | ||
margin: 0 0.2rem 0.2rem; | ||
} | ||
|
||
/* .user-list-table th td { border: #54585d; } */ | ||
|
||
#user-list-table { | ||
table-layout: fixed; | ||
word-wrap: break-word; | ||
} | ||
|
||
#user-list-table.table-bordered, | ||
#user-list-table.table-bordered > thead > tr > th, | ||
#user-list-table.table-bordered > tbody > tr > td { | ||
border: 1px solid #a1a1a1; | ||
} | ||
</style> | ||
|
||
<div class="header row">{% include "header.html" %}</div> | ||
<div class="holder row"> | ||
<div class="container-fluid table-responsive-xl"> | ||
<h3 id="user_title" class="texteous ins"> | ||
Список пользователей: | ||
</h3> | ||
<table id="user-list-table" class="table bg-white" | ||
data-filter-control="true" | ||
data-pagination="true" | ||
data-page-list="[5, 10, 25, 50, All]" | ||
data-ajax="ajaxRequest" | ||
data-query-params="queryParams" | ||
data-show-refresh="false" | ||
data-auto-refresh="true" | ||
data-auto-refresh-interval="10" | ||
data-show-auto-refresh="false" | ||
data-side-pagination="server" | ||
data-icon-size="lg" | ||
data-buttons="buttons" | ||
data-show-filter-control-switch="true" | ||
data-show-button-icons="false" | ||
data-show-button-text="true"> | ||
<thead> | ||
<tr> | ||
<th data-field="username" data-filter-control="input" data-sortable="true">Username</th> | ||
<th data-field="name" data-filter-control="input" data-sortable="true">Name</th> | ||
<th data-field="all_formats" data-filter-control="input" data-sortable="true">Formats</th> | ||
<th data-field="all_criteria" data-filter-control="input" data-sortable="true">Criteria</th> | ||
<th data-field="check_counts" data-filter-control="input" data-sortable="true" title="insert operator and value with space (f.e > 1000)">Count of checks</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
{% endblock main %} | ||
|
||
|
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 |
---|---|---|
|
@@ -253,4 +253,4 @@ function downdloadBlob(blob, filename) { | |
document.body.appendChild(a); | ||
a.click(); | ||
a.remove(); | ||
} | ||
} |
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
Oops, something went wrong.