8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 11:26:27 +00:00

Merge branch 'end_sub_mail' into crans

This commit is contained in:
Grizzly 2018-07-01 16:51:07 +00:00
commit 81c78685d3
10 changed files with 365 additions and 201 deletions

View file

@ -35,6 +35,7 @@ from .models import (
GeneralOption, GeneralOption,
Service, Service,
MailContact, MailContact,
Reminder,
AssoOption, AssoOption,
MailMessageOption, MailMessageOption,
HomeOption HomeOption
@ -85,6 +86,9 @@ class HomeOptionAdmin(VersionAdmin):
"""Class admin options home""" """Class admin options home"""
pass pass
class ReminderAdmin(VersionAdmin):
"""Class reminder"""
pass
admin.site.register(OptionalUser, OptionalUserAdmin) admin.site.register(OptionalUser, OptionalUserAdmin)
admin.site.register(OptionalMachine, OptionalMachineAdmin) admin.site.register(OptionalMachine, OptionalMachineAdmin)
@ -93,5 +97,6 @@ admin.site.register(GeneralOption, GeneralOptionAdmin)
admin.site.register(HomeOption, HomeOptionAdmin) admin.site.register(HomeOption, HomeOptionAdmin)
admin.site.register(Service, ServiceAdmin) admin.site.register(Service, ServiceAdmin)
admin.site.register(MailContact, MailContactAdmin) admin.site.register(MailContact, MailContactAdmin)
admin.site.register(Reminder, ReminderAdmin)
admin.site.register(AssoOption, AssoOptionAdmin) admin.site.register(AssoOption, AssoOptionAdmin)
admin.site.register(MailMessageOption, MailMessageOptionAdmin) admin.site.register(MailMessageOption, MailMessageOptionAdmin)

View file

@ -24,6 +24,7 @@ Formulaire d'edition des réglages : user, machine, topologie, asso...
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from re2o.mixins import FormRevMixin
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from django import forms from django import forms
@ -36,7 +37,8 @@ from .models import (
MailMessageOption, MailMessageOption,
HomeOption, HomeOption,
Service, Service,
MailContact MailContact,
Reminder
) )
class EditOptionalUserForm(ModelForm): class EditOptionalUserForm(ModelForm):
@ -52,18 +54,6 @@ class EditOptionalUserForm(ModelForm):
prefix=prefix, prefix=prefix,
**kwargs **kwargs
) )
self.fields['is_tel_mandatory'].label = (
'Exiger un numéro de téléphone'
)
self.fields['user_solde'].label = (
'Activation du solde pour les utilisateurs'
)
self.fields['max_solde'].label = 'Solde maximum'
self.fields['min_online_payment'].label = (
'Montant de rechargement minimum en ligne'
)
self.fields['self_adhesion'].label = 'Auto inscription'
class EditOptionalMachineForm(ModelForm): class EditOptionalMachineForm(ModelForm):
"""Options machines (max de machines, etc)""" """Options machines (max de machines, etc)"""
@ -208,7 +198,7 @@ class EditHomeOptionForm(ModelForm):
) )
class ServiceForm(ModelForm): class ServiceForm(FormRevMixin, ModelForm):
"""Edition, ajout de services sur la page d'accueil""" """Edition, ajout de services sur la page d'accueil"""
class Meta: class Meta:
model = Service model = Service
@ -218,22 +208,16 @@ class ServiceForm(ModelForm):
prefix = kwargs.pop('prefix', self.Meta.model.__name__) prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs) super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)
class ReminderForm(FormRevMixin, ModelForm):
class DelServiceForm(Form): """Edition, ajout de rappel"""
"""Suppression de services sur la page d'accueil""" class Meta:
services = forms.ModelMultipleChoiceField( model = Reminder
queryset=Service.objects.none(), fields = '__all__'
label="Enregistrements service actuels",
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None) prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(DelServiceForm, self).__init__(*args, **kwargs) super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs)
if instances:
self.fields['services'].queryset = instances
else:
self.fields['services'].queryset = Service.objects.all()
class MailContactForm(ModelForm): class MailContactForm(ModelForm):
"""Edition, ajout d'adresse de contact""" """Edition, ajout d'adresse de contact"""

