Verified Commit 9dfdfac1 authored by erdnaxe's avatar erdnaxe 🎇

Clean up old forms

parent 28336c30
Pipeline #1103 passed with stage
in 3 minutes and 2 seconds
......@@ -171,37 +171,6 @@ class DelAliasForm(FormRevMixin, Form):
)
class MachineTypeForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un machinetype, relié à un iptype"""
class Meta:
model = MachineType
fields = ['name', 'ip_type']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(MachineTypeForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['name'].label = _("Machine type to add")
self.fields['ip_type'].label = _("Related IP type")
class DelMachineTypeForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs machinetype"""
machinetypes = forms.ModelMultipleChoiceField(
queryset=MachineType.objects.none(),
label=_("Current machine types"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelMachineTypeForm, self).__init__(*args, **kwargs)
if instances:
self.fields['machinetypes'].queryset = instances
else:
self.fields['machinetypes'].queryset = MachineType.objects.all()
class IpTypeForm(FormRevMixin, ModelForm):
"""Formulaire d'ajout d'un iptype. Pas d'edition de l'ip de start et de
stop après creation"""
......@@ -472,36 +441,6 @@ class DelSrvForm(FormRevMixin, Form):
self.fields['srv'].queryset = Srv.objects.all()
class NasForm(FormRevMixin, ModelForm):
"""Ajout d'un type de nas (machine d'authentification,
swicths, bornes...)"""
class Meta:
model = Nas
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(NasForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelNasForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs nas"""
nas = forms.ModelMultipleChoiceField(
queryset=Nas.objects.none(),
label=_("Current NAS devices"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelNasForm, self).__init__(*args, **kwargs)
if instances:
self.fields['nas'].queryset = instances
else:
self.fields['nas'].queryset = Nas.objects.all()
class RoleForm(FormRevMixin, ModelForm):
"""Add and edit role."""
......@@ -577,18 +516,6 @@ class DelServiceForm(FormRevMixin, Form):
self.fields['service'].queryset = Service.objects.all()
class VlanForm(FormRevMixin, ModelForm):
"""Ajout d'un vlan : id, nom"""
class Meta:
model = Vlan
fields = ['vlan_id', 'name', 'comment']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(VlanForm, self).__init__(*args, prefix=prefix, **kwargs)
class EditOptionVlanForm(FormRevMixin, ModelForm):
"""Ajout d'un vlan : id, nom"""
class Meta:
......@@ -600,23 +527,6 @@ class EditOptionVlanForm(FormRevMixin, ModelForm):
super(EditOptionVlanForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelVlanForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs vlans"""
vlan = forms.ModelMultipleChoiceField(
queryset=Vlan.objects.none(),
label=_("Current VLANs"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelVlanForm, self).__init__(*args, **kwargs)
if instances:
self.fields['vlan'].queryset = instances
else:
self.fields['vlan'].queryset = Vlan.objects.all()
class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
"""Edition de la liste des profils d'ouverture de ports
pour l'interface"""
......
......@@ -48,8 +48,6 @@ from .forms import (
EditMachineForm,
EditInterfaceForm,
AddInterfaceForm,
MachineTypeForm,
DelMachineTypeForm,
ExtensionForm,
DelExtensionForm,
EditIpTypeForm,
......@@ -68,15 +66,11 @@ from .forms import (
DelDNameForm,
MxForm,
DelMxForm,
VlanForm,
DelVlanForm,
RoleForm,
DelRoleForm,
ServiceForm,
DelServiceForm,
SshFpForm,
NasForm,
DelNasForm,
SrvForm,
DelSrvForm,
Ipv6ListForm,
......@@ -87,7 +81,6 @@ from .models import (
IpType,
Machine,
Interface,
MachineType,
Extension,
SOA,
Mx,
......@@ -97,8 +90,6 @@ from .models import (
Service,
Service_link,
regen,
Vlan,
Nas,
Txt,
DName,
Srv,
......
......@@ -152,17 +152,6 @@ class NewSwitchForm(NewMachineForm):
fields = ['name', 'switchbay', 'number', 'stack', 'stack_member_id']
class EditRoomForm(FormRevMixin, ModelForm):
"""Permet d'éediter le nom et commentaire d'une prise murale"""
class Meta:
model = Room
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditRoomForm, self).__init__(*args, prefix=prefix, **kwargs)
class CreatePortsForm(forms.Form):
"""Permet de créer une liste de ports pour un switch."""
begin = forms.IntegerField(label=_("Start:"), min_value=0)
......@@ -236,28 +225,6 @@ class EditSwitchBayForm(FormRevMixin, ModelForm):
return instance
class EditBuildingForm(FormRevMixin, ModelForm):
"""Permet d'éditer le batiment"""
class Meta:
model = Building
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditBuildingForm, self).__init__(*args, prefix=prefix, **kwargs)
class EditDormitoryForm(FormRevMixin, ModelForm):
"""Enable dormitory edition"""
class Meta:
model = Dormitory
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditDormitoryForm, self).__init__(*args, prefix=prefix, **kwargs)
class EditPortProfileForm(FormRevMixin, ModelForm):
"""Form to edit a port profile"""
class Meta:
......
# -*- mode: python; coding: utf-8 -*-
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
"""topologie.tests
The tests for the Topologie module.
"""
# from django.test import TestCase
# Create your tests here.
......@@ -81,24 +81,6 @@ urlpatterns = [
url(r'^del_switch_bay/(?P<switchbayid>[0-9]+)$',
views.del_switch_bay,
name='del-switch-bay'),
url(r'^new_building/$',
views.new_building,
name='new-building'),
url(r'^edit_building/(?P<buildingid>[0-9]+)$',
views.edit_building,
name='edit-building'),
url(r'^del_building/(?P<buildingid>[0-9]+)$',
views.del_building,
name='del-building'),
url(r'^new_dormitory/$',
views.new_dormitory,
name='new-dormitory'),
url(r'^edit_dormitory/(?P<dormitoryid>[0-9]+)$',
views.edit_dormitory,
name='edit-dormitory'),
url(r'^del_dormitory/(?P<dormitoryid>[0-9]+)$',
views.del_dormitory,
name='del-dormitory'),
url(r'^index_port_profile/$',
views.index_port_profile,
name='index-port-profile'),
......
......@@ -28,7 +28,7 @@ from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from django.db.models import ProtectedError, Prefetch
from django.core.exceptions import ValidationError
from django.template import Context, Template, loader
from django.template import Template, loader
from django.utils.translation import ugettext as _
import tempfile
......@@ -63,7 +63,6 @@ from preferences.models import AssoOption, GeneralOption
from .models import (
Switch,
Port,
Room,
Stack,
ModelSwitch,
ConstructorSwitch,
......@@ -81,7 +80,6 @@ from .forms import (
NewSwitchForm,
EditSwitchForm,
AddPortForm,
EditRoomForm,
StackForm,
EditModelSwitchForm,
EditConstructorSwitchForm,
......@@ -89,8 +87,6 @@ from .forms import (
AddAccessPointForm,
EditAccessPointForm,
EditSwitchBayForm,
EditBuildingForm,
EditDormitoryForm,
EditPortProfileForm,
EditModuleForm,
EditSwitchModuleForm,
......@@ -806,122 +802,6 @@ def del_switch_bay(request, switch_bay, **_kwargs):
)
@login_required
@can_create(Building)
def new_building(request):
"""New Building of a dorm
Nouveau batiment"""
building = EditBuildingForm(request.POST or None)
if building.is_valid():
building.save()
messages.success(request, _("The building was created."))
return redirect(reverse('topologie:index-physical-grouping'))
return form(
{'topoform': building, 'action_name': _("Create")},
'topologie/topo.html',
request
)
@login_required
@can_edit(Building)
def edit_building(request, building, **_kwargs):
"""Edit a building
Edition d'un batiment"""
building = EditBuildingForm(request.POST or None, instance=building)
if building.is_valid():
if building.changed_data:
building.save()
messages.success(request, _("The building was edited."))
return redirect(reverse('topologie:index-physical-grouping'))
return form(
{'topoform': building, 'action_name': _("Edit")},
'topologie/topo.html',
request
)
@login_required
@can_delete(Building)
def del_building(request, building, **_kwargs):
"""Delete a building
Suppression d'un batiment"""
if request.method == "POST":
try:
building.delete()
messages.success(request, _("The building was deleted."))
except ProtectedError:
messages.error(
request,
(_("The building %s is used by another object, impossible"
" to delete it.") % building)
)
return redirect(reverse('topologie:index-physical-grouping'))
return form(
{'objet': building, 'objet_name': _("Building")},
'topologie/delete.html',
request
)
@login_required
@can_create(Dormitory)
def new_dormitory(request):
"""A new dormitory
Nouvelle residence"""
dormitory = EditDormitoryForm(request.POST or None)
if dormitory.is_valid():
dormitory.save()
messages.success(request, _("The dormitory was created."))
return redirect(reverse('topologie:index-physical-grouping'))
return form(
{'topoform': dormitory, 'action_name': _("Create")},
'topologie/topo.html',
request
)
@login_required
@can_edit(Dormitory)
def edit_dormitory(request, dormitory, **_kwargs):
"""Edit a dormitory
Edition d'une residence"""
dormitory = EditDormitoryForm(request.POST or None, instance=dormitory)
if dormitory.is_valid():
if dormitory.changed_data:
dormitory.save()
messages.success(request, _("The dormitory was edited."))
return redirect(reverse('topologie:index-physical-grouping'))
return form(
{'topoform': dormitory, 'action_name': _("Edit")},
'topologie/topo.html',
request
)
@login_required
@can_delete(Dormitory)
def del_dormitory(request, dormitory, **_kwargs):
"""Delete a dormitory
Suppression d'une residence"""
if request.method == "POST":
try:
dormitory.delete()
messages.success(request, _("The dormitory was deleted."))
except ProtectedError:
messages.error(
request,
(_("The dormitory %s is used by another object, impossible"
" to delete it.") % dormitory)
)
return redirect(reverse('topologie:index-physical-grouping'))
return form(
{'objet': dormitory, 'objet_name': _("Dormitory")},
'topologie/delete.html',
request
)
@login_required
@can_create(ConstructorSwitch)
def new_constructor_switch(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment