From ab21768311e387af2c35ad1e69c7c5541dcff5aa Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 4 Nov 2020 14:54:27 +0100 Subject: [PATCH] smaller rework while getting an overview --- web/app/admin/views.py | 10 ++-------- web/app/models.py | 22 +++++++++++----------- web/app/static/js/nopaque.lists.js | 10 ++++------ web/app/templates/admin/users.html.j2 | 8 +++----- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/web/app/admin/views.py b/web/app/admin/views.py index d06c856a..c3f4e875 100644 --- a/web/app/admin/views.py +++ b/web/app/admin/views.py @@ -1,5 +1,5 @@ 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 .forms import EditGeneralSettingsAdminForm from .. import db @@ -12,13 +12,7 @@ from ..settings import tasks as settings_tasks @login_required @admin_required def users(): - users = 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] + users = [user.to_dict() for user in User.query.all()] return render_template('admin/users.html.j2', title='Users', users=users) diff --git a/web/app/models.py b/web/app/models.py index 00c83245..4f72960a 100644 --- a/web/app/models.py +++ b/web/app/models.py @@ -145,17 +145,18 @@ class User(UserMixin, db.Model): 'email': self.email, 'last_seen': self.last_seen.timestamp(), 'member_since': self.member_since.timestamp(), - 'username': self.username, 'settings': {'dark_mode': self.setting_dark_mode, 'job_status_mail_notifications': self.setting_job_status_mail_notifications, 'job_status_site_notifications': self.setting_job_status_site_notifications}, + 'username': self.username, 'corpora': {corpus.id: corpus.to_dict() for corpus in self.corpora}, 'jobs': {job.id: job.to_dict() for job in self.jobs}, '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): ''' @@ -334,6 +335,7 @@ class Job(db.Model): end_date = db.Column(db.DateTime()) mem_mb = db.Column(db.Integer) n_cores = db.Column(db.Integer) + # This is used for zip creation secure_filename = db.Column(db.String(32)) service = db.Column(db.String(64)) ''' @@ -413,16 +415,14 @@ class Job(db.Model): 'description': self.description, 'end_date': (self.end_date.timestamp() if self.end_date else None), - 'inputs': {input.id: input.to_dict() for input in self.inputs}, - 'mem_mb': self.mem_mb, - 'n_cores': self.n_cores, - 'results': {result.id: result.to_dict() - for result in self.results}, - 'service': self.service, - 'service_args': self.service_args, - 'service_version': self.service_version, + 'service': {'args': self.service_args, + 'name': self.service, + 'version': self.service_version}, '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): diff --git a/web/app/static/js/nopaque.lists.js b/web/app/static/js/nopaque.lists.js index 28ae8679..8d7b6159 100644 --- a/web/app/static/js/nopaque.lists.js +++ b/web/app/static/js/nopaque.lists.js @@ -131,7 +131,7 @@ RessourceList.dataMappers = { email: user.email, id: user.id, link: `users/${user.id}`, - role_id: user.role_id, + role: user.role.name, username: user.username, username2: user.username, "delete-link": `/admin/users/${user.id}/delete`, @@ -388,11 +388,10 @@ RessourceList.options = { }, User: { item: ` + - - - +
@@ -418,8 +417,7 @@ RessourceList.options = { "username", "username2", "email", - "role_id", - "confirmed", + "role", "id", {name: "link", attr: "href"}, {name: "delete-link", attr: "href"}, diff --git a/web/app/templates/admin/users.html.j2 b/web/app/templates/admin/users.html.j2 index 539ce0f1..a7b712da 100644 --- a/web/app/templates/admin/users.html.j2 +++ b/web/app/templates/admin/users.html.j2 @@ -19,16 +19,14 @@ + - - - - +
Id Username Email RoleConfirmed StatusId {# Actions #}
    @@ -43,6 +41,6 @@ {% endblock scripts %}