mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 15:33:45 +00:00
Add exception handling
This commit is contained in:
parent
ef33bc67c1
commit
742f95f335
1 changed files with 11 additions and 4 deletions
|
@ -35,6 +35,7 @@ from __future__ import unicode_literals
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.db.models import ProtectedError, F
|
from django.db.models import ProtectedError, F
|
||||||
|
from django.db import IntegrityError
|
||||||
from django.forms import modelformset_factory
|
from django.forms import modelformset_factory
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
@ -506,8 +507,11 @@ def edit_iptype(request, iptype_instance, **_kwargs):
|
||||||
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
|
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
|
||||||
if iptype.is_valid():
|
if iptype.is_valid():
|
||||||
if iptype.changed_data:
|
if iptype.changed_data:
|
||||||
|
try:
|
||||||
iptype.save()
|
iptype.save()
|
||||||
messages.success(request, _("The IP type was edited."))
|
messages.success(request, _("The IP type was edited."))
|
||||||
|
except IntegrityError as e:
|
||||||
|
messages.success(request, _("This IP type change would create duplicated domains"))
|
||||||
return redirect(reverse("machines:index-iptype"))
|
return redirect(reverse("machines:index-iptype"))
|
||||||
return form(
|
return form(
|
||||||
{"iptypeform": iptype, "action_name": _("Edit")},
|
{"iptypeform": iptype, "action_name": _("Edit")},
|
||||||
|
@ -572,8 +576,11 @@ def edit_machinetype(request, machinetype_instance, **_kwargs):
|
||||||
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
|
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
|
||||||
if machinetype.is_valid():
|
if machinetype.is_valid():
|
||||||
if machinetype.changed_data:
|
if machinetype.changed_data:
|
||||||
|
try:
|
||||||
machinetype.save()
|
machinetype.save()
|
||||||
messages.success(request, _("The machine type was edited."))
|
messages.success(request, _("The machine type was edited."))
|
||||||
|
except IntegrityError as e:
|
||||||
|
messages.error(request, _("This machine type change would create duplicated domains"))
|
||||||
return redirect(reverse("machines:index-machinetype"))
|
return redirect(reverse("machines:index-machinetype"))
|
||||||
return form(
|
return form(
|
||||||
{"machinetypeform": machinetype, "action_name": _("Edit")},
|
{"machinetypeform": machinetype, "action_name": _("Edit")},
|
||||||
|
|
Loading…
Reference in a new issue