No more manage memberships, we will use NK20

This commit is contained in:
Yohann D'ANELLO 2021-10-23 14:49:44 +02:00
parent 7f24e5c1bf
commit 2a17a32d4c
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
6 changed files with 24 additions and 72 deletions

View File

@ -90,10 +90,6 @@ bureau
media | Can add borrowed item
media | Can change borrowed item
media | Can delete borrowed item
users | Can view adhesion
users | Can add adhesion
users | Can change adhesion
users | Can delete adhesion
users | Can view user
users | Can add user
users | Can change user

View File

@ -13,12 +13,7 @@ from reversion.admin import VersionAdmin
from med.admin import admin_site
from .forms import UserCreationAdminForm
from .models import Adhesion, User
class AdhesionAdmin(VersionAdmin):
list_display = ('starting_in', 'ending_in')
autocomplete_fields = ('members',)
from .models import User
class IsMemberFilter(admin.SimpleListFilter):
@ -31,12 +26,7 @@ class IsMemberFilter(admin.SimpleListFilter):
)
def queryset(self, request, queryset):
value = self.value()
if value == 'Yes':
# Get current membership year and list all members
last_adh_year = Adhesion.objects.all().order_by('starting_in') \
.reverse().first()
return last_adh_year.members
# FIXME Replace with imported Note Kfet memberships
return queryset
@ -88,9 +78,8 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
"""
Get current membership year and check if user is there
"""
last_adh_year = Adhesion.objects.all().order_by('starting_in') \
.reverse().first()
is_member = last_adh_year and obj in last_adh_year.members.all()
# FIXME Use NK20
is_member = True
if is_member:
return format_html(
'<img src="/static/admin/img/icon-yes.svg" alt="True">'
@ -108,4 +97,3 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
admin_site.register(User, UserAdmin)
admin_site.register(Adhesion, AdhesionAdmin)

View File

@ -0,0 +1,16 @@
# Generated by Django 2.2.17 on 2021-10-23 12:48
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0041_auto_20200923_2030'),
]
operations = [
migrations.DeleteModel(
name='Adhesion',
),
]

View File

@ -42,31 +42,5 @@ class User(AbstractUser):
@property
def is_member(self):
last_year = Adhesion.objects.all().order_by(
'starting_in').reverse().first()
return last_year and self in last_year.members.all()
class Adhesion(models.Model):
starting_in = models.IntegerField(
verbose_name=_('starting in'),
help_text=_('Year in which the membership year starts.'),
unique=True,
)
ending_in = models.IntegerField(
verbose_name=_('ending in'),
help_text=_('Year in which the membership year ends.'),
unique=True,
)
members = models.ManyToManyField(
'User',
verbose_name=_('members'),
blank=True,
)
class Meta:
verbose_name = _('membership year')
verbose_name_plural = _('membership years')
def __str__(self):
return f"{self.starting_in} - {self.ending_in}"
# FIXME Use NK20
return True

View File

@ -9,5 +9,4 @@ from . import views
app_name = 'users'
urlpatterns = [
url(r'^edit_info/$', views.edit_info, name='edit-info'),
url(r'^adherer/(?P<userid>[0-9]+)$', views.adherer, name='adherer'),
]

View File

@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from django.db import transaction
from django.shortcuts import redirect, render
@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
from rest_framework import viewsets
from reversion import revisions as reversion
from users.forms import BaseInfoForm
from users.models import Adhesion, User
from users.models import User
from .serializers import GroupSerializer, UserSerializer
@ -44,27 +44,6 @@ def edit_info(request):
}, 'users/user.html', request)
@login_required
@permission_required('users.add_adhesion')
def adherer(request, userid):
try:
users = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant")
return redirect("admin:users_user_changelist")
adh_year = Adhesion.objects.all().order_by('starting_in').reverse().first()
if not adh_year:
messages.error(request, "Année d'adhésion non définie")
return redirect("admin:users_user_changelist")
with transaction.atomic(), reversion.create_revision():
reversion.set_user(request.user)
adh_year.members.add(users)
adh_year.save()
reversion.set_comment("Adhesion de %s" % users)
messages.success(request, "Adhesion effectuee")
return redirect("admin:users_user_changelist")
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.