Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
d0620328
Commit
d0620328
authored
Oct 13, 2017
by
chirac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pylint, pep8 et doc sur forms et admin de topologie
parent
e211957e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
7 deletions
+58
-7
topologie/admin.py
topologie/admin.py
+12
-0
topologie/forms.py
topologie/forms.py
+46
-7
No files found.
topologie/admin.py
View file @
d0620328
...
...
@@ -20,6 +20,9 @@
# 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.
"""
Fichier définissant les administration des models dans l'interface admin
"""
from
__future__
import
unicode_literals
...
...
@@ -28,18 +31,27 @@ from reversion.admin import VersionAdmin
from
.models
import
Port
,
Room
,
Switch
,
Stack
class
StackAdmin
(
VersionAdmin
):
"""Administration d'une stack de switches (inclus des switches)"""
pass
class
SwitchAdmin
(
VersionAdmin
):
"""Administration d'un switch"""
pass
class
PortAdmin
(
VersionAdmin
):
"""Administration d'un port de switches"""
pass
class
RoomAdmin
(
VersionAdmin
):
"""Administration d'un chambre"""
pass
admin
.
site
.
register
(
Port
,
PortAdmin
)
admin
.
site
.
register
(
Room
,
RoomAdmin
)
admin
.
site
.
register
(
Switch
,
SwitchAdmin
)
...
...
topologie/forms.py
View file @
d0620328
...
...
@@ -19,14 +19,27 @@
# 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.
"""
Un forms le plus simple possible pour les objets topologie de re2o.
Permet de créer et supprimer : un Port de switch, relié à un switch.
Permet de créer des stacks et d'y ajouter des switchs (StackForm)
Permet de créer, supprimer et editer un switch (EditSwitchForm,
NewSwitchForm)
"""
from
__future__
import
unicode_literals
from
.models
import
Port
,
Switch
,
Room
,
Stack
from
django.forms
import
ModelForm
,
Form
from
machines.models
import
Interface
from
django.forms
import
ModelForm
from
.models
import
Port
,
Switch
,
Room
,
Stack
class
PortForm
(
ModelForm
):
"""Formulaire pour la création d'un port d'un switch
Relié directement au modèle port"""
class
Meta
:
model
=
Port
fields
=
'__all__'
...
...
@@ -35,25 +48,45 @@ class PortForm(ModelForm):
prefix
=
kwargs
.
pop
(
'prefix'
,
self
.
Meta
.
model
.
__name__
)
super
(
PortForm
,
self
).
__init__
(
*
args
,
prefix
=
prefix
,
**
kwargs
)
class
EditPortForm
(
ModelForm
):
"""Form pour l'édition d'un port de switche : changement des reglages
radius ou vlan, ou attribution d'une chambre, autre port ou machine
Un port est relié à une chambre, un autre port (uplink) ou une machine
(serveur ou borne), mutuellement exclusif
Optimisation sur les queryset pour machines et port_related pour
optimiser le temps de chargement avec select_related (vraiment
lent sans)"""
class
Meta
(
PortForm
.
Meta
):
fields
=
[
'room'
,
'related'
,
'machine_interface'
,
'radius'
,
'vlan_force'
,
'details'
]
fields
=
[
'room'
,
'related'
,
'machine_interface'
,
'radius'
,
'vlan_force'
,
'details'
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
prefix
=
kwargs
.
pop
(
'prefix'
,
self
.
Meta
.
model
.
__name__
)
super
(
EditPortForm
,
self
).
__init__
(
*
args
,
prefix
=
prefix
,
**
kwargs
)
self
.
fields
[
'machine_interface'
].
queryset
=
Interface
.
objects
.
all
().
select_related
(
'domain__extension'
)
self
.
fields
[
'related'
].
queryset
=
Port
.
objects
.
all
().
select_related
(
'switch__switch_interface__domain__extension'
).
order_by
(
'switch'
,
'port'
)
self
.
fields
[
'machine_interface'
].
queryset
=
Interface
.
objects
.
all
()
\
.
select_related
(
'domain__extension'
)
self
.
fields
[
'related'
].
queryset
=
Port
.
objects
.
all
()
\
.
select_related
(
'switch__switch_interface__domain__extension'
)
\
.
order_by
(
'switch'
,
'port'
)
class
AddPortForm
(
ModelForm
):
"""Permet d'ajouter un port de switch. Voir EditPortForm pour plus
d'informations"""
class
Meta
(
PortForm
.
Meta
):
fields
=
[
'port'
,
'room'
,
'machine_interface'
,
'related'
,
'radius'
,
'vlan_force'
,
'details'
]
fields
=
[
'port'
,
'room'
,
'machine_interface'
,
'related'
,
'radius'
,
'vlan_force'
,
'details'
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
prefix
=
kwargs
.
pop
(
'prefix'
,
self
.
Meta
.
model
.
__name__
)
super
(
AddPortForm
,
self
).
__init__
(
*
args
,
prefix
=
prefix
,
**
kwargs
)
class
StackForm
(
ModelForm
):
"""Permet d'edition d'une stack : stack_id, et switches membres
de la stack"""
class
Meta
:
model
=
Stack
fields
=
'__all__'
...
...
@@ -62,7 +95,9 @@ class StackForm(ModelForm):
prefix
=
kwargs
.
pop
(
'prefix'
,
self
.
Meta
.
model
.
__name__
)
super
(
StackForm
,
self
).
__init__
(
*
args
,
prefix
=
prefix
,
**
kwargs
)
class
EditSwitchForm
(
ModelForm
):
"""Permet d'éditer un switch : nom et nombre de ports"""
class
Meta
:
model
=
Switch
fields
=
'__all__'
...
...
@@ -73,7 +108,10 @@ class EditSwitchForm(ModelForm):
self
.
fields
[
'location'
].
label
=
'Localisation'
self
.
fields
[
'number'
].
label
=
'Nombre de ports'
class
NewSwitchForm
(
ModelForm
):
"""Permet de créer un switch : emplacement, paramètres machine,
membre d'un stack (option), nombre de ports (number)"""
class
Meta
(
EditSwitchForm
.
Meta
):
fields
=
[
'location'
,
'number'
,
'details'
,
'stack'
,
'stack_member_id'
]
...
...
@@ -81,7 +119,9 @@ class NewSwitchForm(ModelForm):
prefix
=
kwargs
.
pop
(
'prefix'
,
self
.
Meta
.
model
.
__name__
)
super
(
NewSwitchForm
,
self
).
__init__
(
*
args
,
prefix
=
prefix
,
**
kwargs
)
class
EditRoomForm
(
ModelForm
):
"""Permet d'éediter le nom et commentaire d'une prise murale"""
class
Meta
:
model
=
Room
fields
=
'__all__'
...
...
@@ -89,4 +129,3 @@ class EditRoomForm(ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
prefix
=
kwargs
.
pop
(
'prefix'
,
self
.
Meta
.
model
.
__name__
)
super
(
EditRoomForm
,
self
).
__init__
(
*
args
,
prefix
=
prefix
,
**
kwargs
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment