nk20/apps/wei/models.py

240 lines
5.9 KiB
Python
Raw Normal View History

2020-04-11 01:37:06 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
2020-04-11 21:02:12 +00:00
2020-04-11 15:42:08 +00:00
import json
2020-04-11 01:37:06 +00:00
from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import gettext_lazy as _
2020-04-11 15:42:08 +00:00
from member.models import Role, Club, Membership
2020-04-11 01:37:06 +00:00
from note.models import NoteSpecial
2020-04-11 15:42:08 +00:00
class WEIClub(Club):
2020-04-11 01:37:06 +00:00
"""
2020-04-11 21:02:12 +00:00
The WEI is a club. Register to the WEI is equivalent than be member of the club.
2020-04-11 01:37:06 +00:00
"""
year = models.PositiveIntegerField(
unique=True,
verbose_name=_("year"),
)
2020-04-11 21:02:12 +00:00
date_start = models.DateField(
verbose_name=_("date start"),
)
date_end = models.DateField(
verbose_name=_("date end"),
)
2020-04-11 15:42:08 +00:00
def update_membership_dates(self):
"""
We can't join the WEI next years.
"""
return
2020-04-11 01:37:06 +00:00
class Bus(models.Model):
"""
The best bus for the best WEI
"""
wei = models.ForeignKey(
2020-04-11 15:42:08 +00:00
WEIClub,
2020-04-11 01:37:06 +00:00
on_delete=models.PROTECT,
related_name="buses",
verbose_name=_("WEI"),
)
name = models.CharField(
max_length=255,
verbose_name=_("name"),
)
def __str__(self):
return self.name
class Meta:
unique_together = ('wei', 'name',)
class BusTeam(models.Model):
"""
A bus has multiple teams
"""
bus = models.ForeignKey(
Bus,
on_delete=models.CASCADE,
related_name="teams",
verbose_name=_("bus"),
)
name = models.CharField(
max_length=255,
)
color = models.PositiveIntegerField( # Use a color picker to get the hexa code
verbose_name=_("color"),
help_text=_("The color of the T-Shirt, stored with its number equivalent"),
)
def __str__(self):
return self.name + " (" + str(self.bus) + ")"
class Meta:
unique_together = ('bus', 'name',)
verbose_name = _("Bus team")
verbose_name_plural = _("Bus teams")
2020-04-11 15:42:08 +00:00
class WEIRole(Role):
2020-04-11 01:37:06 +00:00
"""
A Role for the WEI can be bus chief, team chief, free electron, ...
"""
2020-04-11 15:42:08 +00:00
bus = models.ForeignKey(
Bus,
on_delete=models.CASCADE,
2020-04-11 21:02:12 +00:00
null=True,
default=None,
2020-04-11 15:42:08 +00:00
related_name="roles",
verbose_name=_("bus"),
2020-04-11 01:37:06 +00:00
)
2020-04-11 15:42:08 +00:00
class WEIRegistration(models.Model):
2020-04-11 01:37:06 +00:00
"""
Store personal data that can be useful for the WEI.
"""
user = models.ForeignKey(
User,
on_delete=models.PROTECT,
related_name="wei",
verbose_name=_("user"),
)
wei = models.ForeignKey(
2020-04-11 15:42:08 +00:00
WEIClub,
2020-04-11 01:37:06 +00:00
on_delete=models.PROTECT,
related_name="users",
verbose_name=_("WEI"),
)
2020-04-11 15:42:08 +00:00
payment_method = models.ForeignKey(
NoteSpecial,
2020-04-11 01:37:06 +00:00
on_delete=models.PROTECT,
2020-04-11 15:42:08 +00:00
null=True, # null = no credit, paid with note
related_name="+",
verbose_name=_("payment method"),
)
soge_credit = models.BooleanField(
verbose_name=_("Credit from Société générale"),
2020-04-11 01:37:06 +00:00
)
birth_date = models.DateField(
verbose_name=_("birth date"),
)
gender = models.CharField(
max_length=16,
choices=(
('male', _("Male")),
('female', _("Female")),
('nonbinary', _("Non binary")),
),
verbose_name=_("gender"),
)
health_issues = models.TextField(
verbose_name=_("health issues"),
)
emergency_contact_name = models.CharField(
max_length=255,
verbose_name=_("emergency contact name"),
)
emergency_contact_phone = models.CharField(
max_length=32,
verbose_name=_("emergency contact phone"),
)
2020-04-11 15:42:08 +00:00
ml_events_registration = models.BooleanField(
2020-04-11 01:37:06 +00:00
verbose_name=_("Register on the mailing list to stay informed of the events of the campus (1 mail/week)"),
)
2020-04-11 15:42:08 +00:00
ml_sport_registration = models.BooleanField(
2020-04-11 01:37:06 +00:00
verbose_name=_("Register on the mailing list to stay informed of the sport events of the campus (1 mail/week)"),
)
2020-04-11 15:42:08 +00:00
ml_art_registration = models.BooleanField(
2020-04-11 01:37:06 +00:00
verbose_name=_("Register on the mailing list to stay informed of the art events of the campus (1 mail/week)"),
)
2020-04-11 15:42:08 +00:00
information_json = models.TextField(
verbose_name=_("registration information"),
help_text=_("Information about the registration (buses for old members, survey fot the new members), "
"encoded in JSON"),
2020-04-11 01:37:06 +00:00
)
2020-04-11 15:42:08 +00:00
@property
def information(self):
"""
The information about the registration (the survey for the new members, the bus for the older members, ...)
are stored in a dictionary that can evolve following the years. The dictionary is stored as a JSON string.
"""
return json.loads(self.information_json)
@information.setter
def information(self, information):
"""
Store information as a JSON string
"""
self.information_json = json.dumps(information)
@property
def is_1A(self):
"""
We assume that a user is a new member if it not fully registered yet.
"""
return not self.user.profile.registration_valid
def __str__(self):
return str(self.user)
class Meta:
unique_together = ('user', 'wei',)
verbose_name = _("WEI User")
verbose_name_plural = _("WEI Users")
class WEIMembership(Membership):
bus = models.ForeignKey(
2020-04-11 01:37:06 +00:00
Bus,
on_delete=models.PROTECT,
2020-04-11 15:42:08 +00:00
null=True,
default=None,
verbose_name=_("bus"),
2020-04-11 01:37:06 +00:00
)
2020-04-11 15:42:08 +00:00
team = models.ForeignKey(
BusTeam,
2020-04-11 01:37:06 +00:00
on_delete=models.PROTECT,
2020-04-11 15:42:08 +00:00
related_name="memberships",
2020-04-11 01:37:06 +00:00
null=True,
blank=True,
2020-04-11 15:42:08 +00:00
default=None,
verbose_name=_("team"),
2020-04-11 01:37:06 +00:00
)
2020-04-11 15:42:08 +00:00
registration = models.OneToOneField(
WEIRegistration,
2020-04-11 01:37:06 +00:00
on_delete=models.PROTECT,
null=True,
blank=True,
2020-04-11 15:42:08 +00:00
default=None,
related_name="membership",
verbose_name=_("WEI registration"),
2020-04-11 01:37:06 +00:00
)