mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 17:25:44 +00:00
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
from flask import (abort, current_app, flash, redirect, request,
|
|
render_template, url_for, send_from_directory)
|
|
from flask_login import current_user, login_required
|
|
from ..models import Corpus, User
|
|
from ..tables import AdminUserTable, AdminUserItem
|
|
from . import admin
|
|
from ..decorators import admin_required
|
|
from .. import db
|
|
import os
|
|
|
|
|
|
@admin.route('/overview', 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, u.id) 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('admin/admin.html.j2', title='Administration tools',
|
|
table=table)
|
|
|
|
|
|
@admin.route('/overview/admin_user_page/<int:user_id>', methods=['GET', 'POST'])
|
|
@login_required
|
|
@admin_required
|
|
def admin_user_page(user_id):
|
|
selected_user = User.query.filter_by(id=user_id).first()
|
|
title = 'Administration of user {} with ID: {}'.format(selected_user.username,
|
|
selected_user.id)
|
|
return render_template('admin/admin_user_page.html.j2',
|
|
title=title, selected_user=selected_user)
|
|
|
|
|
|
@admin.route('/overview/admin_user_page/delete/<int:user_id>', methods=['GET', 'POST'])
|
|
@login_required
|
|
@admin_required
|
|
def admin_delete_user(user_id):
|
|
selected_user = User.query.filter_by(id=user_id).first()
|
|
db.session.delete(selected_user)
|
|
db.session.commit()
|
|
flash('User {} has been deleted!'.format(user_id))
|
|
return redirect(url_for('admin.for_admins_only'))
|