mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Ajoute le réglage reminder et factorise la liste des services
This commit is contained in:
parent
60b2a6cd9d
commit
5a8888231d
10 changed files with 201 additions and 71 deletions
|
@ -34,6 +34,7 @@ from .models import (
|
||||||
OptionalTopologie,
|
OptionalTopologie,
|
||||||
GeneralOption,
|
GeneralOption,
|
||||||
Service,
|
Service,
|
||||||
|
Reminder,
|
||||||
AssoOption,
|
AssoOption,
|
||||||
MailMessageOption,
|
MailMessageOption,
|
||||||
HomeOption
|
HomeOption
|
||||||
|
@ -79,6 +80,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)
|
||||||
|
@ -86,5 +90,6 @@ admin.site.register(OptionalTopologie, OptionalTopologieAdmin)
|
||||||
admin.site.register(GeneralOption, GeneralOptionAdmin)
|
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(Reminder, ReminderAdmin)
|
||||||
admin.site.register(AssoOption, AssoOptionAdmin)
|
admin.site.register(AssoOption, AssoOptionAdmin)
|
||||||
admin.site.register(MailMessageOption, MailMessageOptionAdmin)
|
admin.site.register(MailMessageOption, MailMessageOptionAdmin)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -35,7 +36,8 @@ from .models import (
|
||||||
AssoOption,
|
AssoOption,
|
||||||
MailMessageOption,
|
MailMessageOption,
|
||||||
HomeOption,
|
HomeOption,
|
||||||
Service
|
Service,
|
||||||
|
Reminder
|
||||||
)
|
)
|
||||||
|
|
||||||
class EditOptionalUserForm(ModelForm):
|
class EditOptionalUserForm(ModelForm):
|
||||||
|
@ -51,18 +53,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)"""
|
||||||
|
@ -207,7 +197,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
|
||||||
|
@ -217,19 +207,13 @@ 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()
|
|
||||||
|
|
28
preferences/migrations/0035_reminder.py
Normal file
28
preferences/migrations/0035_reminder.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -239,6 +239,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 où les liens sont valides"""
|
temps où les liens sont valides"""
|
||||||
|
|
47
preferences/templates/preferences/aff_reminder.html
Normal file
47
preferences/templates/preferences/aff_reminder.html
Normal 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>
|
||||||
|
|
|
@ -146,19 +146,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">
|
||||||
<tr>
|
{% for line in assooptions %}
|
||||||
<th>Url du compte twitter</th>
|
<tr>
|
||||||
<td>{{ homeoptions.twitter_url }}</td>
|
{% for text, field in line %}
|
||||||
<th>Nom utilisé pour afficher le compte</th>
|
<th>{{ field }}</th>
|
||||||
<td>{{ homeoptions.twitter_account_name }}</td>
|
<td>{{ text }}</td>
|
||||||
</tr>
|
{% endfor %}
|
||||||
<tr>
|
</tr>
|
||||||
<th>Url du compte facebook</th>
|
{% endfor %}
|
||||||
<td>{{ homeoptions.facebook_url }}</td>
|
|
||||||
</tr>
|
|
||||||
</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 />
|
||||||
|
|
|
@ -73,7 +73,14 @@ urlpatterns = [
|
||||||
views.edit_service,
|
views.edit_service,
|
||||||
name='edit-service'
|
name='edit-service'
|
||||||
),
|
),
|
||||||
url(r'^del_services/$', views.del_services, name='del-services'),
|
url(r'^del_service/$', views.del_service, name='del-service'),
|
||||||
|
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,
|
||||||
|
|
|
@ -40,9 +40,9 @@ 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
|
from .forms import ServiceForm, ReminderForm
|
||||||
from .models import (
|
from .models import (
|
||||||
Service,
|
Service,
|
||||||
OptionalUser,
|
OptionalUser,
|
||||||
|
@ -145,10 +145,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(
|
||||||
|
@ -164,14 +161,7 @@ def edit_service(request, service_instance, **_kwargs):
|
||||||
"""Edition des services affichés sur la page d'accueil"""
|
"""Edition des services affichés sur la page d'accueil"""
|
||||||
service = ServiceForm(request.POST or None, request.FILES or None,instance=service_instance)
|
service = ServiceForm(request.POST or None, request.FILES or None,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(
|
||||||
|
@ -180,26 +170,62 @@ def edit_service(request, service_instance, **_kwargs):
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete_set(Service)
|
@can_delete(Service)
|
||||||
def del_services(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ée")
|
|
||||||
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',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@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',
|
'preferences/preferences.html',
|
||||||
request
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@ MODEL_NAME = {
|
||||||
'OptionalTopologie': preferences.models.OptionalTopologie,
|
'OptionalTopologie': preferences.models.OptionalTopologie,
|
||||||
'GeneralOption': preferences.models.GeneralOption,
|
'GeneralOption': preferences.models.GeneralOption,
|
||||||
'preferences.Service': preferences.models.Service,
|
'preferences.Service': preferences.models.Service,
|
||||||
|
'preferences.Reminder': preferences.models.Reminder,
|
||||||
'AssoOption': preferences.models.AssoOption,
|
'AssoOption': preferences.models.AssoOption,
|
||||||
'MailMessageOption': preferences.models.MailMessageOption,
|
'MailMessageOption': preferences.models.MailMessageOption,
|
||||||
# topologie
|
# topologie
|
||||||
|
|
|
@ -94,6 +94,7 @@ HISTORY_BIND = {
|
||||||
},
|
},
|
||||||
'preferences': {
|
'preferences': {
|
||||||
'service': preferences.models.Service,
|
'service': preferences.models.Service,
|
||||||
|
'reminder': preferences.models.Reminder,
|
||||||
},
|
},
|
||||||
'cotisations': {
|
'cotisations': {
|
||||||
'facture': cotisations.models.Facture,
|
'facture': cotisations.models.Facture,
|
||||||
|
|
Loading…
Reference in a new issue