101 lines
3.5 KiB
Python
101 lines
3.5 KiB
Python
from django.contrib.auth.models import AbstractUser, UserManager
|
|
from django.db import models
|
|
from django.template.defaultfilters import linebreaksbr
|
|
from django.utils.safestring import SafeString
|
|
|
|
|
|
class CustomUserManager(UserManager):
|
|
def create_superuser(self, **kwargs):
|
|
return super().create_superuser("foo", **kwargs)
|
|
|
|
|
|
class User(AbstractUser):
|
|
username = None
|
|
USERNAME_FIELD = "email"
|
|
REQUIRED_FIELDS = []
|
|
|
|
objects = CustomUserManager()
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(name="unique_user_email", fields=["email"]),
|
|
]
|
|
|
|
def __init__(self, *args, username=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
class Membre(models.Model):
|
|
nom = models.CharField("Nom", max_length=40)
|
|
prenom = models.CharField("Prénom", max_length=40)
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
|
|
fonction = models.CharField("Fonction", max_length=100, blank=True)
|
|
avatar = models.ImageField("Avatar", upload_to="avatars", blank=True)
|
|
rue = models.CharField("Rue", max_length=80, blank=True)
|
|
npa = models.CharField("NPA", max_length=5, blank=True)
|
|
localite = models.CharField("Localité", max_length=40, blank=True)
|
|
tel1 = models.CharField("Tél. 1", max_length=20, blank=True)
|
|
tel2 = models.CharField("Tél. 2", max_length=20, blank=True)
|
|
courriel = models.EmailField("Courriel", blank=True)
|
|
date_naissance = models.DateField("Date de naissance", null=True, blank=True)
|
|
annee_entree = models.PositiveSmallIntegerField("Année entrée", null=True, blank=True)
|
|
|
|
def __str__(self):
|
|
return f"{self.nom} {self.prenom}"
|
|
|
|
|
|
class Agenda(models.Model):
|
|
titre = models.CharField("Titre", max_length=150)
|
|
lieu = models.CharField("Lieu", max_length=80, blank=True)
|
|
date_heure = models.DateTimeField("Date/heure")
|
|
infos = models.TextField("Informations", blank=True)
|
|
infos_internes = models.TextField("Informations internes", blank=True)
|
|
prive = models.BooleanField(
|
|
"Privé", default=False, help_text=(
|
|
"Un évènement privé ne peut être consulté que par les membres de "
|
|
"l'association, tandis qu'un évènement public est visible de tous."
|
|
)
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = "Agenda"
|
|
verbose_name_plural = "Agenda"
|
|
|
|
def __str__(self):
|
|
return f"{self.titre} {self.date_heure}"
|
|
|
|
|
|
class Document(models.Model):
|
|
class Categories(models.TextChoices):
|
|
VIDEO = "video", "Vidéo"
|
|
AUDIO = "audio", "Audio"
|
|
PHOTOS = "photos", "Photos"
|
|
DOCUMENT = "doc", "Document"
|
|
|
|
fichier = models.FileField("Fichier", upload_to="documents", blank=True)
|
|
url = models.URLField("URL", blank=True)
|
|
quand = models.DateField("Date")
|
|
titre = models.CharField("Titre", max_length=150)
|
|
infos = models.TextField("Infos", blank=True)
|
|
categorie = models.CharField("Catégorie", max_length=30, choices=Categories)
|
|
prive = models.BooleanField(
|
|
"Privé", default=False, help_text=(
|
|
"Un document privé ne peut être consulté que par les membres de "
|
|
"l'association, tandis qu'un document public est visible de tous."
|
|
)
|
|
)
|
|
|
|
def __str__(self):
|
|
return f"{self.titre} {self.quand}"
|
|
|
|
def print_infos(self):
|
|
if self.infos.startswith("<"):
|
|
return SafeString(self.infos)
|
|
return linebreaksbr(self.infos)
|
|
|
|
def get_url(self):
|
|
if self.url:
|
|
return self.url
|
|
elif self.fichier:
|
|
return self.fichier.url
|