mirror of https://gitlab.crans.org/bde/nk20
When a membership is renewed, set the same roles as the previous membership
This commit is contained in:
parent
d666179037
commit
e172b4f4bb
|
@ -680,6 +680,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||||
club = Club.objects.filter(PermissionBackend.filter_queryset(self.request.user, Club, "view")) \
|
club = Club.objects.filter(PermissionBackend.filter_queryset(self.request.user, Club, "view")) \
|
||||||
.get(pk=self.kwargs["club_pk"])
|
.get(pk=self.kwargs["club_pk"])
|
||||||
user = form.instance.user
|
user = form.instance.user
|
||||||
|
old_membership = None
|
||||||
else: # get from url for renewal
|
else: # get from url for renewal
|
||||||
old_membership = self.get_queryset().get(pk=self.kwargs["pk"])
|
old_membership = self.get_queryset().get(pk=self.kwargs["pk"])
|
||||||
club = old_membership.club
|
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() \
|
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 == "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()
|
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.roles.set(member_role)
|
||||||
form.instance._force_save = True
|
form.instance._force_save = True
|
||||||
form.instance.save()
|
form.instance.save()
|
||||||
|
@ -791,7 +795,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_success_url(self):
|
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):
|
class ClubManageRolesView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
|
|
Loading…
Reference in New Issue