models.py 5.08 KB
Newer Older
1
# -*- mode: python; coding: utf-8 -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# Re2o un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017  Gabriel Détraz
# Copyright © 2017  Goulven Kermarec
# Copyright © 2017  Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 24 25
"""
Reglages généraux, machines, utilisateurs, mail, general pour l'application.
"""
26
from __future__ import unicode_literals
27 28

from django.db import models
chibrac's avatar
chibrac committed
29
from cotisations.models import Paiement
30

31 32

class OptionalUser(models.Model):
33 34
    """Options pour l'user : obligation ou nom du telephone,
    activation ou non du solde, autorisation du negatif, fingerprint etc"""
35 36
    PRETTY_NAME = "Options utilisateur"

37 38
    is_tel_mandatory = models.BooleanField(default=True)
    user_solde = models.BooleanField(default=False)
39 40 41 42 43
    solde_negatif = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        default=0
    )
44 45
    gpg_fingerprint = models.BooleanField(default=True)

chibrac's avatar
chibrac committed
46
    def clean(self):
47
        """Creation du mode de paiement par solde"""
chibrac's avatar
chibrac committed
48 49 50
        if self.user_solde:
            Paiement.objects.get_or_create(moyen="Solde")

51

52
class OptionalMachine(models.Model):
53 54
    """Options pour les machines : maximum de machines ou d'alias par user
    sans droit, activation de l'ipv6"""
55 56
    PRETTY_NAME = "Options machines"

57 58 59
    password_machine = models.BooleanField(default=False)
    max_lambdauser_interfaces = models.IntegerField(default=10)
    max_lambdauser_aliases = models.IntegerField(default=10)
60
    ipv6 = models.BooleanField(default=False)
61

62

63
class OptionalTopologie(models.Model):
64 65
    """Reglages pour la topologie : mode d'accès radius, vlan où placer
    les machines en accept ou reject"""
66
    PRETTY_NAME = "Options topologie"
67 68 69
    MACHINE = 'MACHINE'
    DEFINED = 'DEFINED'
    CHOICE_RADIUS = (
70 71 72
        (MACHINE, 'Sur le vlan de la plage ip machine'),
        (DEFINED, 'Prédéfini dans "Vlan où placer les machines\
            après acceptation RADIUS"'),
73
    )
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    radius_general_policy = models.CharField(
        max_length=32,
        choices=CHOICE_RADIUS,
        default='DEFINED'
    )
    vlan_decision_ok = models.OneToOneField(
        'machines.Vlan',
        on_delete=models.PROTECT,
        related_name='decision_ok',
        blank=True,
        null=True
    )
    vlan_decision_nok = models.OneToOneField(
        'machines.Vlan',
        on_delete=models.PROTECT,
        related_name='decision_nok',
        blank=True,
        null=True
    )
94

95 96

class GeneralOption(models.Model):
97 98
    """Options générales : nombre de resultats par page, nom du site,
    temps où les liens sont valides"""
99 100
    PRETTY_NAME = "Options générales"

101 102 103
    search_display_page = models.IntegerField(default=15)
    pagination_number = models.IntegerField(default=25)
    pagination_large_number = models.IntegerField(default=8)
104 105 106
    req_expire_hrs = models.IntegerField(default=48)
    site_name = models.CharField(max_length=32, default="Re2o")
    email_from = models.EmailField(default="www-data@serveur.net")
107

108

109
class Service(models.Model):
110 111
    """Liste des services affichés sur la page d'accueil : url, description,
    image et nom"""
112 113 114
    name = models.CharField(max_length=32)
    url = models.URLField()
    description = models.TextField()
115
    image = models.ImageField(upload_to='logo', blank=True)
116

117 118 119
    def __str__(self):
        return str(self.name)

120

121
class AssoOption(models.Model):
122
    """Options générales de l'asso : siret, addresse, nom, etc"""
123 124
    PRETTY_NAME = "Options de l'association"

125 126 127 128
    name = models.CharField(
        default="Association réseau école machin",
        max_length=256
    )
129 130 131 132 133 134
    siret = models.CharField(default="00000000000000", max_length=32)
    adresse1 = models.CharField(default="1 Rue de exemple", max_length=128)
    adresse2 = models.CharField(default="94230 Cachan", max_length=128)
    contact = models.EmailField(default="contact@example.org")
    telephone = models.CharField(max_length=15, default="0000000000")
    pseudo = models.CharField(default="Asso", max_length=32)
135 136 137 138 139 140 141
    utilisateur_asso = models.OneToOneField(
        'users.User',
        on_delete=models.PROTECT,
        blank=True,
        null=True
    )

142 143

class MailMessageOption(models.Model):
144
    """Reglages, mail de bienvenue et autre"""
145 146 147 148
    PRETTY_NAME = "Options de corps de mail"

    welcome_mail_fr = models.TextField(default="")
    welcome_mail_en = models.TextField(default="")