1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 07:58:26 +02:00

Add & join teams

This commit is contained in:
Yohann D'ANELLO
2020-05-05 00:56:34 +02:00
parent b55aa6f4f3
commit 3889256fb1
8 changed files with 82 additions and 24 deletions

View File

@ -43,6 +43,16 @@ class JoinTeam(forms.Form):
max_length=6,
)
def clean(self):
cleaned_data = super().clean()
team = Team.objects.filter(access_code=cleaned_data["access_code"])
if not team.exists():
self.add_error('access_code', _("This access code is invalid."))
cleaned_data["team"] = team.get()
return cleaned_data
class SolutionForm(forms.ModelForm):
problem = forms.ChoiceField(

View File

@ -14,7 +14,7 @@ from django.views.generic.edit import BaseFormView
from django_tables2.views import SingleTableView
from member.models import TFJMUser, Solution, Synthesis
from .forms import TournamentForm, OrganizerForm, TeamForm, SolutionForm, SynthesisForm
from .forms import TournamentForm, OrganizerForm, SolutionForm, SynthesisForm, TeamForm
from .models import Tournament, Team
from .tables import TournamentTable, TeamTable, SolutionTable, SynthesisTable
@ -128,6 +128,12 @@ class TeamDetailView(LoginRequiredMixin, DetailView):
.format(_("Solutions for team {team}.zip")
.format(team=str(team)).replace(" ", "%20"))
return resp
elif "leave" in request.POST:
request.user.team = None
request.user.save()
if not team.users.exists():
team.delete()
return redirect('tournament:detail', pk=team.tournament.pk)
elif "delete" in request.POST:
team.delete()
return redirect('tournament:detail', pk=team.tournament.pk)