Fix membership filters
This commit is contained in:
parent
e75f04b530
commit
cdcb743b55
|
@ -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(
|
||||
membership__date_start__lte=timezone.now(),
|
||||
membership__date_end__gte=timezone.now(),
|
||||
).distinct()
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
|
@ -45,39 +48,21 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
|||
list_filter = (IsMemberFilter, 'is_staff', 'is_superuser', 'is_active',
|
||||
'groups')
|
||||
|
||||
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': obj.email})
|
||||
if password_reset.is_valid():
|
||||
password_reset.save(request=request,
|
||||
use_https=request.is_secure())
|
||||
messages.success(request, _("An email to set the password"
|
||||
" was sent."))
|
||||
else:
|
||||
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">'
|
||||
)
|
||||
else:
|
||||
return format_html(
|
||||
'<img src="/static/admin/img/icon-no.svg" alt="False"> '
|
||||
'<a class="button" href="{}">{}</a>',
|
||||
reverse('users:adherer', args=[obj.pk]),
|
||||
_('Adhere')
|
||||
return mark_safe(
|
||||
'<img src="/static/admin/img/icon-no.svg" alt="False">'
|
||||
)
|
||||
|
||||
is_member.short_description = _('is member')
|
||||
|
|
Loading…
Reference in New Issue