3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-06-02 21:31:47 +00:00
coope/preferences/models.py

201 lines
7.2 KiB
Python
Raw Normal View History

2018-08-31 12:46:35 +00:00
from django.db import models
2018-11-27 08:07:12 +00:00
from simple_history.models import HistoricalRecords
from django.core.validators import MinValueValidator
2019-06-23 08:54:21 +00:00
from django.contrib.auth.models import User
2018-11-27 08:07:12 +00:00
2018-08-31 12:46:35 +00:00
class PaymentMethod(models.Model):
2018-12-02 15:28:40 +00:00
"""
2019-02-28 12:18:41 +00:00
Stores payment methods.
2018-12-02 15:28:40 +00:00
"""
2019-02-27 07:59:41 +00:00
class Meta:
verbose_name="Moyen de paiement"
verbose_name_plural = "Moyens de paiement"
2018-10-05 22:03:02 +00:00
name = models.CharField(max_length=255, verbose_name="Nom")
2019-02-28 12:18:41 +00:00
"""
The name of the PaymentMethod.
"""
2018-10-05 22:03:02 +00:00
is_active = models.BooleanField(default=True, verbose_name="Actif")
2019-02-28 12:18:41 +00:00
"""
If False, the PaymentMethod can't be use anywhere.
"""
2018-11-22 21:52:15 +00:00
is_usable_in_cotisation = models.BooleanField(default=True, verbose_name="Cotisations ?")
2019-02-28 12:18:41 +00:00
"""
If true, the PaymentMethod can be used to pay cotisation.
"""
2018-11-22 21:52:15 +00:00
is_usable_in_reload = models.BooleanField(default=True, verbose_name="Rechargements ?")
2019-02-28 12:18:41 +00:00
"""
If true, the PaymentMethod can be used to reload an user account.
"""
2018-10-05 22:03:02 +00:00
affect_balance = models.BooleanField(default=False, verbose_name="Affecte le solde")
2019-02-28 12:18:41 +00:00
"""
If true, the PaymentMethod will decrease the user's balance when used.
"""
2019-01-06 04:18:31 +00:00
icon = models.CharField(max_length=255, verbose_name="Icône", blank=True)
2019-02-28 12:18:41 +00:00
"""
A font awesome icon (without the fa)
"""
2018-11-27 08:07:12 +00:00
history = HistoricalRecords()
2018-08-31 12:46:35 +00:00
def __str__(self):
return self.name
class GeneralPreferences(models.Model):
2018-12-02 15:28:40 +00:00
"""
Stores a unique line of general preferences
"""
2019-02-27 07:59:41 +00:00
class Meta:
verbose_name="Préférences générales"
verbose_name_plural = "Préférences générales"
is_active = models.BooleanField(default=True, verbose_name="Site actif")
2019-02-28 12:18:41 +00:00
"""
If True, the site will be accessible. If False, all the requests are redirect to :func:`~preferences.views.inactive`.
"""
2019-02-27 07:59:41 +00:00
active_message = models.TextField(blank=True, verbose_name="Message non actif")
2019-02-28 12:18:41 +00:00
"""
Message displayed on the :func:`~preferences.views.inactive`
"""
2019-02-27 07:59:41 +00:00
global_message = models.TextField(blank=True, verbose_name="Message global")
2019-02-28 12:18:41 +00:00
"""
List of messages, separated by a carriage return. One will be chosen randomly at each request on displayed in the header
"""
2019-02-27 07:59:41 +00:00
president = models.CharField(max_length=255, blank=True, verbose_name="Président")
2019-02-28 12:18:41 +00:00
"""
The name of the president
"""
2019-02-27 07:59:41 +00:00
treasurer = models.CharField(max_length=255, blank=True, verbose_name="Trésorier")
2019-02-28 12:18:41 +00:00
"""
The name of the treasurer
"""
2019-02-27 07:59:41 +00:00
secretary = models.CharField(max_length=255, blank=True, verbose_name="Secrétaire")
2019-02-28 12:18:41 +00:00
"""
The name of the secretary
"""
phoenixTM_responsible = models.CharField(max_length=255, blank=True, verbose_name="Responsable Phœnix Technopôle Metz")
2019-02-28 12:18:41 +00:00
"""
The name of the people in charge of the club
2019-02-28 12:18:41 +00:00
"""
2019-02-27 07:59:41 +00:00
use_pinte_monitoring = models.BooleanField(default=False, verbose_name="Suivi de pintes")
2019-02-28 12:18:41 +00:00
"""
If True, alert will be displayed to allocate pints during order
"""
2019-02-27 07:59:41 +00:00
lost_pintes_allowed = models.PositiveIntegerField(default=0, verbose_name="Nombre de pintes perdus admises")
2019-02-28 12:18:41 +00:00
"""
If > 0, a user will be blocked if he has losted more pints than the value
"""
2019-02-27 07:59:41 +00:00
floating_buttons = models.BooleanField(default=False, verbose_name="Boutons flottants")
2019-02-28 12:18:41 +00:00
"""
If True, displays floating paymentButtons on the :func:`~gestion.views.manage` view.
"""
2019-02-27 07:59:41 +00:00
home_text = models.TextField(blank=True, verbose_name="Message d'accueil")
2019-02-28 12:18:41 +00:00
"""
Text display on the home page
"""
2019-02-27 07:59:41 +00:00
automatic_logout_time = models.PositiveIntegerField(null=True, verbose_name="Temps de déconnexion automatique")
2019-02-28 12:18:41 +00:00
"""
Duration after which the user is automatically disconnected if inactive
"""
2019-02-27 07:59:41 +00:00
statutes = models.FileField(blank=True, null=True, verbose_name="Statuts")
2019-02-28 12:18:41 +00:00
"""
The file of the statutes
"""
2019-02-27 07:59:41 +00:00
rules = models.FileField(blank=True, null=True, verbose_name="Règlement intérieur")
2019-02-28 12:18:41 +00:00
"""
The file of the internal rules
"""
2019-02-27 07:59:41 +00:00
menu = models.FileField(blank=True, null=True, verbose_name="Menu")
2019-02-28 12:18:41 +00:00
"""
The file of the menu
"""
2019-04-28 11:22:09 +00:00
alcohol_charter = models.FileField(blank=True, null=True, verbose_name="Charte alcool")
"""
The file of the alcohol charter
"""
2018-11-27 08:07:12 +00:00
history = HistoricalRecords()
2018-10-05 22:03:02 +00:00
class Cotisation(models.Model):
2018-12-02 15:28:40 +00:00
"""
2019-02-28 12:18:41 +00:00
Stores cotisations.
2018-12-02 15:28:40 +00:00
"""
2019-06-23 08:54:21 +00:00
class Meta:
permissions = (("can_divide", "Can divide money for cotisation"),)
2018-11-27 08:07:12 +00:00
amount = models.DecimalField(max_digits=5, decimal_places=2, null=True, verbose_name="Montant", validators=[MinValueValidator(0)])
2019-02-28 12:18:41 +00:00
"""
Price of the cotisation.
"""
2018-10-05 22:03:02 +00:00
duration = models.PositiveIntegerField(verbose_name="Durée de la cotisation (jours)")
2019-02-28 12:18:41 +00:00
"""
Duration (in days) of the cotisation
"""
2019-06-23 08:54:21 +00:00
amount_ptm = models.DecimalField(max_digits=5, decimal_places=2, null=True, verbose_name="Montant pour le club Phœnix Technopôle Metz")
"""
Amount of money given to the PTM club
"""
2018-11-27 08:07:12 +00:00
history = HistoricalRecords()
2018-10-05 22:03:02 +00:00
def __str__(self):
2019-06-09 23:35:48 +00:00
if self.duration == 1:
jour = "jour"
else:
jour = "jours"
return "Cotisation de " + str(self.duration) + " " + jour + " pour le prix de " + str(self.amount) + ""
2019-06-23 08:54:21 +00:00
class DivideHistory(models.Model):
"""
Stores divide history
"""
class Meta:
verbose_name = "Historique répartition"
date = models.DateTimeField(auto_now_add=True)
"""
Date of the divide
"""
total_cotisations = models.IntegerField(verbose_name="Nombre de cotisations")
"""
Number of non-divided cotisations (before the divide)
"""
total_cotisations_amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant total des cotisations")
"""
Amount of non-divided cotisations (before the divide)
"""
total_ptm_amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant donné au Phœnix Technopôle Metz")
"""
Amount given to the PTM
"""
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="divide_realized")
"""
Coopeman (:class:`django.contrib.auth.models.User`) who collected the reload.
"""
def __str__(self):
return "Répartition du " + str(self.date)
2019-06-23 12:53:18 +00:00
class PriceProfile(models.Model):
"""
Stores parameters to compute price
"""
name = models.CharField(max_length=255, verbose_name="Nom")
a = models.DecimalField(verbose_name="Marge constante", max_digits=3, decimal_places=2)
b = models.DecimalField(verbose_name="Marge variable", max_digits=3, decimal_places=2)
c = models.DecimalField(verbose_name="Paramètre de forme", max_digits=4, decimal_places=2)
alpha = models.DecimalField(verbose_name="Étendue", max_digits=4, decimal_places=2)
use_for_draft = models.BooleanField(default=False, verbose_name="Utiliser pour les pressions ?")
def save(self, *args, **kwargs):
if self.use_for_draft:
try:
temp = PriceProfile.objects.get(use_for_draft=True)
if self != temp:
temp.use_for_draft = False
temp.save()
except PriceProfile.DoesNotExist:
pass
super(PriceProfile, self).save(*args, **kwargs)
def __str__(self):
return self.name