mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Add exception handling
This commit is contained in:
parent
be1c051e98
commit
c3fae17599
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:
|
||||||
iptype.save()
|
try:
|
||||||
messages.success(request, _("The IP type was edited."))
|
iptype.save()
|
||||||
|
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:
|
||||||
machinetype.save()
|
try:
|
||||||
messages.success(request, _("The machine type was edited."))
|
machinetype.save()
|
||||||
|
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