Commit 03fdd0b9 authored by Sli's avatar Sli

Merge branch 'trombi' into 'master'

trombi: raw tool for trombi admins to add a club membership to a trombi member

See merge request !266
parents 7ee4557a fb8faacd
Pipeline #2177 passed with stage
in 30 minutes and 46 seconds
This diff is collapsed.
......@@ -33,6 +33,7 @@
</div>
<div>{{ u.user.get_display_name() }}</div>
<div><a href="{{ url('trombi:delete_user', user_id=u.id) }}">{% trans %}Delete{% endtrans %}</a></div>
<div><a href="{{ url('trombi:create_membership', user_id=u.id) }}">{% trans %}Add club membership{% endtrans %}</a></div>
</div>
{% endfor %}
</div>
......
# -*- coding:utf-8 -*
#
# Copyright 2017
# Copyright 2017,2020
# - Skia <skia@libskia.so>
# - Sli <antoine@bartuccio.fr>
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
......@@ -81,4 +82,9 @@ urlpatterns = [
UserTrombiDeleteMembershipView.as_view(),
name="delete_membership",
),
re_path(
r"^membership/(?P<user_id>[0-9]+)/create$",
UserTrombiAddMembershipView.as_view(),
name="create_membership",
),
]
# -*- coding:utf-8 -*
#
# Copyright 2017
# Copyright 2017,2020
# - Skia <skia@libskia.so>
# - Sli <antoine.bartuccio@gmail.com>
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
......@@ -31,6 +32,7 @@ from django.utils.translation import ugettext_lazy as _
from django import forms
from django.conf import settings
from django.forms.models import modelform_factory
from django.core.exceptions import PermissionDenied
from ajax_select.fields import AutoCompleteSelectField
......@@ -410,6 +412,35 @@ class UserTrombiDeleteMembershipView(TrombiTabsMixin, CanEditMixin, DeleteView):
)
# Used by admins when someone does not have every club in his list
class UserTrombiAddMembershipView(TrombiTabsMixin, CreateView):
model = TrombiClubMembership
template_name = "core/edit.jinja"
fields = ["club", "role", "start", "end"]
pk_url_kwarg = "user_id"
current_tab = "profile"
def dispatch(self, request, *arg, **kwargs):
self.trombi_user = get_object_or_404(TrombiUser, pk=kwargs["user_id"])
if not self.trombi_user.trombi.is_owned_by(request.user):
raise PermissionDenied()
return super(UserTrombiAddMembershipView, self).dispatch(
request, *arg, **kwargs
)
def form_valid(self, form):
membership = form.save(commit=False)
membership.user = self.trombi_user
membership.save()
return HttpResponseRedirect(self.get_success_url())
def get_success_url(self):
return reverse(
"trombi:detail", kwargs={"trombi_id": self.trombi_user.trombi.id}
)
class UserTrombiEditMembershipView(CanEditMixin, TrombiTabsMixin, UpdateView):
model = TrombiClubMembership
pk_url_kwarg = "membership_id"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment