8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Nouvelle form pour la création de switch

This commit is contained in:
chirac 2016-10-27 19:45:31 +02:00
parent 3442680933
commit 900718557a
2 changed files with 42 additions and 12 deletions

View file

@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, LDAP, MAIN_EXTENSION, GID_RANGES, UID_RANGES, SEARCH_RESULT from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, LDAP, MAIN_EXTENSION, GID_RANGES, UID_RANGES, ASSO_PSEUDO, SEARCH_RESULT
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View file

@ -7,10 +7,14 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from reversion import revisions as reversion from reversion import revisions as reversion
from topologie.models import Switch, Port, Room from topologie.models import Switch, Port, Room
from topologie.forms import EditPortForm, EditSwitchForm, AddPortForm, EditRoomForm from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm, AddPortForm, EditRoomForm
from users.views import form from users.views import form
from users.models import User
from re2o.settings import PAGINATION_NUMBER from machines.forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm
from machines.views import free_ip, full_domain_validator, assign_ipv4
from re2o.settings import ASSO_PSEUDO, PAGINATION_NUMBER
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
@ -116,15 +120,41 @@ def edit_port(request, port_id):
@login_required @login_required
@permission_required('infra') @permission_required('infra')
def new_switch(request): def new_switch(request):
switch = EditSwitchForm(request.POST or None) switch = NewSwitchForm(request.POST or None)
if switch.is_valid(): machine = NewMachineForm(request.POST or None)
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
if switch.is_valid() and machine.is_valid() and interface.is_valid():
try:
user = User.objects.get(pseudo=ASSO_PSEUDO)
except User.DoesNotExist:
messages.error(request, "L'user %s n'existe pas encore, veuillez le créer" % ASSO_PSEUDO)
return redirect("/topologie/")
new_machine = machine.save(commit=False)
new_machine.user = user
new_interface = interface.save(commit=False)
new_switch = switch.save(commit=False)
if full_domain_validator(request, new_interface):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
switch.save() new_machine.save()
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Le switch a été créé") new_interface.machine = new_machine
if free_ip(new_interface.type.ip_type) and not new_interface.ipv4:
new_interface = assign_ipv4(new_interface)
elif not new_interface.ipv4:
messages.error(request, "Il n'y a plus d'ip disponibles")
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_switch.switch_interface = new_interface
with transaction.atomic(), reversion.create_revision():
new_switch.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Le switch a été crée")
return redirect("/topologie/") return redirect("/topologie/")
return form({'topoform':switch}, 'topologie/topo.html', request) return form({'topoform':switch, 'machineform': machine, 'interfaceform': interface}, 'topologie/switch.html', request)
@login_required @login_required
@permission_required('infra') @permission_required('infra')