Verified Commit cdcb743b authored by ynerant's avatar ynerant
Browse files

Fix membership filters

parent e75f04b5
Pipeline #9542 passed with stages
in 2 minutes and 54 seconds
......@@ -3,11 +3,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from django.contrib import messages
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import PasswordResetForm
from django.urls import reverse
from django.utils.html import format_html
from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from reversion.admin import VersionAdmin
from med.admin import admin_site
......@@ -25,7 +23,12 @@ class IsMemberFilter(admin.SimpleListFilter):
def queryset(self, request, queryset):
# FIXME Replace with imported Note Kfet memberships
if self.parameter_name in request.GET:
queryset = queryset.filter(,,
return queryset
......@@ -45,39 +48,21 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
list_filter = (IsMemberFilter, 'is_staff', 'is_superuser', 'is_active',
def save_model(self, request, obj, form, change):
On creation, send a password init mail
super().save_model(request, obj, form, change)
if not change:
# Virtually fill the password reset form
password_reset = PasswordResetForm(data={'email':})
if password_reset.is_valid():,
messages.success(request, _("An email to set the password"
" was sent."))
messages.error(request, _("The email is invalid."))
def has_add_permission(self, request):
# Only add users through Note Kfet login
return False
def is_member(self, obj):
Get current membership year and check if user is there
# FIXME Use NK20
is_member = True
if is_member:
return format_html(
if obj.is_member:
return mark_safe(
'<img src="/static/admin/img/icon-yes.svg" alt="True">'
return format_html(
'<img src="/static/admin/img/icon-no.svg" alt="False"> '
'<a class="button" href="{}">{}</a>',
reverse('users:adherer', args=[]),
return mark_safe(
'<img src="/static/admin/img/icon-no.svg" alt="False">'
is_member.short_description = _('is member')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment