diff --git a/apps/participation/forms.py b/apps/participation/forms.py index 02a8279..782cdc1 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -59,6 +59,21 @@ class ParticipationForm(forms.ModelForm): fields = ('tournament',) +class MotivationLetterForm(forms.ModelForm): + def clean_file(self): + if "file" in self.files: + file = self.files["motivation_letter"] + if file.size > 2e6: + raise ValidationError(_("The uploaded file size must be under 2 Mo.")) + if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]: + raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file.")) + return self.cleaned_data["motivation_letter"] + + class Meta: + model = Team + fields = ('motivation_letter',) + + class RequestValidationForm(forms.Form): """ Form to ask about validation. diff --git a/apps/participation/migrations/0003_team_motivation_letter.py b/apps/participation/migrations/0003_team_motivation_letter.py new file mode 100644 index 0000000..fb298af --- /dev/null +++ b/apps/participation/migrations/0003_team_motivation_letter.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.11 on 2021-01-22 08:15 + +from django.db import migrations, models +import participation.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('participation', '0002_auto_20210121_2206'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='motivation_letter', + field=models.FileField(blank=True, default='', upload_to=participation.models.get_motivation_letter_filename, verbose_name='motivation letter'), + ), + ] diff --git a/apps/participation/models.py b/apps/participation/models.py index d19a0d6..912125b 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -20,6 +20,10 @@ from tfjm.lists import get_sympa_client from tfjm.matrix import Matrix, RoomPreset, RoomVisibility +def get_motivation_letter_filename(instance, filename): + return f"authorization/motivation_letters/motivation_letter_{instance.trigram}" + + class Team(models.Model): """ The Team model represents a real team that participates to the TFJM². @@ -45,6 +49,13 @@ class Team(models.Model): help_text=_("The access code let other people to join the team."), ) + motivation_letter = models.FileField( + verbose_name=_("motivation letter"), + upload_to=get_motivation_letter_filename, + blank=True, + default="", + ) + @property def students(self): return self.participants.filter(studentregistration__isnull=False) diff --git a/apps/participation/templates/participation/team_detail.html b/apps/participation/templates/participation/team_detail.html index 03dc45f..ff3acac 100644 --- a/apps/participation/templates/participation/team_detail.html +++ b/apps/participation/templates/participation/team_detail.html @@ -85,6 +85,18 @@ {% endif %} {% endfor %} + +
{% trans "Motivation letter:" %}
+
+ {% if team.motivation_letter %} + {% trans "Download" %} + {% else %} + {% trans "Not uploaded yet" %} + {% endif %} + {% if user.registration.team == team and not user.registration.team.participation.valid or user.registration.is_admin %} + + {% endif %} +