View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-05-05 10:53
from __future__ import unicode_literals
from django.db import migrations, models
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('preferences', '0034_auto_20180416_1120'),
]
operations = [
migrations.CreateModel(
name='Reminder',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('days', models.IntegerField(default=7, help_text="Délais entre le mail et la fin d'adhésion", unique=True)),
('message', models.CharField(blank=True, default='', max_length=255, null=True)),
],
options={
'permissions': (('view_reminder', 'Peut voir un objet reminder'),),
},
bases=(re2o.mixins.AclMixin, models.Model),
),
]

View file

@ -67,24 +67,35 @@ class OptionalUser(AclMixin, PreferencesModel):
activation ou non du solde, autorisation du negatif, fingerprint etc""" activation ou non du solde, autorisation du negatif, fingerprint etc"""
PRETTY_NAME = "Options utilisateur" PRETTY_NAME = "Options utilisateur"
is_tel_mandatory = models.BooleanField(default=True) is_tel_mandatory = models.BooleanField(
user_solde = models.BooleanField(default=False) default=True,
help_text="Obligation de renseigner le téléphone"
)
user_solde = models.BooleanField(
default=False,
help_text="Solde pour les users"
)
solde_negatif = models.DecimalField( solde_negatif = models.DecimalField(
max_digits=5, max_digits=5,
decimal_places=2, decimal_places=2,
default=0 default=0,
help_text="Maximum de négatif autorisé"
) )
max_solde = models.DecimalField( max_solde = models.DecimalField(
max_digits=5, max_digits=5,
decimal_places=2, decimal_places=2,
default=50 default=50,
help_text="Valeur maximum du solde"
) )
min_online_payment = models.DecimalField( min_online_payment = models.DecimalField(
max_digits=5, max_digits=5,
decimal_places=2, decimal_places=2,
default=10 default=10,
help_text="Montant minimum pour le rechargement online"
) )
gpg_fingerprint = models.BooleanField(default=True) gpg_fingerprint = models.BooleanField(
default=True,
help_text="Gpg fingerprint activée")
all_can_create_club = models.BooleanField( all_can_create_club = models.BooleanField(
default=False, default=False,
help_text="Les users peuvent créer un club" help_text="Les users peuvent créer un club"
@ -101,7 +112,8 @@ class OptionalUser(AclMixin, PreferencesModel):
'users.ListShell', 'users.ListShell',
on_delete=models.PROTECT, on_delete=models.PROTECT,
blank=True, blank=True,
null=True null=True,
help_text="Shell par default"
) )
mail_accounts = models.BooleanField( mail_accounts = models.BooleanField(
default=False, default=False,
@ -157,13 +169,20 @@ class OptionalMachine(AclMixin, PreferencesModel):
(DISABLED, 'Désactivé'), (DISABLED, 'Désactivé'),
) )
password_machine = models.BooleanField(default=False) password_machine = models.BooleanField(
max_lambdauser_interfaces = models.IntegerField(default=10) default=False,
max_lambdauser_aliases = models.IntegerField(default=10) help_text="Un mot de passe par machine activé")
max_lambdauser_interfaces = models.IntegerField(
default=10,
help_text="Maximum d'interface pour un user sans droits")
max_lambdauser_aliases = models.IntegerField(
default=10,
help_text="Maximum de cname pour un user sans droits")
ipv6_mode = models.CharField( ipv6_mode = models.CharField(
max_length=32, max_length=32,
choices=CHOICE_IPV6, choices=CHOICE_IPV6,
default='DISABLED' default='DISABLED',
help_text="Mode ipv6"
) )
create_machine = models.BooleanField( create_machine = models.BooleanField(
default=True, default=True,
@ -206,21 +225,24 @@ class OptionalTopologie(AclMixin, PreferencesModel):
radius_general_policy = models.CharField( radius_general_policy = models.CharField(
max_length=32, max_length=32,
choices=CHOICE_RADIUS, choices=CHOICE_RADIUS,
default='DEFINED' default='DEFINED',
help_text="Politique par defaut de placement de vlan avec radius"
) )
vlan_decision_ok = models.OneToOneField( vlan_decision_ok = models.OneToOneField(
'machines.Vlan', 'machines.Vlan',
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name='decision_ok', related_name='decision_ok',
blank=True, blank=True,
null=True null=True,
help_text="Placement sur ce vlan par default en cas d'accès OK"
) )
vlan_decision_nok = models.OneToOneField( vlan_decision_nok = models.OneToOneField(
'machines.Vlan', 'machines.Vlan',
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name='decision_nok', related_name='decision_nok',
blank=True, blank=True,
null=True null=True,
help_text="Placement par defaut sur ce vlan en cas de rejet"
) )
class Meta: class Meta:
@ -236,6 +258,32 @@ def optionaltopologie_post_save(**kwargs):
topologie_pref.set_in_cache() topologie_pref.set_in_cache()
class Reminder(AclMixin, models.Model):
"""Options pour les mails de notification de fin d'adhésion.
Days: liste des nombres de jours pour lesquells un mail est envoyé
optionalMessage: message additionel pour le mail
"""
PRETTY_NAME="Options pour le mail de fin d'adhésion"
days = models.IntegerField(
default=7,
unique=True,
help_text="Délais entre le mail et la fin d'adhésion"
)
message = models.CharField(
max_length=255,
default="",
null=True,
blank=True,
help_text="Message affiché spécifiquement pour ce rappel"
)
class Meta:
permissions = (
("view_reminder", "Peut voir un objet reminder"),
)
class GeneralOption(AclMixin, PreferencesModel): class GeneralOption(AclMixin, PreferencesModel):
"""Options générales : nombre de resultats par page, nom du site, """Options générales : nombre de resultats par page, nom du site,
temps les liens sont valides""" temps les liens sont valides"""
@ -244,23 +292,44 @@ class GeneralOption(AclMixin, PreferencesModel):
general_message = models.TextField( general_message = models.TextField(
default="", default="",
blank=True, blank=True,
help_text="Message général affiché sur le site (maintenance, etc" help_text="Message général affiché sur le site (maintenance, etc)"
)
search_display_page = models.IntegerField(
default=15,
help_text="Nombre de résultats affichés dans une recherche"
)
pagination_number = models.IntegerField(
default=25,
help_text="Nombre d'item par page paginée"
)
pagination_large_number = models.IntegerField(
default=8,
help_text="Nombre d'item par page paginée, items larges"
)
req_expire_hrs = models.IntegerField(
default=48,
help_text="Delais d'expiration des token changement de mdp, en heure"
)
site_name = models.CharField(
max_length=32,
default="Re2o",
help_text="Nom du site web, par defaut re2o"
)
email_from = models.EmailField(
default="www-data@example.com",
help_text="From des mails envoyés par re2o"
) )
search_display_page = models.IntegerField(default=15)
pagination_number = models.IntegerField(default=25)
pagination_large_number = models.IntegerField(default=8)
req_expire_hrs = models.IntegerField(default=48)
site_name = models.CharField(max_length=32, default="Re2o")
email_from = models.EmailField(default="www-data@example.com")
GTU_sum_up = models.TextField( GTU_sum_up = models.TextField(
default="", default="",
blank=True, blank=True,
help_text="Résumé des CGU à l'inscription"
) )
GTU = models.FileField( GTU = models.FileField(
upload_to='', upload_to='',
default="", default="",
null=True, null=True,
blank=True, blank=True,
help_text="CGU et documents réglementaires à l'inscription"
) )
class Meta: class Meta:
@ -326,19 +395,43 @@ class AssoOption(AclMixin, PreferencesModel):
name = models.CharField( name = models.CharField(
default="Association réseau école machin", default="Association réseau école machin",
max_length=256 max_length=256,
help_text="Nom complet de l'asso"
)
siret = models.CharField(
default="00000000000000",
max_length=32,
help_text="Numero SIRET"
)
adresse1 = models.CharField(
default="1 Rue de exemple",
max_length=128,
help_text="Adresse"
)
adresse2 = models.CharField(
default="94230 Cachan",
max_length=128
)
contact = models.EmailField(
default="contact@example.org",
help_text="Mail de contact"
)
telephone = models.CharField(
max_length=15,
default="0000000000",
help_text="Téléphone de contact"
)
pseudo = models.CharField(
default="Asso",
max_length=32,
help_text="Pseudo de l'asso"
) )
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)
utilisateur_asso = models.OneToOneField( utilisateur_asso = models.OneToOneField(
'users.User', 'users.User',
on_delete=models.PROTECT, on_delete=models.PROTECT,
blank=True, blank=True,
null=True null=True,
help_text="Utilisateur dans la db correspondant à l'asso"
) )
PAYMENT = ( PAYMENT = (
('NONE', 'NONE'), ('NONE', 'NONE'),
@ -348,20 +441,24 @@ class AssoOption(AclMixin, PreferencesModel):
max_length=255, max_length=255,
choices=PAYMENT, choices=PAYMENT,
default='NONE', default='NONE',
help_text="Mode de paiement en ligne"
) )
payment_id = models.CharField( payment_id = models.CharField(
max_length=255, max_length=255,
default='', default='',
blank=True blank=True,
help_text="Id de paiement en ligne"
) )
payment_pass = AESEncryptedField( payment_pass = AESEncryptedField(
max_length=255, max_length=255,
null=True, null=True,
blank=True, blank=True,
help_text="Clef de paiement en ligne"
) )
description = models.TextField( description = models.TextField(
null=True, null=True,
blank=True, blank=True,
help_text="Description de l'asso"
) )
class Meta: class Meta:

View file

@ -0,0 +1,47 @@
{% comment %}
Re2o est 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.
{% endcomment %}
{% load acl %}
<table class="table table-striped">
<thead>
<tr>
<th>Nombre de jours avant le rappel</th>
<th>Message custom pour ce rappel</th>
<th></th>
<th></th>
</tr>
</thead>
{% for reminder in reminder_list %}
<tr>
<td>{{ reminder.days }}</td>
<td>{{ reminder.message }}</td>
<td class="text-right">
{% can_edit reminder %}
{% include 'buttons/edit.html' with href='preferences:edit-reminder' id=reminder.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='preferences:history' name='reminder' id=reminder.id %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -85,6 +85,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Nombre d'alias maximum</th> <th>Nombre d'alias maximum</th>
<td>{{ useroption.max_mail_alias }}<td> <td>{{ useroption.max_mail_alias }}<td>
</tr> </tr>
{% endfor %}
</table> </table>
<h4>Préférences machines</h4> <h4>Préférences machines</h4>
@ -95,22 +96,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<p> <p>
</p> </p>
<table class="table table-striped"> <table class="table table-striped">
{% for line in machineoptions %}
<tr> <tr>
<th>Mot de passe par machine</th> {% for text, field in line %}
<td>{{ machineoptions.password_machine }}</td> <th>{{ field }}</th>
<th>Machines/interfaces autorisées par utilisateurs</th> <td>{{ text }}</td>
<td>{{ machineoptions.max_lambdauser_interfaces }}</td> {% endfor %}
</tr>
<tr>
<th>Alias dns autorisé par utilisateur</th>
<td>{{ machineoptions.max_lambdauser_aliases }}</td>
<th>Support de l'ipv6</th>
<td>{{ machineoptions.ipv6_mode }}</td>
</tr>
<tr>
<th>Creation de machines</th>
<td>{{ machineoptions.create_machine }}</td>
</tr> </tr>
{% endfor %}
</table> </table>
<h4>Préférences topologie</h4> <h4>Préférences topologie</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalTopologie' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalTopologie' %}">
@ -120,19 +113,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<p> <p>
</p> </p>
<table class="table table-striped"> <table class="table table-striped">
{% for line in topologieoptions %}
<tr> <tr>
<th>Politique générale de placement de vlan</th> {% for text, field in line %}
<td>{{ topologieoptions.radius_general_policy }}</td> <th>{{ field }}</th>
<th> Ce réglage défini la politique vlan après acceptation radius : soit sur le vlan de la plage d'ip de la machine, soit sur un vlan prédéfini dans "Vlan où placer les machines après acceptation RADIUS"</th> <td>{{ text }}</td>
<td></td> {% endfor %}
</tr>
<tr>
<th>Vlan où placer les machines après acceptation RADIUS</th>
<td>{{ topologieoptions.vlan_decision_ok }}</td>
<th>Vlan où placer les machines après rejet RADIUS</th>
<td>{{ topologieoptions.vlan_decision_nok }}</td>
</tr> </tr>
{% endfor %}
</table> </table>
<h4>Préférences generales</h4> <h4>Préférences generales</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'GeneralOption' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'GeneralOption' %}">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
@ -141,35 +131,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<p> <p>
</p> </p>
<table class="table table-striped"> <table class="table table-striped">
{% for line in generaloptions %}
<tr> <tr>
<th>Nom du site web</th> {% for text, field in line %}
<td>{{ generaloptions.site_name }}</td> <th>{{ field }}</th>
<th>Adresse mail d'expedition automatique</th> <td>{{ text }}</td>
<td>{{ generaloptions.email_from }}</td> {% endfor %}
</tr>
<tr>
<th>Affichage de résultats dans le champ de recherche</th>
<td>{{ generaloptions.search_display_page }}</td>
<th>Nombre d'items affichés en liste (taille normale)</th>
<td>{{ generaloptions.pagination_number }}</td>
</tr>
<tr>
<th>Nombre d'items affichés en liste (taille élevée)</th>
<td>{{ generaloptions.pagination_large_number }}</td>
<th>Temps avant expiration du lien de reinitialisation de mot de passe (en heures)</th>
<td>{{ generaloptions.req_expire_hrs }}</td>
</tr>
<tr>
<th>Message global affiché sur le site</th>
<td>{{ generaloptions.general_message }}</td>
<th>Résumé des CGU</th>
<td>{{ generaloptions.GTU_sum_up }}</td>
<tr>
<tr>
<th>CGU</th>
<td>{{generaloptions.GTU}}</th>
</tr> </tr>
{% endfor %}
</table> </table>
<h4>Données de l'association</h4> <h4>Données de l'association</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'AssoOption' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'AssoOption' %}">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
@ -178,37 +149,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<p> <p>
</p> </p>
<table class="table table-striped"> <table class="table table-striped">
{% for line in assooptions %}
<tr> <tr>
<th>Nom</th> {% for text, field in line %}
<td>{{ assooptions.name }}</td> <th>{{ field }}</th>
<th>SIRET</th> <td>{{ text }}</td>
<td>{{ assooptions.siret }}</td> {% endfor %}
</tr> </tr>
<tr> {% endfor %}
<th>Adresse</th>
<td>{{ assooptions.adresse1 }}<br>
{{ assooptions.adresse2 }}</td>
<th>Contact mail</th>
<td>{{ assooptions.contact }}</td>
</tr>
<tr>
<th>Telephone</th>
<td>{{ assooptions.telephone }}</td>
<th>Pseudo d'usage</th>
<td>{{ assooptions.pseudo }}</td>
</tr>
<tr>
<th>Objet utilisateur de l'association</th>
<td>{{ assooptions.utilisateur_asso }}</td>
<th>Moyen de paiement automatique</th>
<td>{{ assooptions.payment }}</td>
</tr>
<tr>
<th>Description de l'association</th>
<td colspan="3">{{ assooptions.description | safe }}</td>
</tr>
</table> </table>
<h4>Messages personalisé dans les mails</h4> <h4>Messages personalisé dans les mails</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'MailMessageOption' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'MailMessageOption' %}">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
@ -217,20 +167,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<p> <p>
</p> </p>
<table class="table table-striped"> <table class="table table-striped">
{% for line in assooptions %}
<tr> <tr>
<th>Mail de bienvenue (Français)</th> {% for text, field in line %}
<td>{{ mailmessageoptions.welcome_mail_fr | safe }}</td> <th>{{ field }}</th>
</tr> <td>{{ text }}</td>
<tr> {% endfor %}
<th>Mail de bienvenue (Anglais)</th>
<td>{{ mailmessageoptions.welcome_mail_en | safe }}</td>
</tr> </tr>
{% endfor %}
</table> </table>
<h2>Liste des services et préférences page d'accueil</h2> <h2>Liste des services et préférences page d'accueil</h2>
{% can_create preferences.Service%} {% can_create preferences.Service%}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:add-service' %}"><i class="fa fa-plus"></i> Ajouter un service</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:add-service' %}"><i class="fa fa-plus"></i> Ajouter un service</a>
{% acl_end %} {% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'preferences:del-service' %}"><i class="fa fa-trash"></i> Supprimer un ou plusieurs services</a>
{% include "preferences/aff_service.html" with service_list=service_list %} {% include "preferences/aff_service.html" with service_list=service_list %}
<h2>Liste des adresses mail de contact</h2> <h2>Liste des adresses mail de contact</h2>
@ -246,19 +196,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Editer Editer
</a> </a>
<p> <p>
<table class="table table-striped"> <table class="table table-striped">
{% for line in assooptions %}
<tr> <tr>
<th>Url du compte twitter</th> {% for text, field in line %}
<td>{{ homeoptions.twitter_url }}</td> <th>{{ field }}</th>
<th>Nom utilisé pour afficher le compte</th> <td>{{ text }}</td>
<td>{{ homeoptions.twitter_account_name }}</td> {% endfor %}
</tr>
<tr>
<th>Url du compte facebook</th>
<td>{{ homeoptions.facebook_url }}</td>
</tr> </tr>
{% endfor %}
</table> </table>
<h2>Options pour le mail de fin d'adhésion</h2>
{% can_create preferences.Reminder%}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:add-reminder' %}"><i class="fa fa-plus"></i> Ajouter un rappel</a>
{% acl_end %}
{% include "preferences/aff_reminder.html" with reminder_list=reminder_list %}
<br /> <br />
<br /> <br />
<br /> <br />

