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:
Antoine Bartuccio 2017-10-01 23:14:47 +02:00
parent baa7be69e4
commit 4310441269
Signed by: klmp200
GPG Key ID: E7245548C53F904B

View File

@ -272,29 +272,31 @@ 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(): if (form.cleaned_data['role'] <= SITH_MAXIMUM_FREE_ROLE or
ms = self.object.get_membership_for(request.user) (ms is not None and ms.role >= form.cleaned_data['role']) or
if (form.cleaned_data['role'] <= SITH_MAXIMUM_FREE_ROLE or user.is_board_member or user.is_root):
(ms is not None and ms.role >= form.cleaned_data['role']) or form.save()
request.user.is_board_member or form = self.form_class()
request.user.is_root): return super(ModelFormMixin, self).form_valid(form)
return self.form_valid(form)
else:
form.add_error(None, _("You do not have the permission to do that"))
return self.form_invalid(form)
else: else:
form.add_error(None, _("You do not have the permission to do that"))
return self.form_invalid(form) 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):
""" """