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

Création, modification, suppression d'adresses mail de contact

This commit is contained in:
grisel-davy 2018-06-30 19:19:40 +02:00 committed by Gabriel Detraz
parent 90674d4978
commit 38edf3b0eb
8 changed files with 206 additions and 7 deletions

View file

@ -34,6 +34,7 @@ from .models import (
OptionalTopologie, OptionalTopologie,
GeneralOption, GeneralOption,
Service, Service,
MailContact,
AssoOption, AssoOption,
MailMessageOption, MailMessageOption,
HomeOption HomeOption
@ -65,6 +66,11 @@ class ServiceAdmin(VersionAdmin):
pass pass
class MailContactAdmin(VersionAdmin):
"""Class admin gestion des adresses mail de contact"""
pass
class AssoOptionAdmin(VersionAdmin): class AssoOptionAdmin(VersionAdmin):
"""Class admin options de l'asso""" """Class admin options de l'asso"""
pass pass
@ -86,5 +92,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(MailContact, MailContactAdmin)
admin.site.register(AssoOption, AssoOptionAdmin) admin.site.register(AssoOption, AssoOptionAdmin)
admin.site.register(MailMessageOption, MailMessageOptionAdmin) admin.site.register(MailMessageOption, MailMessageOptionAdmin)

View file

@ -35,7 +35,8 @@ from .models import (
AssoOption, AssoOption,
MailMessageOption, MailMessageOption,
HomeOption, HomeOption,
Service Service,
MailContact
) )
@ -227,3 +228,30 @@ class DelServiceForm(Form):
self.fields['services'].queryset = instances self.fields['services'].queryset = instances
else: else:
self.fields['services'].queryset = Service.objects.all() 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()

View file

@ -267,6 +267,29 @@ class Service(AclMixin, models.Model):
def __str__(self): def __str__(self):
return str(self.name) 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): class AssoOption(AclMixin, PreferencesModel):
"""Options générales de l'asso : siret, addresse, nom, etc""" """Options générales de l'asso : siret, addresse, nom, etc"""

View 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>

View file

@ -220,6 +220,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'HomeOption' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'HomeOption' %}">
<i class="fa fa-edit"></i> Editer <i class="fa fa-edit"></i> Editer
</a> </a>
<h4>Liste des adresses mail de contact</h4>
{% 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 %}
<p>
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>Url du compte twitter</th> <th>Url du compte twitter</th>

View file

@ -72,6 +72,19 @@ 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_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,
name='history',
kwargs={'application': 'preferences'},
),
url(r'^$', views.display_options, name='display-options'), url(r'^$', views.display_options, name='display-options'),
] ]

View file

@ -42,9 +42,10 @@ 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_set, can_view_all
from .forms import ServiceForm, DelServiceForm from .forms import ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm
from .models import ( from .models import (
Service, Service,
MailContact,
OptionalUser, OptionalUser,
OptionalMachine, OptionalMachine,
AssoOption, AssoOption,
@ -71,6 +72,7 @@ def display_options(request):
homeoptions, _created = HomeOption.objects.get_or_create() homeoptions, _created = HomeOption.objects.get_or_create()
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()
return form({ return form({
'useroptions': useroptions, 'useroptions': useroptions,
'machineoptions': machineoptions, 'machineoptions': machineoptions,
@ -79,7 +81,8 @@ def display_options(request):
'assooptions': assooptions, 'assooptions': assooptions,
'homeoptions': homeoptions, 'homeoptions': homeoptions,
'mailmessageoptions': mailmessageoptions, 'mailmessageoptions': mailmessageoptions,
'service_list': service_list 'service_list': service_list,
'mailcontact_list': mailcontact_list
}, 'preferences/display_preferences.html', request) }, 'preferences/display_preferences.html', request)
@ -169,7 +172,7 @@ def edit_service(request, service_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Service) @can_delete_set(Service)
def del_services(request, instances): def del_service(request, instances):
"""Suppression d'un service de la page d'accueil""" """Suppression d'un service de la page d'accueil"""
services = DelServiceForm(request.POST or None, instances=instances) services = DelServiceForm(request.POST or None, instances=instances)
if services.is_valid(): if services.is_valid():
@ -179,7 +182,7 @@ def del_services(request, instances):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
services_del.delete() services_del.delete()
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "Le service a été supprimée") messages.success(request, "Le service a été supprimé")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le service\ messages.error(request, "Erreur le service\
suivant %s ne peut être supprimé" % services_del) suivant %s ne peut être supprimé" % services_del)
@ -189,3 +192,75 @@ def del_services(request, instances):
'preferences/preferences.html', 'preferences/preferences.html',
request 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
)

View file

@ -79,7 +79,6 @@ from django.contrib.contenttypes.models import ContentType
register = template.Library() register = template.Library()
def get_model(model_name): def get_model(model_name):
"""Retrieve the model object from its name""" """Retrieve the model object from its name"""
splitted = model_name.split('.') splitted = model_name.split('.')