mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-21 20:38:22 +02:00
Add leave team button
This commit is contained in:
@ -62,6 +62,9 @@
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#updateTeamModal">{% trans "Update" %}</button>
|
||||
{% if not team.participation.valid %}
|
||||
<button class="btn btn-danger" data-toggle="modal" data-target="#leaveTeamModal">{% trans "Leave" %}</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -120,6 +123,11 @@
|
||||
{% trans "Update" as modal_button %}
|
||||
{% url "participation:update_team" pk=team.pk as modal_action %}
|
||||
{% include "base_modal.html" with modal_id="updateTeam" %}
|
||||
|
||||
{% trans "Leave team" as modal_title %}
|
||||
{% trans "Leave" as modal_button %}
|
||||
{% url "participation:team_leave" as modal_action %}
|
||||
{% include "base_modal.html" with modal_id="leaveTeam" modal_button_type="danger" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
@ -130,6 +138,11 @@
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:update_team" pk=team.pk %} #form-content");
|
||||
});
|
||||
$('button[data-target="#leaveTeamModal"]').click(function() {
|
||||
let modalBody = $("#leaveTeamModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:team_leave" %} #form-content");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
13
apps/participation/templates/participation/team_leave.html
Normal file
13
apps/participation/templates/participation/team_leave.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<div class="alert alert-warning" id="form-content">
|
||||
{% csrf_token %}
|
||||
{% trans "Are you sure that you want to leave this team?" %}
|
||||
</div>
|
||||
<button class="btn btn-danger" type="submit">{% trans "Leave" %}</button>
|
||||
</form>
|
||||
{% endblock %}
|
@ -1,7 +1,8 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import CalendarView, CreateTeamView, JoinTeamView, MyParticipationDetailView, MyTeamDetailView, \
|
||||
ParticipationDetailView, PhaseUpdateView, TeamAuthorizationsView, TeamDetailView, TeamUpdateView, UploadVideoView
|
||||
ParticipationDetailView, PhaseUpdateView, TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamUpdateView, \
|
||||
UploadVideoView
|
||||
|
||||
|
||||
app_name = "participation"
|
||||
@ -13,6 +14,7 @@ urlpatterns = [
|
||||
path("team/<int:pk>/", TeamDetailView.as_view(), name="team_detail"),
|
||||
path("team/<int:pk>/update/", TeamUpdateView.as_view(), name="update_team"),
|
||||
path("team/<int:pk>/authorizations/", TeamAuthorizationsView.as_view(), name="team_authorizations"),
|
||||
path("team/leave/", TeamLeaveView.as_view(), name="team_leave"),
|
||||
path("detail/", MyParticipationDetailView.as_view(), name="my_participation_detail"),
|
||||
path("detail/<int:pk>/", ParticipationDetailView.as_view(), name="participation_detail"),
|
||||
path("detail/upload-video/<int:pk>/", UploadVideoView.as_view(), name="upload_video"),
|
||||
|
@ -2,6 +2,9 @@ from io import BytesIO
|
||||
import os
|
||||
from zipfile import ZipFile
|
||||
|
||||
from django.shortcuts import redirect
|
||||
from django.views.generic.base import View, TemplateView
|
||||
|
||||
from corres2math.lists import get_sympa_client
|
||||
from corres2math.views import AdminMixin
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
@ -236,6 +239,29 @@ class TeamAuthorizationsView(LoginRequiredMixin, DetailView):
|
||||
return response
|
||||
|
||||
|
||||
class TeamLeaveView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "participation/team_leave.html"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated:
|
||||
return self.handle_no_permission()
|
||||
if not request.user.registration.team:
|
||||
raise PermissionDenied(_("You are not in a team."))
|
||||
if request.user.registration.team.participation.valid is not None:
|
||||
raise PermissionDenied(_("The team is already validated or the validation is pending."))
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
@transaction.atomic()
|
||||
def post(self, request, *args, **kwargs):
|
||||
team = request.user.registration.team
|
||||
request.user.registration.team = None
|
||||
request.user.registration.save()
|
||||
get_sympa_client().unsubscribe(request.user.email, f"equipe-{team.trigram.lower()}", False)
|
||||
if team.students.count() + team.coachs.count() == 0:
|
||||
team.delete()
|
||||
return redirect(reverse_lazy("index"))
|
||||
|
||||
|
||||
class MyParticipationDetailView(LoginRequiredMixin, RedirectView):
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
user = self.request.user
|
||||
|
Reference in New Issue
Block a user