2019-08-02 12:57:53 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-06-11 23:34:13 +00:00
|
|
|
|
2019-08-08 10:16:40 +00:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
2019-08-02 12:57:53 +00:00
|
|
|
from django.db import models
|
2019-08-10 09:21:50 +00:00
|
|
|
from django.utils import timezone
|
2019-08-02 12:57:53 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2019-08-09 21:17:55 +00:00
|
|
|
from med.settings import MAX_EMPRUNT
|
2017-06-11 23:34:13 +00:00
|
|
|
|
2017-06-12 01:25:22 +00:00
|
|
|
|
2019-08-08 10:16:40 +00:00
|
|
|
class User(AbstractUser):
|
|
|
|
telephone = models.CharField(
|
|
|
|
verbose_name=_('phone number'),
|
|
|
|
max_length=15,
|
|
|
|
blank=True,
|
2019-08-02 19:35:30 +00:00
|
|
|
)
|
2019-08-08 10:16:40 +00:00
|
|
|
address = models.CharField(
|
|
|
|
verbose_name=_('address'),
|
|
|
|
max_length=255,
|
|
|
|
blank=True,
|
2019-08-02 16:37:54 +00:00
|
|
|
)
|
2019-08-08 10:16:40 +00:00
|
|
|
maxemprunt = models.IntegerField(
|
|
|
|
verbose_name=_('maximum borrowed'),
|
2019-08-08 13:35:25 +00:00
|
|
|
help_text=_('Maximal amount of simultaneous borrowed item '
|
|
|
|
'authorized.'),
|
2019-08-08 10:16:40 +00:00
|
|
|
default=MAX_EMPRUNT,
|
|
|
|
)
|
|
|
|
comment = models.CharField(
|
|
|
|
verbose_name=_('comment'),
|
|
|
|
help_text=_('Promotion...'),
|
|
|
|
max_length=255,
|
|
|
|
blank=True,
|
2019-08-02 16:37:54 +00:00
|
|
|
)
|
2019-08-10 09:21:50 +00:00
|
|
|
date_joined = models.DateTimeField(
|
|
|
|
_('date joined'),
|
|
|
|
default=timezone.now,
|
|
|
|
null=True,
|
|
|
|
)
|
2017-06-11 23:34:13 +00:00
|
|
|
|
2019-08-08 10:16:40 +00:00
|
|
|
REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
|
2017-06-11 23:34:13 +00:00
|
|
|
|
2017-07-04 22:47:05 +00:00
|
|
|
@property
|
2019-08-10 14:22:04 +00:00
|
|
|
def is_member(self):
|
|
|
|
last_year = Adhesion.objects.all().order_by(
|
2019-08-10 14:13:32 +00:00
|
|
|
'starting_in').reverse().first()
|
2019-08-10 14:22:04 +00:00
|
|
|
return last_year and self in last_year.members.all()
|
2017-07-04 22:47:05 +00:00
|
|
|
|
2017-06-11 23:34:13 +00:00
|
|
|
|
2017-07-04 22:47:05 +00:00
|
|
|
class Adhesion(models.Model):
|
2019-08-10 14:13:32 +00:00
|
|
|
starting_in = models.IntegerField(
|
|
|
|
verbose_name=_('starting in'),
|
|
|
|
help_text=_('Year in which the membership year starts.'),
|
|
|
|
unique=True,
|
|
|
|
)
|
|
|
|
ending_in = models.IntegerField(
|
|
|
|
verbose_name=_('ending in'),
|
|
|
|
help_text=_('Year in which the membership year ends.'),
|
|
|
|
unique=True,
|
|
|
|
)
|
|
|
|
members = models.ManyToManyField(
|
|
|
|
'User',
|
|
|
|
verbose_name=_('members'),
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('membership year')
|
|
|
|
verbose_name_plural = _('membership years')
|
2020-09-23 18:21:55 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.starting_in} - {self.ending_in}"
|