smaller rework while getting an overview

This commit is contained in:
Patrick Jentsch 2020-11-04 14:54:27 +01:00
parent 9c9790be89
commit ab21768311
4 changed files with 20 additions and 30 deletions

View File

@ -1,5 +1,5 @@
from flask import flash, redirect, render_template, url_for from flask import flash, redirect, render_template, url_for
from flask_login import current_user, login_required from flask_login import login_required
from . import admin from . import admin
from .forms import EditGeneralSettingsAdminForm from .forms import EditGeneralSettingsAdminForm
from .. import db from .. import db
@ -12,13 +12,7 @@ from ..settings import tasks as settings_tasks
@login_required @login_required
@admin_required @admin_required
def users(): def users():
users = User.query.all() users = [user.to_dict() for user in User.query.all()]
users = [dict(username=u.username,
email=u.email,
role_id=u.role_id,
confirmed=u.confirmed,
id=u.id)
for u in users]
return render_template('admin/users.html.j2', title='Users', users=users) return render_template('admin/users.html.j2', title='Users', users=users)

View File

@ -145,17 +145,18 @@ class User(UserMixin, db.Model):
'email': self.email, 'email': self.email,
'last_seen': self.last_seen.timestamp(), 'last_seen': self.last_seen.timestamp(),
'member_since': self.member_since.timestamp(), 'member_since': self.member_since.timestamp(),
'username': self.username,
'settings': {'dark_mode': self.setting_dark_mode, 'settings': {'dark_mode': self.setting_dark_mode,
'job_status_mail_notifications': 'job_status_mail_notifications':
self.setting_job_status_mail_notifications, self.setting_job_status_mail_notifications,
'job_status_site_notifications': 'job_status_site_notifications':
self.setting_job_status_site_notifications}, self.setting_job_status_site_notifications},
'username': self.username,
'corpora': {corpus.id: corpus.to_dict() 'corpora': {corpus.id: corpus.to_dict()
for corpus in self.corpora}, for corpus in self.corpora},
'jobs': {job.id: job.to_dict() for job in self.jobs}, 'jobs': {job.id: job.to_dict() for job in self.jobs},
'query_results': {query_result.id: query_result.to_dict() 'query_results': {query_result.id: query_result.to_dict()
for query_result in self.query_results}} for query_result in self.query_results},
'role': self.role.to_dict()}
def __repr__(self): def __repr__(self):
''' '''
@ -334,6 +335,7 @@ class Job(db.Model):
end_date = db.Column(db.DateTime()) end_date = db.Column(db.DateTime())
mem_mb = db.Column(db.Integer) mem_mb = db.Column(db.Integer)
n_cores = db.Column(db.Integer) n_cores = db.Column(db.Integer)
# This is used for zip creation
secure_filename = db.Column(db.String(32)) secure_filename = db.Column(db.String(32))
service = db.Column(db.String(64)) service = db.Column(db.String(64))
''' '''
@ -413,16 +415,14 @@ class Job(db.Model):
'description': self.description, 'description': self.description,
'end_date': (self.end_date.timestamp() if self.end_date else 'end_date': (self.end_date.timestamp() if self.end_date else
None), None),
'inputs': {input.id: input.to_dict() for input in self.inputs}, 'service': {'args': self.service_args,
'mem_mb': self.mem_mb, 'name': self.service,
'n_cores': self.n_cores, 'version': self.service_version},
'results': {result.id: result.to_dict()
for result in self.results},
'service': self.service,
'service_args': self.service_args,
'service_version': self.service_version,
'status': self.status, 'status': self.status,
'title': self.title} 'title': self.title,
'inputs': {input.id: input.to_dict() for input in self.inputs},
'results': {result.id: result.to_dict()
for result in self.results}}
class NotificationData(db.Model): class NotificationData(db.Model):

View File

@ -131,7 +131,7 @@ RessourceList.dataMappers = {
email: user.email, email: user.email,
id: user.id, id: user.id,
link: `users/${user.id}`, link: `users/${user.id}`,
role_id: user.role_id, role: user.role.name,
username: user.username, username: user.username,
username2: user.username, username2: user.username,
"delete-link": `/admin/users/${user.id}/delete`, "delete-link": `/admin/users/${user.id}/delete`,
@ -388,11 +388,10 @@ RessourceList.options = {
}, },
User: { User: {
item: `<tr> item: `<tr>
<td class="id"></td>
<td class="username"></td> <td class="username"></td>
<td class="email"></td> <td class="email"></td>
<td class="role_id"></td> <td class="role"></td>
<td class="confirmed"></td>
<td class="id"></td>
<td> <td>
<div class="right-align"> <div class="right-align">
<a class="btn-floating modal-trigger red tooltipped waves-effect waves-light delete-modal-trigger" data-position="top" data-tooltip="Delete"> <a class="btn-floating modal-trigger red tooltipped waves-effect waves-light delete-modal-trigger" data-position="top" data-tooltip="Delete">
@ -418,8 +417,7 @@ RessourceList.options = {
"username", "username",
"username2", "username2",
"email", "email",
"role_id", "role",
"confirmed",
"id", "id",
{name: "link", attr: "href"}, {name: "link", attr: "href"},
{name: "delete-link", attr: "href"}, {name: "delete-link", attr: "href"},

View File

@ -19,16 +19,14 @@
<table class="highlight responsive-table"> <table class="highlight responsive-table">
<thead> <thead>
<tr> <tr>
<th class="sort" data-sort="id">Id</th>
<th class="sort" data-sort="username">Username</th> <th class="sort" data-sort="username">Username</th>
<th class="sort" data-sort="email">Email</th> <th class="sort" data-sort="email">Email</th>
<th class="sort" data-sort="role_id">Role</th> <th class="sort" data-sort="role_id">Role</th>
<th class="sort" data-sort="confirmed">Confirmed Status</th>
<th class="sort" data-sort="id">Id</th>
<th>{# Actions #}</th> <th>{# Actions #}</th>
</tr> </tr>
</thead> </thead>
<tbody class="list"> <tbody class="list"></tbody>
</tbody>
</table> </table>
<ul class="pagination paginationBottom"></ul> <ul class="pagination paginationBottom"></ul>
</div> </div>
@ -43,6 +41,6 @@
<script type="module"> <script type="module">
import {RessourceList} from '{{ url_for('static', filename='js/nopaque.lists.js') }}'; import {RessourceList} from '{{ url_for('static', filename='js/nopaque.lists.js') }}';
let userList = new RessourceList('users', null, "User", RessourceList.options.extended); let userList = new RessourceList('users', null, "User", RessourceList.options.extended);
userList._add({{ users|tojson}}); userList._add({{ users|tojson }});
</script> </script>
{% endblock scripts %} {% endblock scripts %}