From e172b4f4bb4df4e0da5700a3b4a994df53a2b89b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 4 Oct 2020 20:54:03 +0200 Subject: [PATCH] When a membership is renewed, set the same roles as the previous membership --- apps/member/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/member/views.py b/apps/member/views.py index 90dba96b..ab4a5bc7 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -680,6 +680,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView): club = Club.objects.filter(PermissionBackend.filter_queryset(self.request.user, Club, "view")) \ .get(pk=self.kwargs["club_pk"]) user = form.instance.user + old_membership = None else: # get from url for renewal old_membership = self.get_queryset().get(pk=self.kwargs["pk"]) club = old_membership.club @@ -754,6 +755,9 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView): member_role = Role.objects.filter(Q(name="Adhérent BDE") | Q(name="Membre de club")).all() \ if club.name == "BDE" else Role.objects.filter(Q(name="Adhérent Kfet") | Q(name="Membre de club")).all() \ if club.name == "Kfet"else Role.objects.filter(name="Membre de club").all() + # Set the same roles as before + if old_membership: + member_role = member_role.union(old_membership.roles.all()) form.instance.roles.set(member_role) form.instance._force_save = True form.instance.save() @@ -791,7 +795,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView): return ret def get_success_url(self): - return reverse_lazy('member:club_detail', kwargs={'pk': self.object.club.id}) + return reverse_lazy('member:user_detail', kwargs={'pk': self.object.user.id}) class ClubManageRolesView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):