2017-06-25 22:50:55 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
# App de gestion des machines pour re2o
|
|
|
|
# Gabriel Détraz, Augustin Lemesle
|
|
|
|
# Gplv2
|
2017-10-14 04:03:53 +00:00
|
|
|
"""
|
|
|
|
Vue d'affichage, et de modification des réglages (réglages machine,
|
|
|
|
topologie, users, service...)
|
|
|
|
"""
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-10-26 15:58:41 +00:00
|
|
|
from django.urls import reverse
|
2018-04-14 18:55:24 +00:00
|
|
|
from django.shortcuts import redirect
|
2017-06-25 22:50:55 +00:00
|
|
|
from django.contrib import messages
|
2018-04-14 18:55:24 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2017-10-14 04:03:53 +00:00
|
|
|
from django.db.models import ProtectedError
|
2017-06-25 22:50:55 +00:00
|
|
|
from django.db import transaction
|
2018-07-26 19:53:32 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
from reversion import revisions as reversion
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
from re2o.views import form
|
2018-09-19 21:24:03 +00:00
|
|
|
from re2o.acl import can_create, can_edit, can_delete_set, can_view_all, can_delete
|
2018-04-14 18:55:24 +00:00
|
|
|
|
2018-07-10 23:07:31 +00:00
|
|
|
from .forms import MailContactForm, DelMailContactForm
|
|
|
|
from .forms import (
|
|
|
|
ServiceForm,
|
|
|
|
ReminderForm,
|
2018-07-11 00:19:29 +00:00
|
|
|
RadiusKeyForm,
|
|
|
|
SwitchManagementCredForm
|
2018-07-26 19:53:32 +00:00
|
|
|
)
|
2018-04-16 03:28:27 +00:00
|
|
|
from .models import (
|
|
|
|
Service,
|
2018-06-30 17:19:40 +00:00
|
|
|
MailContact,
|
2018-04-16 03:28:27 +00:00
|
|
|
OptionalUser,
|
|
|
|
OptionalMachine,
|
|
|
|
AssoOption,
|
|
|
|
MailMessageOption,
|
|
|
|
GeneralOption,
|
|
|
|
OptionalTopologie,
|
2018-07-10 23:07:31 +00:00
|
|
|
HomeOption,
|
|
|
|
Reminder,
|
2018-07-11 00:19:29 +00:00
|
|
|
RadiusKey,
|
2018-09-02 14:53:21 +00:00
|
|
|
SwitchManagementCred,
|
|
|
|
RadiusOption,
|
2018-04-16 03:28:27 +00:00
|
|
|
)
|
2017-08-24 19:36:59 +00:00
|
|
|
from . import models
|
|
|
|
from . import forms
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-05-07 17:43:53 +00:00
|
|
|
@can_view_all(OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption,
|
|
|
|
AssoOption, MailMessageOption, HomeOption)
|
2017-06-25 22:50:55 +00:00
|
|
|
def display_options(request):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Vue pour affichage des options (en vrac) classé selon les models
|
|
|
|
correspondants dans un tableau"""
|
|
|
|
useroptions, _created = OptionalUser.objects.get_or_create()
|
|
|
|
machineoptions, _created = OptionalMachine.objects.get_or_create()
|
|
|
|
topologieoptions, _created = OptionalTopologie.objects.get_or_create()
|
|
|
|
generaloptions, _created = GeneralOption.objects.get_or_create()
|
|
|
|
assooptions, _created = AssoOption.objects.get_or_create()
|
2018-04-16 16:22:51 +00:00
|
|
|
homeoptions, _created = HomeOption.objects.get_or_create()
|
2017-10-14 04:03:53 +00:00
|
|
|
mailmessageoptions, _created = MailMessageOption.objects.get_or_create()
|
2017-08-25 02:35:49 +00:00
|
|
|
service_list = Service.objects.all()
|
2018-06-30 17:19:40 +00:00
|
|
|
mailcontact_list = MailContact.objects.all()
|
2018-07-10 23:07:31 +00:00
|
|
|
reminder_list = Reminder.objects.all()
|
|
|
|
radiuskey_list = RadiusKey.objects.all()
|
2018-07-11 00:19:29 +00:00
|
|
|
switchmanagementcred_list = SwitchManagementCred.objects.all()
|
2018-09-02 14:53:21 +00:00
|
|
|
radiusoptions, _ = RadiusOption.objects.get_or_create()
|
2017-10-14 04:03:53 +00:00
|
|
|
return form({
|
|
|
|
'useroptions': useroptions,
|
|
|
|
'machineoptions': machineoptions,
|
|
|
|
'topologieoptions': topologieoptions,
|
|
|
|
'generaloptions': generaloptions,
|
|
|
|
'assooptions': assooptions,
|
2018-04-16 16:22:51 +00:00
|
|
|
'homeoptions': homeoptions,
|
2017-10-14 04:03:53 +00:00
|
|
|
'mailmessageoptions': mailmessageoptions,
|
2018-06-30 17:19:40 +00:00
|
|
|
'service_list': service_list,
|
2018-07-10 23:07:31 +00:00
|
|
|
'mailcontact_list': mailcontact_list,
|
2018-09-19 21:24:03 +00:00
|
|
|
'reminder_list': reminder_list,
|
2018-07-10 23:07:31 +00:00
|
|
|
'radiuskey_list' : radiuskey_list,
|
2018-09-02 14:53:21 +00:00
|
|
|
'switchmanagementcred_list': switchmanagementcred_list,
|
|
|
|
'radiusoptions' : radiusoptions,
|
2017-10-14 04:03:53 +00:00
|
|
|
}, 'preferences/display_preferences.html', request)
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-08-24 19:36:59 +00:00
|
|
|
def edit_options(request, section):
|
|
|
|
""" Edition des préférences générales"""
|
|
|
|
model = getattr(models, section, None)
|
|
|
|
form_instance = getattr(forms, 'Edit' + section + 'Form', None)
|
2018-01-08 10:04:00 +00:00
|
|
|
if not (model or form_instance):
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.error(request, _("Unknown object."))
|
2018-01-08 10:04:00 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
|
|
|
|
options_instance, _created = model.objects.get_or_create()
|
|
|
|
can, msg = options_instance.can_edit(request.user)
|
|
|
|
if not can:
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.error(request, msg or _("You don't have the right to edit"
|
|
|
|
" this option."))
|
2018-01-08 10:04:00 +00:00
|
|
|
return redirect(reverse('index'))
|
|
|
|
options = form_instance(
|
|
|
|
request.POST or None,
|
2018-01-14 22:47:44 +00:00
|
|
|
request.FILES or None,
|
2018-01-08 10:04:00 +00:00
|
|
|
instance=options_instance
|
|
|
|
)
|
|
|
|
if options.is_valid():
|
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
options.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment(
|
2018-08-05 16:48:35 +00:00
|
|
|
"Field(s) edited: %s" % ', '.join(
|
2018-01-08 10:04:00 +00:00
|
|
|
field for field in options.changed_data
|
2017-10-14 04:03:53 +00:00
|
|
|
)
|
|
|
|
)
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.success(request, _("The preferences were edited."))
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
2018-01-08 10:04:00 +00:00
|
|
|
return form(
|
2018-12-02 16:03:27 +00:00
|
|
|
{
|
|
|
|
'options': options,
|
|
|
|
},
|
2018-01-08 10:04:00 +00:00
|
|
|
'preferences/edit_preferences.html',
|
|
|
|
request
|
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-08-25 02:35:49 +00:00
|
|
|
@login_required
|
2017-12-08 23:41:16 +00:00
|
|
|
@can_create(Service)
|
|
|
|
def add_service(request):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Ajout d'un service de la page d'accueil"""
|
2018-04-15 17:09:12 +00:00
|
|
|
service = ServiceForm(request.POST or None, request.FILES or None)
|
2017-12-08 23:41:16 +00:00
|
|
|
if service.is_valid():
|
2018-09-30 18:29:46 +00:00
|
|
|
service.save()
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.success(request, _("The service was added."))
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
2017-10-14 04:03:53 +00:00
|
|
|
return form(
|
2018-08-05 16:48:35 +00:00
|
|
|
{'preferenceform': service, 'action_name': _("Add a service")},
|
2017-10-14 04:03:53 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
2017-08-25 02:35:49 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-08 23:41:16 +00:00
|
|
|
@can_edit(Service)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_service(request, service_instance, **_kwargs):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Edition des services affichés sur la page d'accueil"""
|
2018-05-07 17:43:53 +00:00
|
|
|
service = ServiceForm(
|
2018-05-07 18:03:12 +00:00
|
|
|
request.POST or None,
|
|
|
|
request.FILES or None,
|
|
|
|
instance=service_instance
|
|
|
|
)
|
2017-12-08 23:41:16 +00:00
|
|
|
if service.is_valid():
|
2018-09-30 18:29:46 +00:00
|
|
|
service.save()
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.success(request, _("The service was edited."))
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
2017-10-14 04:03:53 +00:00
|
|
|
return form(
|
2018-08-05 16:48:35 +00:00
|
|
|
{'preferenceform': service, 'action_name': _("Edit")},
|
2017-10-14 04:03:53 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
2017-08-25 02:35:49 +00:00
|
|
|
@login_required
|
2018-09-30 18:29:46 +00:00
|
|
|
@can_delete(Service)
|
|
|
|
def del_service(request, service_instance, **_kwargs):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Suppression d'un service de la page d'accueil"""
|
2018-09-30 18:29:46 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
service_instance.delete()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The service was deleted."))
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
2017-10-14 04:03:53 +00:00
|
|
|
return form(
|
2018-09-30 18:29:46 +00:00
|
|
|
{'objet': service_instance, 'objet_name': 'service'},
|
|
|
|
'preferences/delete.html',
|
2017-10-14 04:03:53 +00:00
|
|
|
request
|
2018-09-30 18:29:46 +00:00
|
|
|
)
|
2018-06-30 17:19:40 +00:00
|
|
|
|
2018-09-19 21:24:03 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(Reminder)
|
|
|
|
def add_reminder(request):
|
2018-09-30 18:29:46 +00:00
|
|
|
"""Ajout d'un mail de rappel"""
|
2018-09-19 21:24:03 +00:00
|
|
|
reminder = ReminderForm(request.POST or None, request.FILES or None)
|
2018-09-30 18:29:46 +00:00
|
|
|
if reminder.is_valid():
|
|
|
|
reminder.save()
|
|
|
|
messages.success(request, _("The reminder was added."))
|
2018-09-19 21:24:03 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2019-01-08 23:39:47 +00:00
|
|
|
{'preferenceform': reminder, 'action_name': _("Add a reminder")},
|
2018-09-19 21:24:03 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(Reminder)
|
2018-09-30 18:29:46 +00:00
|
|
|
def edit_reminder(request, reminder_instance, **_kwargs):
|
|
|
|
"""Edition reminder"""
|
2018-09-19 21:24:03 +00:00
|
|
|
reminder = ReminderForm(
|
|
|
|
request.POST or None,
|
|
|
|
request.FILES or None,
|
|
|
|
instance=reminder_instance
|
|
|
|
)
|
|
|
|
if reminder.is_valid():
|
2018-09-30 18:29:46 +00:00
|
|
|
reminder.save()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The reminder was edited."))
|
2018-09-19 21:24:03 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2018-09-30 18:29:46 +00:00
|
|
|
{'preferenceform': reminder, 'action_name': _("Edit")},
|
2018-09-19 21:24:03 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-06-30 17:19:40 +00:00
|
|
|
|
|
|
|
@login_required
|
2018-07-10 23:07:31 +00:00
|
|
|
@can_delete(Reminder)
|
|
|
|
def del_reminder(request, reminder_instance, **_kwargs):
|
|
|
|
"""Destruction d'un reminder"""
|
|
|
|
if request.method == "POST":
|
|
|
|
reminder_instance.delete()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The reminder was deleted."))
|
2018-07-10 23:07:31 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
|
|
|
{'objet': reminder_instance, 'objet_name': 'reminder'},
|
|
|
|
'preferences/delete.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_create(RadiusKey)
|
|
|
|
def add_radiuskey(request):
|
|
|
|
"""Ajout d'une clef radius"""
|
|
|
|
radiuskey = RadiusKeyForm(request.POST or None)
|
|
|
|
if radiuskey.is_valid():
|
|
|
|
radiuskey.save()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The RADIUS key was added."))
|
2018-07-10 23:07:31 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2019-01-08 23:39:47 +00:00
|
|
|
{'preferenceform': radiuskey, 'action_name': _("Add a RADIUS key")},
|
2018-07-10 23:07:31 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
@can_edit(RadiusKey)
|
|
|
|
def edit_radiuskey(request, radiuskey_instance, **_kwargs):
|
|
|
|
"""Edition des clefs radius"""
|
|
|
|
radiuskey = RadiusKeyForm(request.POST or None, instance=radiuskey_instance)
|
|
|
|
if radiuskey.is_valid():
|
|
|
|
radiuskey.save()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The RADIUS key was edited."))
|
2018-07-10 23:07:31 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2019-01-08 23:39:47 +00:00
|
|
|
{'preferenceform': radiuskey, 'action_name': _("Edit")},
|
2018-07-10 23:07:31 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(RadiusKey)
|
|
|
|
def del_radiuskey(request, radiuskey_instance, **_kwargs):
|
|
|
|
"""Destruction d'un radiuskey"""
|
|
|
|
if request.method == "POST":
|
2018-07-11 01:14:56 +00:00
|
|
|
try:
|
|
|
|
radiuskey_instance.delete()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The RADIUS key was deleted."))
|
2018-07-11 01:14:56 +00:00
|
|
|
except ProtectedError:
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.error(request, _("The RADIUS key is assigned to at least"
|
|
|
|
" one switch, you can't delete it."))
|
2018-07-10 23:07:31 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
|
|
|
{'objet': radiuskey_instance, 'objet_name': 'radiuskey'},
|
|
|
|
'preferences/delete.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-07-11 00:19:29 +00:00
|
|
|
@can_create(SwitchManagementCred)
|
|
|
|
def add_switchmanagementcred(request):
|
|
|
|
"""Ajout de creds de management"""
|
|
|
|
switchmanagementcred = SwitchManagementCredForm(request.POST or None)
|
|
|
|
if switchmanagementcred.is_valid():
|
|
|
|
switchmanagementcred.save()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The switch management credentials were added."))
|
2018-07-11 00:19:29 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2019-01-08 23:39:47 +00:00
|
|
|
{'preferenceform': switchmanagementcred, 'action_name': _("Add switch management credentials")},
|
2018-07-11 00:19:29 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
@can_edit(SwitchManagementCred)
|
|
|
|
def edit_switchmanagementcred(request, switchmanagementcred_instance, **_kwargs):
|
|
|
|
"""Edition des creds de management"""
|
|
|
|
switchmanagementcred = SwitchManagementCredForm(request.POST or None, instance=switchmanagementcred_instance)
|
|
|
|
if switchmanagementcred.is_valid():
|
|
|
|
switchmanagementcred.save()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The switch management credentials were edited."))
|
2018-07-11 00:19:29 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2019-01-08 23:39:47 +00:00
|
|
|
{'preferenceform': switchmanagementcred, 'action_name': _("Edit")},
|
2018-07-11 00:19:29 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(SwitchManagementCred)
|
|
|
|
def del_switchmanagementcred(request, switchmanagementcred_instance, **_kwargs):
|
|
|
|
"""Destruction d'un switchmanagementcred"""
|
|
|
|
if request.method == "POST":
|
2018-07-11 01:14:56 +00:00
|
|
|
try:
|
|
|
|
switchmanagementcred_instance.delete()
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.success(request, _("The switch management credentials were deleted."))
|
2018-07-11 01:14:56 +00:00
|
|
|
except ProtectedError:
|
2019-01-08 23:39:47 +00:00
|
|
|
messages.error(request, _("The switch management credentials are"
|
|
|
|
" assigned to at least one switch, you"
|
|
|
|
" can't delete them."))
|
2018-07-11 00:19:29 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
|
|
|
{'objet': switchmanagementcred_instance, 'objet_name': 'switchmanagementcred'},
|
|
|
|
'preferences/delete.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-06-30 17:19:40 +00:00
|
|
|
@can_create(MailContact)
|
|
|
|
def add_mailcontact(request):
|
2018-07-26 19:53:32 +00:00
|
|
|
"""Add a contact email adress."""
|
2018-06-30 17:19:40 +00:00
|
|
|
mailcontact = MailContactForm(
|
|
|
|
request.POST or None,
|
|
|
|
request.FILES or None
|
|
|
|
)
|
|
|
|
if mailcontact.is_valid():
|
2018-07-26 19:53:32 +00:00
|
|
|
mailcontact.save()
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.success(request, _("The contact email address was created."))
|
2018-06-30 17:19:40 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2018-08-05 16:48:35 +00:00
|
|
|
{'preferenceform': mailcontact,
|
|
|
|
'action_name': _("Add a contact email address")},
|
2018-06-30 17:19:40 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(MailContact)
|
|
|
|
def edit_mailcontact(request, mailcontact_instance, **_kwargs):
|
2018-07-26 19:53:32 +00:00
|
|
|
"""Edit contact email adress."""
|
2018-06-30 17:19:40 +00:00
|
|
|
mailcontact = MailContactForm(
|
|
|
|
request.POST or None,
|
|
|
|
request.FILES or None,
|
|
|
|
instance=mailcontact_instance
|
|
|
|
)
|
|
|
|
if mailcontact.is_valid():
|
2018-07-26 19:53:32 +00:00
|
|
|
mailcontact.save()
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.success(request, _("The contact email address was edited."))
|
2018-06-30 17:19:40 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2018-08-05 16:48:35 +00:00
|
|
|
{'preferenceform': mailcontact, 'action_name': _("Edit")},
|
2018-06-30 17:19:40 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete_set(MailContact)
|
|
|
|
def del_mailcontact(request, instances):
|
2018-07-26 19:53:32 +00:00
|
|
|
"""Delete an email adress"""
|
2018-06-30 17:19:40 +00:00
|
|
|
mailcontacts = DelMailContactForm(
|
|
|
|
request.POST or None,
|
|
|
|
instances=instances
|
|
|
|
)
|
|
|
|
if mailcontacts.is_valid():
|
|
|
|
mailcontacts_dels = mailcontacts.cleaned_data['mailcontacts']
|
|
|
|
for mailcontacts_del in mailcontacts_dels:
|
2018-07-26 19:53:32 +00:00
|
|
|
mailcontacts_del.delete()
|
2018-08-05 16:48:35 +00:00
|
|
|
messages.success(request,
|
|
|
|
_("The contact email adress was deleted."))
|
2018-06-30 17:19:40 +00:00
|
|
|
return redirect(reverse('preferences:display-options'))
|
|
|
|
return form(
|
2018-08-05 16:48:35 +00:00
|
|
|
{'preferenceform': mailcontacts, 'action_name': _("Delete")},
|
2018-06-30 17:19:40 +00:00
|
|
|
'preferences/preferences.html',
|
|
|
|
request
|
|
|
|
)
|
2018-08-05 16:48:35 +00:00
|
|
|
|