mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-11-26 18:07:10 +00:00
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
# -*- mode: python; coding: utf-8 -*-
|
|
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
from django.utils.translation import gettext_lazy as _
|
|
from med.settings import MAX_EMPRUNT
|
|
|
|
|
|
class User(AbstractUser):
|
|
telephone = models.CharField(
|
|
verbose_name=_('phone number'),
|
|
max_length=15,
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
address = models.CharField(
|
|
verbose_name=_('address'),
|
|
max_length=255,
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
maxemprunt = models.IntegerField(
|
|
verbose_name=_('maximum borrowed'),
|
|
help_text=_('Maximal amount of simultaneous borrowed item '
|
|
'authorized.'),
|
|
default=MAX_EMPRUNT,
|
|
)
|
|
comment = models.CharField(
|
|
verbose_name=_('comment'),
|
|
help_text=_('Promotion...'),
|
|
max_length=255,
|
|
blank=True,
|
|
)
|
|
date_joined = models.DateTimeField(
|
|
_('date joined'),
|
|
default=timezone.now,
|
|
null=True,
|
|
)
|
|
|
|
REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
|
|
|
|
@property
|
|
def is_member(self):
|
|
last_year = Adhesion.objects.all().order_by(
|
|
'starting_in').reverse().first()
|
|
return last_year and self in last_year.members.all()
|
|
|
|
|
|
class Adhesion(models.Model):
|
|
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')
|