From cf99c3f40e9ef8d148c8eee2cde83051166521da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 3 Jan 2023 17:00:07 +0100 Subject: [PATCH] We want a list of users, not memberships. --- src/membership/permissions.py | 6 ++-- src/membership/selectors.py | 4 +++ .../membership/membership_admin.html | 13 --------- src/membership/views.py | 27 ++++++++++-------- src/project/templates/base.html | 4 +-- src/project/urls.py | 4 +-- src/utils/templates/utils/list.html | 23 +++++++++++++++ src/utils/view_utils.py | 28 +++++++++++++++++++ 8 files changed, 77 insertions(+), 32 deletions(-) delete mode 100644 src/membership/templates/membership/membership_admin.html create mode 100644 src/utils/templates/utils/list.html diff --git a/src/membership/permissions.py b/src/membership/permissions.py index 4582149..02a5388 100644 --- a/src/membership/permissions.py +++ b/src/membership/permissions.py @@ -38,9 +38,9 @@ class Permission: ) -ADMINISTRATE_MEMBERSHIPS = Permission( - name=_("Can administrate memberships"), - codename="administrate_memberships", +ADMINISTRATE_MEMBERS = Permission( + name=_("Can administrate members"), + codename="administrate_members", app_label="membership", model="membership", ) diff --git a/src/membership/selectors.py b/src/membership/selectors.py index 944fa99..d1eb97d 100644 --- a/src/membership/selectors.py +++ b/src/membership/selectors.py @@ -24,3 +24,7 @@ def get_memberships( memberships = memberships.filter(period=period) return memberships + + +def get_users(): + return User.objects.all() diff --git a/src/membership/templates/membership/membership_admin.html b/src/membership/templates/membership/membership_admin.html deleted file mode 100644 index 2a67013..0000000 --- a/src/membership/templates/membership/membership_admin.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} - -{% block content %} - - {% for period in subscription_periods %} -

{{ period }}

- {% for membership in period.membership_set.all %} -

{{ membership.user.username }}

- {% endfor %} - {% endfor %} - -{% endblock %} diff --git a/src/membership/views.py b/src/membership/views.py index 7bcc74a..83a193b 100644 --- a/src/membership/views.py +++ b/src/membership/views.py @@ -1,11 +1,13 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import permission_required +from django.utils.translation import gettext_lazy as _ from zen_queries import render -from .permissions import ADMINISTRATE_MEMBERSHIPS +from .permissions import ADMINISTRATE_MEMBERS from .selectors import get_memberships -from .selectors import get_subscription_periods +from .selectors import get_users from utils.view_utils import base_view_context +from utils.view_utils import render_list @login_required @@ -30,16 +32,17 @@ def membership_overview(request): @login_required -@permission_required(ADMINISTRATE_MEMBERSHIPS.path) -def membership_admin(request): - subscription_periods = get_subscription_periods() +@permission_required(ADMINISTRATE_MEMBERS.path) +def members_admin(request): + users = get_users() - context = base_view_context(request) | { - "subscription_periods": subscription_periods, - } - - return render( + return render_list( request=request, - template_name="membership/membership_admin.html", - context=context, + objects=users, + columns=[ + ("username", _("Username")), + ("first_name", _("First name")), + ("last_name", _("Last name")), + ("email", _("Email")), + ], ) diff --git a/src/project/templates/base.html b/src/project/templates/base.html index 88eb3ae..5c478ee 100644 --- a/src/project/templates/base.html +++ b/src/project/templates/base.html @@ -192,8 +192,8 @@ {% trans "Admin" %}