mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-14 10:00:40 +00:00
Unify more tables
This commit is contained in:
@ -1,45 +0,0 @@
|
||||
from flask_table import Table, Col, LinkCol
|
||||
|
||||
|
||||
class AdminUserTable(Table):
|
||||
'''
|
||||
Declares the table describing colum by column.
|
||||
'''
|
||||
classes = ['highlight', 'responsive-table']
|
||||
username = Col('Username', column_html_attrs={'class': 'username'},
|
||||
th_html_attrs={'class': 'sort',
|
||||
'data-sort': 'username'})
|
||||
email = Col('Email', column_html_attrs={'class': 'email'},
|
||||
th_html_attrs={'class': 'sort',
|
||||
'data-sort': 'email'})
|
||||
role_id = Col('Role', column_html_attrs={'class': 'role'},
|
||||
th_html_attrs={'class': 'sort',
|
||||
'data-sort': 'role'})
|
||||
confirmed = Col('Confrimed Status', column_html_attrs={'class': 'confirmed'}, # noqa
|
||||
th_html_attrs={'class': 'sort',
|
||||
'data-sort': 'confirmed'})
|
||||
id = Col('User Id', column_html_attrs={'class': 'id'},
|
||||
th_html_attrs={'class': 'sort',
|
||||
'data-sort': 'id'})
|
||||
url = LinkCol('Profile', 'admin.user',
|
||||
url_kwargs=dict(user_id='id'),
|
||||
anchor_attrs={'class': 'waves-effect waves-light btn-floating'}, # noqa
|
||||
text_fallback='<i class="material-icons">edit</i>')
|
||||
|
||||
|
||||
class AdminUserItem(object):
|
||||
'''
|
||||
Describes one item like one row per table.
|
||||
'''
|
||||
|
||||
def __init__(self, username, email, role_id, confirmed, id):
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.role_id = role_id
|
||||
self.confirmed = confirmed
|
||||
self.id = id
|
||||
|
||||
if self.role_id == 1:
|
||||
self.role_id = 'User'
|
||||
elif self.role_id == 2:
|
||||
self.role_id = 'Admin'
|
@ -2,12 +2,10 @@ from flask import flash, redirect, render_template, url_for
|
||||
from flask_login import login_required
|
||||
from . import admin
|
||||
from .forms import EditUserForm
|
||||
from .tables import AdminUserItem, AdminUserTable
|
||||
from .. import db
|
||||
from ..decorators import admin_required
|
||||
from ..models import Role, User
|
||||
from ..profile import tasks as profile_tasks
|
||||
import html
|
||||
|
||||
|
||||
@admin.route('/')
|
||||
@ -15,14 +13,15 @@ import html
|
||||
@admin_required
|
||||
def index():
|
||||
users = User.query.all()
|
||||
items = [AdminUserItem(u.username, u.email, u.role_id, u.confirmed, u.id)
|
||||
users = [dict(username=u.username,
|
||||
email=u.email,
|
||||
role_id=u.role_id,
|
||||
confirmed=u.confirmed,
|
||||
id=u.id)
|
||||
for u in users]
|
||||
# Convert table object to html string
|
||||
table = html.unescape(AdminUserTable(items).__html__())
|
||||
# Add class "list" to tbody element. Needed for "List.js"
|
||||
table = table.replace('tbody', 'tbody class="list"', 1)
|
||||
return render_template('admin/index.html.j2', table=table,
|
||||
title='Administration tools')
|
||||
return render_template('admin/index.html.j2',
|
||||
title='Administration tools',
|
||||
users=users)
|
||||
|
||||
|
||||
@admin.route('/user/<int:user_id>')
|
||||
@ -38,7 +37,6 @@ def user(user_id):
|
||||
@login_required
|
||||
@admin_required
|
||||
def delete_user(user_id):
|
||||
user = User.query.get_or_404(user_id)
|
||||
profile_tasks.delete_user(user_id)
|
||||
flash('User has been deleted!')
|
||||
return redirect(url_for('admin.index'))
|
||||
|
Reference in New Issue
Block a user