View file

@ -81,6 +81,13 @@ urlpatterns = [
name='edit-mailcontact' name='edit-mailcontact'
), ),
url(r'^del_mailcontact/$', views.del_mailcontact, name='del-mailcontact'), url(r'^del_mailcontact/$', views.del_mailcontact, name='del-mailcontact'),
url(r'^add_reminder/$', views.add_reminder, name='add-reminder'),
url(
r'^edit_reminder/(?P<reminderid>[0-9]+)$',
views.edit_reminder,
name='edit-reminder'
),
url(r'^del_reminder/$', views.del_reminder, name='del-reminder'),
url( url(
r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$', r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
re2o.views.history, re2o.views.history,

View file

@ -40,9 +40,10 @@ from django.db import transaction
from reversion import revisions as reversion from reversion import revisions as reversion
from re2o.views import form from re2o.views import form
from re2o.acl import can_create, can_edit, can_delete_set, can_view_all from re2o.acl import can_create, can_edit, can_delete, can_view_all
from .forms import ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm from .forms import MailContactForm, DelMailContactForm
from .forms import ServiceForm, ReminderForm
from .models import ( from .models import (
Service, Service,
MailContact, MailContact,
@ -52,12 +53,23 @@ from .models import (
MailMessageOption, MailMessageOption,
GeneralOption, GeneralOption,
OptionalTopologie, OptionalTopologie,
HomeOption HomeOption,
Reminder
) )
from . import models from . import models
from . import forms from . import forms
def format_options(model):
"""Return a list of tuple for display of settings"""
model_formated = []
for field in model._meta.get_fields()[1::2]:
model_formated.append([(getattr(model, field.name), model._meta.get_field(field.name).help_text)])
for rank, field in enumerate(model._meta.get_fields()[2::2]):
model_formated[rank].append((getattr(model, field.name), model._meta.get_field(field.name).help_text))
return model_formated
@login_required @login_required
@can_view_all(OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, @can_view_all(OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption,
AssoOption, MailMessageOption, HomeOption) AssoOption, MailMessageOption, HomeOption)
@ -73,15 +85,17 @@ def display_options(request):
mailmessageoptions, _created = MailMessageOption.objects.get_or_create() mailmessageoptions, _created = MailMessageOption.objects.get_or_create()
service_list = Service.objects.all() service_list = Service.objects.all()
mailcontact_list = MailContact.objects.all() mailcontact_list = MailContact.objects.all()
reminder_list = Reminder.objects.all()
return form({ return form({
'useroptions': useroptions, 'useroptions': format_options(useroptions),
'machineoptions': machineoptions, 'machineoptions': format_options(machineoptions),
'topologieoptions': topologieoptions, 'topologieoptions': format_options(topologieoptions),
'generaloptions': generaloptions, 'generaloptions': format_options(generaloptions),
'assooptions': assooptions, 'assooptions': format_options(assooptions),
'homeoptions': homeoptions, 'homeoptions': format_options(homeoptions),
'mailmessageoptions': mailmessageoptions, 'mailmessageoptions': format_options(mailmessageoptions),
'service_list': service_list, 'service_list': service_list,
'reminder_list':reminder_list,
'mailcontact_list': mailcontact_list 'mailcontact_list': mailcontact_list
}, 'preferences/display_preferences.html', request) }, 'preferences/display_preferences.html', request)
@ -130,10 +144,7 @@ def add_service(request):
"""Ajout d'un service de la page d'accueil""" """Ajout d'un service de la page d'accueil"""
service = ServiceForm(request.POST or None, request.FILES or None) service = ServiceForm(request.POST or None, request.FILES or None)
if service.is_valid(): if service.is_valid():
with transaction.atomic(), reversion.create_revision():
service.save() service.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Ce service a été ajouté") messages.success(request, "Ce service a été ajouté")
return redirect(reverse('preferences:display-options')) return redirect(reverse('preferences:display-options'))
return form( return form(
@ -153,14 +164,7 @@ def edit_service(request, service_instance, **_kwargs):
instance=service_instance instance=service_instance
) )
if service.is_valid(): if service.is_valid():
with transaction.atomic(), reversion.create_revision():
service.save() service.save()
reversion.set_user(request.user)
reversion.set_comment(
"Champs modifié(s) : %s" % ', '.join(
field for field in service.changed_data
)
)
messages.success(request, "Service modifié") messages.success(request, "Service modifié")
return redirect(reverse('preferences:display-options')) return redirect(reverse('preferences:display-options'))
return form( return form(
@ -169,30 +173,64 @@ def edit_service(request, service_instance, **_kwargs):
request request
) )
@login_required @login_required
@can_delete_set(Service) @can_delete(Service)
def del_service(request, instances): def del_service(request, service_instance, **_kwargs):
"""Suppression d'un service de la page d'accueil""" """Destruction d'un service"""
services = DelServiceForm(request.POST or None, instances=instances) if request.method == "POST":
if services.is_valid(): service_instance.delete()
services_dels = services.cleaned_data['services'] messages.success(request, "Le service a été détruit")
for services_del in services_dels:
try:
with transaction.atomic(), reversion.create_revision():
services_del.delete()
reversion.set_user(request.user)
messages.success(request, "Le service a été supprimé")
except ProtectedError:
messages.error(request, "Erreur le service\
suivant %s ne peut être supprimé" % services_del)
return redirect(reverse('preferences:display-options')) return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': services, 'action_name': 'Supprimer'}, {'objet': service_instance, 'objet_name': 'service'},
'preferences/delete.html',
request
)
@login_required
@can_create(Reminder)
def add_reminder(request):
"""Ajout d'un rappel"""
reminder = ReminderForm(request.POST or None)
if reminder.is_valid():
reminder.save()
messages.success(request, "Ce rappel a été ajouté")
return redirect(reverse('preferences:display-options'))
return form(
{'preferenceform': reminder, 'action_name': 'Ajouter'},
'preferences/preferences.html', 'preferences/preferences.html',
request request
) )
@can_edit(Reminder)
def edit_reminder(request, reminder_instance, **_kwargs):
"""Edition des rappels"""
reminder = ReminderForm(request.POST or None, instance=reminder_instance)
if reminder.is_valid():
reminder.save()
messages.success(request, "Service modifié")
return redirect(reverse('preferences:display-options'))
return form(
{'preferenceform': reminder, 'action_name': 'Editer'},
'preferences/preferences.html',
request
)
@login_required
@can_delete(Reminder)
def del_reminder(request, reminder_instance, **_kwargs):
"""Destruction d'un reminder"""
if request.method == "POST":
reminder_instance.delete()
messages.success(request, "Le reminder a été détruit")
return redirect(reverse('preferences:display-options'))
return form(
{'objet': reminder_instance, 'objet_name': 'reminder'},
'preferences/delete.html',
request
)
@login_required @login_required
@can_create(MailContact) @can_create(MailContact)
@ -264,3 +302,4 @@ def del_mailcontact(request, instances):
'preferences/preferences.html', 'preferences/preferences.html',
request request
) )

View file

@ -122,6 +122,7 @@ MODEL_NAME = {
'GeneralOption': preferences.models.GeneralOption, 'GeneralOption': preferences.models.GeneralOption,
'preferences.Service': preferences.models.Service, 'preferences.Service': preferences.models.Service,
'preferences.MailContact': preferences.models.MailContact, 'preferences.MailContact': preferences.models.MailContact,
'preferences.Reminder': preferences.models.Reminder,
'AssoOption': preferences.models.AssoOption, 'AssoOption': preferences.models.AssoOption,
'MailMessageOption': preferences.models.MailMessageOption, 'MailMessageOption': preferences.models.MailMessageOption,
# topologie # topologie

View file

@ -97,6 +97,7 @@ HISTORY_BIND = {
'preferences': { 'preferences': {
'service': preferences.models.Service, 'service': preferences.models.Service,
'mailcontact': preferences.models.MailContact, 'mailcontact': preferences.models.MailContact,
'reminder': preferences.models.Reminder,
}, },
'cotisations': { 'cotisations': {
'facture': cotisations.models.Facture, 'facture': cotisations.models.Facture,