From d9a85948b3e8aa00837cac0b6ce34f99f08ac3a7 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 28 Dec 2020 12:59:12 +0100 Subject: [PATCH] Implement the data structure for members --- apps/registration/forms.py | 11 ++++- apps/registration/models.py | 82 ++++++++++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/apps/registration/forms.py b/apps/registration/forms.py index 80531d7..5f2ae99 100644 --- a/apps/registration/forms.py +++ b/apps/registration/forms.py @@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError from django.forms import FileInput from django.utils.translation import gettext_lazy as _ -from .models import AdminRegistration, CoachRegistration, StudentRegistration +from .models import AdminRegistration, CoachRegistration, StudentRegistration, VolunteerRegistration class SignupForm(UserCreationForm): @@ -101,6 +101,15 @@ class CoachRegistrationForm(forms.ModelForm): fields = ('team', 'professional_activity', 'give_contact_to_animath', 'email_confirmed',) +class VolunteerRegistrationForm(forms.ModelForm): + """ + A volunteer can also tell its professional activity. + """ + class Meta: + model = VolunteerRegistration + fields = ('professional_activity', 'give_contact_to_animath', 'email_confirmed',) + + class AdminRegistrationForm(forms.ModelForm): """ Admins can tell everything they want. diff --git a/apps/registration/models.py b/apps/registration/models.py index e7e0b12..536befc 100644 --- a/apps/registration/models.py +++ b/apps/registration/models.py @@ -91,24 +91,57 @@ class Registration(PolymorphicModel): verbose_name_plural = _("registrations") -def get_random_filename(instance, filename): +def get_random_photo_filename(instance, filename): return "authorization/photo/" + get_random_string(64) -class StudentRegistration(Registration): - """ - Specific registration for students. - They have a team, a student class and a school. - """ +def get_random_health_filename(instance, filename): + return "authorization/health/" + get_random_string(64) + + +def get_random_parental_filename(instance, filename): + return "authorization/parental/" + get_random_string(64) + + +class ParticipantRegistration(Registration): team = models.ForeignKey( "participation.Team", - related_name="students", + related_name="participants", on_delete=models.PROTECT, + blank=True, null=True, default=None, verbose_name=_("team"), ) + photo_authorization = models.FileField( + verbose_name=_("photo authorization"), + upload_to=get_random_photo_filename, + blank=True, + default="", + ) + + health_sheet = models.FileField( + verbose_name=_("health sheet"), + upload_to=get_random_health_filename, + blank=True, + default="", + ) + + @property + def type(self): + raise NotImplementedError + + @property + def form_class(self): + raise NotImplementedError + + +class StudentRegistration(ParticipantRegistration): + """ + Specific registration for students. + They have a team, a student class and a school. + """ student_class = models.IntegerField( choices=[ (12, _("12th grade")), @@ -123,9 +156,9 @@ class StudentRegistration(Registration): verbose_name=_("school"), ) - photo_authorization = models.FileField( - verbose_name=_("photo authorization"), - upload_to=get_random_filename, + parental_authorization = models.FileField( + verbose_name=_("parental authorization"), + upload_to=get_random_parental_filename, blank=True, default="", ) @@ -144,20 +177,11 @@ class StudentRegistration(Registration): verbose_name_plural = _("student registrations") -class CoachRegistration(Registration): +class CoachRegistration(ParticipantRegistration): """ Specific registration for coaches. They have a team and a professional activity. """ - team = models.ForeignKey( - "participation.Team", - related_name="coachs", - on_delete=models.PROTECT, - null=True, - default=None, - verbose_name=_("team"), - ) - professional_activity = models.TextField( verbose_name=_("professional activity"), ) @@ -176,6 +200,24 @@ class CoachRegistration(Registration): verbose_name_plural = _("coach registrations") +class VolunteerRegistration(Registration): + """ + Specific registration for organizers and juries. + """ + professional_activity = models.TextField( + verbose_name=_("professional activity"), + ) + + @property + def type(self): + return _('volunteer') + + @property + def form_class(self): + from registration.forms import VolunteerRegistrationForm + return VolunteerRegistrationForm + + class AdminRegistration(Registration): """ Specific registration for admins.