Implement the data structure for members

This commit is contained in:
Yohann D'ANELLO 2020-12-28 12:59:12 +01:00
parent 03eca29316
commit d9a85948b3
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 72 additions and 21 deletions

View File

@ -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.

View File

@ -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.