mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
API support for app topologie
This commit is contained in:
parent
2ef8930ffe
commit
95acdb2ecd
3 changed files with 190 additions and 0 deletions
|
@ -64,6 +64,17 @@ from preferences.models import (
|
||||||
)
|
)
|
||||||
# Avoid duplicate names
|
# Avoid duplicate names
|
||||||
from preferences.models import Service as ServiceOption
|
from preferences.models import Service as ServiceOption
|
||||||
|
from topologie.models import (
|
||||||
|
Stack,
|
||||||
|
AccessPoint,
|
||||||
|
Switch,
|
||||||
|
ModelSwitch,
|
||||||
|
ConstructorSwitch,
|
||||||
|
SwitchBay,
|
||||||
|
Building,
|
||||||
|
Room
|
||||||
|
)
|
||||||
|
from topologie.models import Port as SwitchPort
|
||||||
from users.models import (
|
from users.models import (
|
||||||
User,
|
User,
|
||||||
Club,
|
Club,
|
||||||
|
@ -456,6 +467,106 @@ class OuverturePortSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# TOPOLOGIE APP
|
||||||
|
|
||||||
|
|
||||||
|
class StackSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Stack
|
||||||
|
fields = ('name', 'stack_id', 'details', 'member_id_min',
|
||||||
|
'member_id_max', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'api_url': {'view_name': 'api:stack-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AccessPointSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = AccessPoint
|
||||||
|
fields = ('user', 'name', 'active', 'location', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'user': {'view_name': 'api:user-detail'},
|
||||||
|
'api_url': {'view_name': 'api:accesspoint-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
port_amount = serializers.IntegerField(source='number')
|
||||||
|
class Meta:
|
||||||
|
model = Switch
|
||||||
|
fields = ('port_amount', 'stack', 'stack_member_id', 'model',
|
||||||
|
'switchbay', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'stack': {'view_name': 'api:stack-detail'},
|
||||||
|
'model': {'view_name': 'api:modelswitch-detail'},
|
||||||
|
'switchbay': {'view_name': 'api:switchbay-detail'},
|
||||||
|
'api_url': {'view_name': 'api:switch-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ModelSwitchSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ModelSwitch
|
||||||
|
fields = ('reference', 'constructor', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'constructor': {'view_name': 'api:constructorswitch-detail'},
|
||||||
|
'api_url': {'view_name': 'api:modelswitch-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ConstructorSwitchSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ConstructorSwitch
|
||||||
|
fields = ('name', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'api_url': {'view_name': 'api:constructorswitch-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchBaySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SwitchBay
|
||||||
|
fields = ('name', 'building', 'info', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'building': {'view_name': 'api:building-detail'},
|
||||||
|
'api_url': {'view_name': 'api:switchbay-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BuildingSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Building
|
||||||
|
fields = ('name', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'api_url': {'view_name': 'api:building-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchPortSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SwitchPort
|
||||||
|
fields = ('switch', 'port', 'room', 'machine_interface', 'related',
|
||||||
|
'radius', 'vlan_force', 'details', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'switch': {'view_name': 'api:switch-detail'},
|
||||||
|
'room': {'view_name': 'api:room-detail'},
|
||||||
|
'machine_interface': {'view_name': 'api:interface-detail'},
|
||||||
|
'related': {'view_name': 'api:switchport-detail'},
|
||||||
|
'vlan_force': {'view_name': 'api:vlan-detail'},
|
||||||
|
'api_url': {'view_name': 'api:switchport-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class RoomSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Room
|
||||||
|
fields = ('name', 'details', 'api_url')
|
||||||
|
extra_kwargs = {
|
||||||
|
'api_url': {'view_name': 'api:room-detail'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# USERS APP
|
# USERS APP
|
||||||
|
|
||||||
|
|
||||||
|
|
10
api/urls.py
10
api/urls.py
|
@ -66,6 +66,16 @@ router.register(r'ouvertureports', views.OuverturePortViewSet)
|
||||||
#router.register(r'assooption', views.AssoOptionSerializer)
|
#router.register(r'assooption', views.AssoOptionSerializer)
|
||||||
#router.register(r'homeoption', views.HomeOptionSerializer)
|
#router.register(r'homeoption', views.HomeOptionSerializer)
|
||||||
#router.register(r'mailmessageoption', views.MailMessageOptionSerializer)
|
#router.register(r'mailmessageoption', views.MailMessageOptionSerializer)
|
||||||
|
# TOPOLOGIE APP
|
||||||
|
router.register(r'stack', views.StackViewSet)
|
||||||
|
router.register(r'acesspoint', views.AccessPointViewSet)
|
||||||
|
router.register(r'switch', views.SwitchViewSet)
|
||||||
|
router.register(r'modelswitch', views.ModelSwitchViewSet)
|
||||||
|
router.register(r'constructorswitch', views.ConstructorSwitchViewSet)
|
||||||
|
router.register(r'switchbay', views.SwitchBayViewSet)
|
||||||
|
router.register(r'building', views.BuildingViewSet)
|
||||||
|
router.register(r'switchport', views.SwitchPortViewSet, 'switchport')
|
||||||
|
router.register(r'room', views.RoomViewSet)
|
||||||
# USERS APP
|
# USERS APP
|
||||||
router.register(r'users', views.UserViewSet)
|
router.register(r'users', views.UserViewSet)
|
||||||
router.register(r'clubs', views.ClubViewSet)
|
router.register(r'clubs', views.ClubViewSet)
|
||||||
|
|
69
api/views.py
69
api/views.py
|
@ -74,6 +74,17 @@ from machines.models import (
|
||||||
# )
|
# )
|
||||||
# # Avoid duplicate names
|
# # Avoid duplicate names
|
||||||
# from preferences.models import Service as ServiceOption
|
# from preferences.models import Service as ServiceOption
|
||||||
|
from topologie.models import (
|
||||||
|
Stack,
|
||||||
|
AccessPoint,
|
||||||
|
Switch,
|
||||||
|
ModelSwitch,
|
||||||
|
ConstructorSwitch,
|
||||||
|
SwitchBay,
|
||||||
|
Building,
|
||||||
|
Room
|
||||||
|
)
|
||||||
|
from topologie.models import Port as SwitchPort
|
||||||
from users.models import (
|
from users.models import (
|
||||||
User,
|
User,
|
||||||
Club,
|
Club,
|
||||||
|
@ -123,6 +134,16 @@ from .serializers import (
|
||||||
# AssoOptionSerializer,
|
# AssoOptionSerializer,
|
||||||
# HomeOptionSerializer,
|
# HomeOptionSerializer,
|
||||||
# MailMessageOptionSerializer,
|
# MailMessageOptionSerializer,
|
||||||
|
# TOPOLOGIE APP
|
||||||
|
StackSerializer,
|
||||||
|
AccessPointSerializer,
|
||||||
|
SwitchSerializer,
|
||||||
|
ModelSwitchSerializer,
|
||||||
|
ConstructorSwitchSerializer,
|
||||||
|
SwitchBaySerializer,
|
||||||
|
BuildingSerializer,
|
||||||
|
SwitchPortSerializer,
|
||||||
|
RoomSerializer,
|
||||||
# USERS APP
|
# USERS APP
|
||||||
UserSerializer,
|
UserSerializer,
|
||||||
ClubSerializer,
|
ClubSerializer,
|
||||||
|
@ -309,6 +330,54 @@ class OuverturePortViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
# serializer_class = MailMessageOptionSerializer
|
# serializer_class = MailMessageOptionSerializer
|
||||||
|
|
||||||
|
|
||||||
|
# TOPOLOGIE APP
|
||||||
|
|
||||||
|
|
||||||
|
class StackViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Stack.objects.all()
|
||||||
|
serializer_class = StackSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class AccessPointViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = AccessPoint.objects.all()
|
||||||
|
serializer_class = AccessPointSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Switch.objects.all()
|
||||||
|
serializer_class = SwitchSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ModelSwitchViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = ModelSwitch.objects.all()
|
||||||
|
serializer_class = ModelSwitchSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ConstructorSwitchViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = ConstructorSwitch.objects.all()
|
||||||
|
serializer_class = ConstructorSwitchSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchBayViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = SwitchBay.objects.all()
|
||||||
|
serializer_class = SwitchBaySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class BuildingViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Building.objects.all()
|
||||||
|
serializer_class = BuildingSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchPortViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = SwitchPort.objects.all()
|
||||||
|
serializer_class = SwitchPortSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class RoomViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Room.objects.all()
|
||||||
|
serializer_class = RoomSerializer
|
||||||
|
|
||||||
|
|
||||||
# USER APP
|
# USER APP
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue