mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 00:22:25 +00:00
Création, modification, suppression d'adresses mail de contact
This commit is contained in:
parent
299453b5bb
commit
97eb065337
8 changed files with 201 additions and 7 deletions
|
@ -34,6 +34,7 @@ from .models import (
|
|||
OptionalTopologie,
|
||||
GeneralOption,
|
||||
Service,
|
||||
MailContact,
|
||||
AssoOption,
|
||||
MailMessageOption,
|
||||
HomeOption
|
||||
|
@ -65,6 +66,11 @@ class ServiceAdmin(VersionAdmin):
|
|||
pass
|
||||
|
||||
|
||||
class MailContactAdmin(VersionAdmin):
|
||||
"""Class admin gestion des adresses mail de contact"""
|
||||
pass
|
||||
|
||||
|
||||
class AssoOptionAdmin(VersionAdmin):
|
||||
"""Class admin options de l'asso"""
|
||||
pass
|
||||
|
@ -86,5 +92,6 @@ admin.site.register(OptionalTopologie, OptionalTopologieAdmin)
|
|||
admin.site.register(GeneralOption, GeneralOptionAdmin)
|
||||
admin.site.register(HomeOption, HomeOptionAdmin)
|
||||
admin.site.register(Service, ServiceAdmin)
|
||||
admin.site.register(MailContact, MailContactAdmin)
|
||||
admin.site.register(AssoOption, AssoOptionAdmin)
|
||||
admin.site.register(MailMessageOption, MailMessageOptionAdmin)
|
||||
|
|
|
@ -35,7 +35,8 @@ from .models import (
|
|||
AssoOption,
|
||||
MailMessageOption,
|
||||
HomeOption,
|
||||
Service
|
||||
Service,
|
||||
MailContact
|
||||
)
|
||||
|
||||
class EditOptionalUserForm(ModelForm):
|
||||
|
@ -233,3 +234,30 @@ class DelServiceForm(Form):
|
|||
self.fields['services'].queryset = instances
|
||||
else:
|
||||
self.fields['services'].queryset = Service.objects.all()
|
||||
|
||||
class MailContactForm(ModelForm):
|
||||
"""Edition, ajout d'adresse de contact"""
|
||||
class Meta:
|
||||
model = MailContact
|
||||
fields = '__all__'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
super(MailContactForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
|
||||
|
||||
class DelMailContactForm(Form):
|
||||
"""Suppression d'adresse de contact"""
|
||||
mailcontacts = forms.ModelMultipleChoiceField(
|
||||
queryset=MailContact.objects.none(),
|
||||
label="Enregistrements adresses actuels",
|
||||
widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instances = kwargs.pop('instances', None)
|
||||
super(DelMailContactForm, self).__init__(*args, **kwargs)
|
||||
if instances:
|
||||
self.fields['mailcontacts'].queryset = instances
|
||||
else:
|
||||
self.fields['mailcontacts'].queryset = MailContact.objects.all()
|
||||
|
|
|
@ -292,6 +292,29 @@ class Service(AclMixin, models.Model):
|
|||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
class MailContact(AclMixin, models.Model):
|
||||
"""Addresse mail de contact associée à un commentaire descriptif"""
|
||||
|
||||
address = models.EmailField(
|
||||
default = "contact@example.org",
|
||||
help_text = "Adresse mail de contact"
|
||||
)
|
||||
|
||||
commentary = models.CharField(
|
||||
blank = True,
|
||||
null = True,
|
||||
help_text = "Description de l'utilisation de l'adresse mail associée",
|
||||
max_length = 256
|
||||
)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
("view_mailcontact", "Peut voir les mails de contact"),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return(self.address)
|
||||
|
||||
|
||||
class AssoOption(AclMixin, PreferencesModel):
|
||||
"""Options générales de l'asso : siret, addresse, nom, etc"""
|
||||
|
|
45
preferences/templates/preferences/aff_mailcontact.html
Normal file
45
preferences/templates/preferences/aff_mailcontact.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
{% 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>Adresse</th>
|
||||
<th>Commentaire</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for mailcontact in mailcontact_list %}
|
||||
<tr>
|
||||
<td>{{ mailcontact.address }}</td>
|
||||
<td>{{ mailcontact.commentary }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit mailcontact %}
|
||||
{% include 'buttons/edit.html' with href='preferences:edit-mailcontact' id=mailcontact.id %}
|
||||
{% acl_end %}
|
||||
{% include 'buttons/history.html' with href='preferences:history' name='mailcontact' id=mailcontact.id %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
|
@ -230,9 +230,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% 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>
|
||||
{% acl_end %}
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'preferences:del-services' %}"><i class="fa fa-trash"></i> Supprimer un ou plusieurs service</a>
|
||||
<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 %}
|
||||
|
||||
<h2>Liste des adresses mail de contact</h2>
|
||||
{% can_create preferences.MailContact%}
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:add-mailcontact' %}"><i class="fa fa-plus"></i>Ajouter une adresse</a>
|
||||
{% acl_end %}
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'preferences:del-mailcontact' %}"><i class="fa fa-trash"></i>Supprimer une ou plusieurs adresses</a>
|
||||
{% include "preferences/aff_mailcontact.html" with mailcontact_list=mailcontact_list %}
|
||||
|
||||
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'HomeOption' %}">
|
||||
<i class="fa fa-edit"></i>
|
||||
Editer
|
||||
|
|
|
@ -73,7 +73,14 @@ urlpatterns = [
|
|||
views.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_mailcontact/$', views.add_mailcontact, name='add-mailcontact'),
|
||||
url(
|
||||
r'^edit_mailcontact/(?P<mailcontactid>[0-9]+)$',
|
||||
views.edit_mailcontact,
|
||||
name='edit-mailcontact'
|
||||
),
|
||||
url(r'^del_mailcontact/$', views.del_mailcontact, name='del-mailcontact'),
|
||||
url(
|
||||
r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
|
||||
re2o.views.history,
|
||||
|
|
|
@ -42,9 +42,10 @@ from reversion import revisions as reversion
|
|||
from re2o.views import form
|
||||
from re2o.acl import can_create, can_edit, can_delete_set, can_view_all
|
||||
|
||||
from .forms import ServiceForm, DelServiceForm
|
||||
from .forms import ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm
|
||||
from .models import (
|
||||
Service,
|
||||
MailContact,
|
||||
OptionalUser,
|
||||
OptionalMachine,
|
||||
AssoOption,
|
||||
|
@ -71,6 +72,7 @@ def display_options(request):
|
|||
homeoptions, _created = HomeOption.objects.get_or_create()
|
||||
mailmessageoptions, _created = MailMessageOption.objects.get_or_create()
|
||||
service_list = Service.objects.all()
|
||||
mailcontact_list = MailContact.objects.all()
|
||||
return form({
|
||||
'useroptions': useroptions,
|
||||
'machineoptions': machineoptions,
|
||||
|
@ -79,7 +81,8 @@ def display_options(request):
|
|||
'assooptions': assooptions,
|
||||
'homeoptions': homeoptions,
|
||||
'mailmessageoptions': mailmessageoptions,
|
||||
'service_list': service_list
|
||||
'service_list': service_list,
|
||||
'mailcontact_list': mailcontact_list
|
||||
}, 'preferences/display_preferences.html', request)
|
||||
|
||||
|
||||
|
@ -169,7 +172,7 @@ def edit_service(request, service_instance, **_kwargs):
|
|||
|
||||
@login_required
|
||||
@can_delete_set(Service)
|
||||
def del_services(request, instances):
|
||||
def del_service(request, instances):
|
||||
"""Suppression d'un service de la page d'accueil"""
|
||||
services = DelServiceForm(request.POST or None, instances=instances)
|
||||
if services.is_valid():
|
||||
|
@ -179,7 +182,7 @@ def del_services(request, instances):
|
|||
with transaction.atomic(), reversion.create_revision():
|
||||
services_del.delete()
|
||||
reversion.set_user(request.user)
|
||||
messages.success(request, "Le service a été supprimée")
|
||||
messages.success(request, "Le service a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(request, "Erreur le service\
|
||||
suivant %s ne peut être supprimé" % services_del)
|
||||
|
@ -189,3 +192,75 @@ def del_services(request, instances):
|
|||
'preferences/preferences.html',
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(MailContact)
|
||||
def add_mailcontact(request):
|
||||
"""Ajout d'une adresse de contact"""
|
||||
mailcontact = MailContactForm(
|
||||
request.POST or None,
|
||||
request.FILES or None
|
||||
)
|
||||
if mailcontact.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
mailcontact.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
messages.success(request, "Cette adresse a été ajoutée")
|
||||
return redirect(reverse('preferences:display-options'))
|
||||
return form(
|
||||
{'preferenceform': mailcontact, 'action_name': 'Ajouter'},
|
||||
'preferences/preferences.html',
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_edit(MailContact)
|
||||
def edit_mailcontact(request, mailcontact_instance, **_kwargs):
|
||||
"""Edition des adresses de contacte affichées"""
|
||||
mailcontact = MailContactForm(
|
||||
request.POST or None,
|
||||
request.FILES or None,
|
||||
instance=mailcontact_instance
|
||||
)
|
||||
if mailcontact.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
mailcontact.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Modification")
|
||||
messages.success(request, "Adresse modifiée")
|
||||
return redirect(reverse('preferences:display-options'))
|
||||
return form(
|
||||
{'preferenceform': mailcontact, 'action_name': 'Editer'},
|
||||
'preferences/preferences.html',
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_delete_set(MailContact)
|
||||
def del_mailcontact(request, instances):
|
||||
"""Suppression d'une adresse de contact"""
|
||||
mailcontacts = DelMailContactForm(
|
||||
request.POST or None,
|
||||
instances=instances
|
||||
)
|
||||
if mailcontacts.is_valid():
|
||||
mailcontacts_dels = mailcontacts.cleaned_data['mailcontacts']
|
||||
for mailcontacts_del in mailcontacts_dels:
|
||||
try:
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
mailcontacts_del.delete()
|
||||
reversion.set_user(request.user)
|
||||
messages.success(request, "L'adresse a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(request, "Erreur le service\
|
||||
suivant %s ne peut être supprimé" % mailcontacts_del)
|
||||
return redirect(reverse('preferences:display-options'))
|
||||
return form(
|
||||
{'preferenceform': mailcontacts, 'action_name': 'Supprimer'},
|
||||
'preferences/preferences.html',
|
||||
request
|
||||
)
|
||||
|
|
|
@ -121,6 +121,7 @@ MODEL_NAME = {
|
|||
'OptionalTopologie': preferences.models.OptionalTopologie,
|
||||
'GeneralOption': preferences.models.GeneralOption,
|
||||
'preferences.Service': preferences.models.Service,
|
||||
'preferences.MailContact': preferences.models.MailContact,
|
||||
'AssoOption': preferences.models.AssoOption,
|
||||
'MailMessageOption': preferences.models.MailMessageOption,
|
||||
# topologie
|
||||
|
|
Loading…
Reference in a new issue