1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-07-04 07:32:18 +02:00

Drop a lot of Corres2math content

This commit is contained in:
Yohann D'ANELLO
2020-12-28 18:52:50 +01:00
parent f5ec9d1054
commit 7ef602c6cd
28 changed files with 63 additions and 1286 deletions

View File

@ -3,13 +3,11 @@
import re
from bootstrap_datepicker_plus import DateTimePickerInput
from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db.models import Q
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from .models import Participation, Phase, Question, Team, Video
from .models import Participation, Team
class TeamForm(forms.ModelForm):
@ -25,7 +23,7 @@ class TeamForm(forms.ModelForm):
class Meta:
model = Team
fields = ('name', 'trigram', 'grant_animath_access_videos',)
fields = ('name', 'trigram',)
class JoinTeamForm(forms.ModelForm):
@ -56,7 +54,7 @@ class ParticipationForm(forms.ModelForm):
"""
class Meta:
model = Participation
fields = ('problem',)
fields = ('tournament',)
class RequestValidationForm(forms.Form):
@ -87,108 +85,3 @@ class ValidateParticipationForm(forms.Form):
label=_("Message to address to the team:"),
widget=forms.Textarea(),
)
class UploadVideoForm(forms.ModelForm):
"""
Form to upload a video, for a solution or a synthesis.
"""
class Meta:
model = Video
fields = ('link',)
def clean(self):
if Phase.current_phase().phase_number != 1 and Phase.current_phase().phase_number != 4 and self.instance.link:
self.add_error("link", _("You can't upload your video after the deadline."))
return super().clean()
class ReceiveParticipationForm(forms.ModelForm):
"""
Update the received participation of a participation.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["received_participation"].queryset = Participation.objects.filter(
~Q(pk=self.instance.pk) & Q(problem=self.instance.problem, valid=True)
)
class Meta:
model = Participation
fields = ('received_participation',)
class SendParticipationForm(forms.ModelForm):
"""
Update the sent participation of a participation.
"""
sent_participation = forms.ModelChoiceField(
queryset=Participation.objects,
label=lambda: _("Send to team"),
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
try:
self.fields["sent_participation"].initial = self.instance.sent_participation
except ObjectDoesNotExist: # No sent participation
pass
self.fields["sent_participation"].queryset = Participation.objects.filter(
~Q(pk=self.instance.pk) & Q(problem=self.instance.problem, valid=True)
)
def clean(self, commit=True):
cleaned_data = super().clean()
if "sent_participation" in cleaned_data:
participation = cleaned_data["sent_participation"]
participation.received_participation = self.instance
self.instance = participation
return cleaned_data
class Meta:
model = Participation
fields = ('sent_participation',)
class QuestionForm(forms.ModelForm):
"""
Create or update a question.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["question"].widget.attrs.update({"placeholder": _("How did you get the idea to ...?")})
def clean(self):
if Phase.current_phase().phase_number != 2:
self.add_error(None, _("You can only create or update a question during the second phase."))
return super().clean()
class Meta:
model = Question
fields = ('question',)
class PhaseForm(forms.ModelForm):
"""
Form to update the calendar of a phase.
"""
class Meta:
model = Phase
fields = ('start', 'end',)
widgets = {
'start': DateTimePickerInput(format='%d/%m/%Y %H:%M'),
'end': DateTimePickerInput(format='%d/%m/%Y %H:%M'),
}
def clean(self):
# Ensure that dates are in a right order
cleaned_data = super().clean()
start = cleaned_data["start"]
end = cleaned_data["end"]
if end <= start:
self.add_error("end", _("Start date must be before the end date."))
if Phase.objects.filter(phase_number__lt=self.instance.phase_number, end__gt=start).exists():
self.add_error("start", _("This phase must start after the previous phases."))
if Phase.objects.filter(phase_number__gt=self.instance.phase_number, start__lt=end).exists():
self.add_error("end", _("This phase must end after the next phases."))
return cleaned_data