mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Redirect directly on member page when adding a new member. Still has a bug : an user already member always show when success
This commit is contained in:
parent
baa7be69e4
commit
4310441269
@ -272,28 +272,30 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
|||||||
form.instance = Membership(club=self.object, user=self.request.user)
|
form.instance = Membership(club=self.object, user=self.request.user)
|
||||||
if not self.request.user.is_root:
|
if not self.request.user.is_root:
|
||||||
form.fields.pop('start_date', None)
|
form.fields.pop('start_date', None)
|
||||||
# form.initial = {'user': self.request.user}
|
|
||||||
# form._user = self.request.user
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def form_valid(self, form):
|
||||||
"""
|
"""
|
||||||
Check user rights
|
Check user rights
|
||||||
"""
|
"""
|
||||||
self.object = self.get_object()
|
user = self.request.user
|
||||||
form = self.get_form()
|
ms = self.object.get_membership_for(user)
|
||||||
if form.is_valid():
|
|
||||||
ms = self.object.get_membership_for(request.user)
|
|
||||||
if (form.cleaned_data['role'] <= SITH_MAXIMUM_FREE_ROLE or
|
if (form.cleaned_data['role'] <= SITH_MAXIMUM_FREE_ROLE or
|
||||||
(ms is not None and ms.role >= form.cleaned_data['role']) or
|
(ms is not None and ms.role >= form.cleaned_data['role']) or
|
||||||
request.user.is_board_member or
|
user.is_board_member or user.is_root):
|
||||||
request.user.is_root):
|
form.save()
|
||||||
return self.form_valid(form)
|
form = self.form_class()
|
||||||
|
return super(ModelFormMixin, self).form_valid(form)
|
||||||
else:
|
else:
|
||||||
form.add_error(None, _("You do not have the permission to do that"))
|
form.add_error(None, _("You do not have the permission to do that"))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
else:
|
|
||||||
return self.form_invalid(form)
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
self.request = request
|
||||||
|
return super(ClubMembersView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_success_url(self, **kwargs):
|
||||||
|
return reverse_lazy('club:club_members', kwargs={'club_id': self.club.id})
|
||||||
|
|
||||||
|
|
||||||
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||||
|
Loading…
Reference in New Issue
Block a user