From 6caed35325d76fe67151c543235fc87b04b16d06 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Tue, 14 Jun 2022 15:23:16 +0200 Subject: [PATCH] Show more details about members on group full page --- CHANGELOG.rst | 5 +++ aleksis/core/static/public/style.scss | 5 +++ aleksis/core/tables.py | 46 +++++++++++++++++++++++++++ aleksis/core/views.py | 3 +- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5f825744b..fe40b48d5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,11 @@ Added * Add Ukrainian locale (contributed by Sergiy Gorichenko from Fre(i)e Software GmbH). * Add third gender to gender choices +Changed +~~~~~~~ + +* Restructure group page and show more information about members. + Fixed ~~~~~~~ diff --git a/aleksis/core/static/public/style.scss b/aleksis/core/static/public/style.scss index 4ae42c291..7aaff6575 100644 --- a/aleksis/core/static/public/style.scss +++ b/aleksis/core/static/public/style.scss @@ -990,3 +990,8 @@ p.ical-description { margin: 0; font-weight: 300; } + +.table-circle, .table-circle .materialize-circle { + height: 4em; + width: 4em; +} diff --git a/aleksis/core/tables.py b/aleksis/core/tables.py index f08460bd8..d60b691c2 100644 --- a/aleksis/core/tables.py +++ b/aleksis/core/tables.py @@ -1,5 +1,6 @@ from textwrap import wrap +from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ import django_tables2 as tables @@ -31,12 +32,57 @@ class PersonsTable(tables.Table): """Table to list persons.""" class Meta: + model = Person attrs = {"class": "highlight"} + fields = [] first_name = tables.LinkColumn("person_by_id", args=[A("id")]) last_name = tables.LinkColumn("person_by_id", args=[A("id")]) +class FullPersonsTable(PersonsTable): + """Table to list persons.""" + + photo = tables.Column(verbose_name=_("Photo"), accessor="pk", orderable=False) + + class Meta(PersonsTable.Meta): + fields = ( + "photo", + "date_of_birth", + "sex", + "email", + "street", + "housenumber", + "postal_code", + "place", + ) + sequence = ("photo", "first_name", "last_name", "...") + + def render_photo(self, value, record): + return render_to_string( + "core/partials/avatar_content.html", + { + "person_or_user": record, + "class": "materialize-circle table-circle", + "img_class": "materialize-circle", + }, + self.request, + ) + + def before_render(self, request): + """Hide columns if user has no permission to view them.""" + if not self.request.user.has_perm("core.view_person_rule"): + self.columns.hide("date_of_birth") + self.columns.hide("sex") + if not self.request.user.has_perm("core.view_contact_details_rule"): + self.columns.hide("email") + if not self.request.user.has_perm("core.view_address"): + self.columns.hide("street") + self.columns.hide("housenumber") + self.columns.hide("postal_code") + self.columns.hide("place") + + class GroupsTable(tables.Table): """Table to list groups.""" diff --git a/aleksis/core/views.py b/aleksis/core/views.py index 62ac22aa6..2a501d52b 100644 --- a/aleksis/core/views.py +++ b/aleksis/core/views.py @@ -115,6 +115,7 @@ from .registries import ( from .tables import ( AdditionalFieldsTable, DashboardWidgetTable, + FullPersonsTable, GroupGlobalPermissionTable, GroupObjectPermissionTable, GroupsTable, @@ -358,7 +359,7 @@ def group(request: HttpRequest, id_: int) -> HttpResponse: members = group.members.all() # Build table - members_table = PersonsTable(members) + members_table = FullPersonsTable(members) RequestConfig(request).configure(members_table) context["members_table"] = members_table -- GitLab