Skip to content

Commit

Permalink
Implement archivable_users table
Browse files Browse the repository at this point in the history
Refs #67
  • Loading branch information
lukasjuhrich committed Jul 24, 2021
1 parent f2ca33e commit 29694eb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deps/bootstrap-table-py
26 changes: 22 additions & 4 deletions web/blueprints/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from itertools import chain
from typing import Optional, TypeVar, Callable

from bs_table_py.table import datetime_format, date_format
from bs_table_py.table import datetime_format, date_format, LinkColumn
from flask import (
Blueprint, Markup, abort, flash, jsonify, redirect, render_template,
request, url_for, session as flask_session, make_response)
Expand All @@ -39,6 +39,7 @@
finish_member_request, send_confirmation_email, \
delete_member_request, get_member_requests, \
get_possible_existing_users_for_pre_member, send_member_request_merged_email, can_target, edit_address
from pycroft.lib.user_deletion import get_archivable_members
from pycroft.model import session
from pycroft.model.facilities import Room
from pycroft.model.finance import Split
Expand All @@ -60,7 +61,7 @@
from .log import formatted_user_hades_logs
from .tables import (LogTableExtended, LogTableSpecific, MembershipTable,
SearchTable, TrafficTopTable, RoomHistoryTable,
PreMemberTable, TenancyTable)
PreMemberTable, TenancyTable, ArchivableMembersTable)
from ..finance.tables import FinanceTable, FinanceTableSplitted
from ..helpers.log import format_user_log_entry, format_room_log_entry, \
format_task_log_entry
Expand Down Expand Up @@ -1277,5 +1278,22 @@ def resend_confirmation_mail():
@nav.navigate('Archivable users')
@bp.route('/archivable_users')
def archivable_users():
from pycroft.lib.user_deletion import get_archivable_members
return render_template('user/archivable_users.html', rows=get_archivable_members())
table = ArchivableMembersTable(data_url=url_for('.archivable_users_json'))
return render_template('user/archivable_users.html', table=table)


@bp.route('/archivable_users_table')
def archivable_users_json():
T = ArchivableMembersTable
return {'items': [
T.row(
id=info.User.id,
user=T.user.value(
title=f'{info.User.name} ({info.User.login})',
href=url_for('user.user_show', user_id=info.User.id)
),
num_hosts=len(info.User.hosts),
# TODO better: `DateColumn.value`
end_of_membership=datetime_format(info.mem_end)
) for info in get_archivable_members()
]}
14 changes: 14 additions & 0 deletions web/blueprints/user/tables.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

from flask import url_for

from bs_table_py.table import BootstrapTable, Column, \
Expand Down Expand Up @@ -104,3 +106,15 @@ class Meta:
table_args = {
'data-row-style': 'table.membershipRequestRowFormatter',
}


class ArchivableMembersTable(RefreshableTableMixin, BootstrapTable):
id = Column("ID")
user = LinkColumn("Mitglied")
num_hosts = Column("#Hosts")
end_of_membership = DateColumn("EOM")

if typing.TYPE_CHECKING:
@classmethod
def row(cls, id: int, user: dict, num_hosts: int, end_of_membership: dict) -> dict: ...

7 changes: 1 addition & 6 deletions web/templates/user/archivable_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
#}
{% extends "layout.html" %}
{% block content %}
<ul>
{% for row in rows %}
<li>{{ row.User.login }} / {{ row.mem_end }}</li>
{% endfor %}
</ul>

{{ table.render('mytable') }}
{% endblock %}

0 comments on commit 29694eb

Please sign in to comment.