1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-26 06:22:23 +00:00
med/users/models.py

98 lines
2.5 KiB
Python
Raw Normal View History

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
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
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
2019-08-08 10:16:40 +00:00
class User(AbstractUser):
telephone = models.CharField(
verbose_name=_('phone number'),
max_length=15,
null=True,
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,
null=True,
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
)
date_joined = models.DateTimeField(
_('date joined'),
default=timezone.now,
null=True,
)
2019-08-08 10:16:40 +00:00
REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
@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-03 18:06:21 +00:00
class Clef(models.Model):
2019-08-10 14:13:32 +00:00
name = models.CharField(
verbose_name=_('name'),
max_length=255,
unique=True,
)
owner = models.ForeignKey(
'User',
on_delete=models.PROTECT,
verbose_name=_('owner'),
blank=True,
null=True,
)
comment = models.CharField(
verbose_name=_('comment'),
max_length=255,
null=True,
blank=True,
)
class Meta:
verbose_name = _('key')
verbose_name_plural = _('keys')
2017-07-03 18:06:21 +00:00
2019-08-02 12:57:53 +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')