From 50273ea4d15715c5bc022a520bc1cb5ca24b2bbf Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Fri, 9 Aug 2019 10:16:31 +0200 Subject: [PATCH] Use links as list items for corpora and jobs. Add colors for service types. Link jobs to job page. --- app/main/views.py | 37 +++++++++++++++++----------- app/templates/main/dashboard.html.j2 | 22 +++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/app/main/views.py b/app/main/views.py index 5f4d2c7c..147d62cb 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -1,6 +1,6 @@ -from flask import current_app, flash, redirect, render_template, url_for +from flask import abort, current_app, flash, redirect, render_template, url_for from flask_login import current_user, login_required -from ..models import User, Corpus +from ..models import Corpus, User, Job from ..tables import AdminUserTable, AdminUserItem from . import main from .forms import CreateCorpusForm @@ -14,9 +14,16 @@ def index(): return render_template('main/index.html.j2', title='Opaque') -@main.route('/corpora/') -def corpora(corpus): - return render_template('main/corpus.html.j2', title=corpus) +@main.route('/admin', methods=['GET', 'POST']) +@login_required +@admin_required +def for_admins_only(): + 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).__html__() # converts table object to html string + table = table.replace('tbody', 'tbody class="list"', 1) # add class list to tbody element. Needed by list.js + return render_template('main/admin.html.j2', title='Administration tools', + table=table) @main.route('/dashboard', methods=['GET', 'POST']) @@ -54,13 +61,15 @@ def dashboard(): ) -@main.route('/admin', methods=['GET', 'POST']) +@main.route('/jobs/') @login_required -@admin_required -def for_admins_only(): - 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).__html__() # converts table object to html string - table = table.replace('tbody', 'tbody class="list"', 1) # add class list to tbody element. Needed by list.js - return render_template('main/admin.html.j2', title='Administration tools', - table=table) +def job(job_id): + job = Job.query.filter_by(id=job_id).first() + if not job: + print('Job not found.') + abort(404) + elif not job.user_id == current_user.id: + print('Job does not belong to current user.') + abort(403) + print(job) + return render_template('main/corpus.html.j2', title=job.title) diff --git a/app/templates/main/dashboard.html.j2 b/app/templates/main/dashboard.html.j2 index 73b429bc..39d58718 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -27,16 +27,15 @@ - +