Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 1 | from rest_framework.decorators import api_view |
| 2 | from rest_framework.response import Response |
| 3 | from rest_framework.reverse import reverse |
| 4 | from rest_framework import serializers |
| 5 | from rest_framework import generics |
| 6 | from core.models import * |
| 7 | from django.forms import widgets |
| 8 | from cord.models import VOLTTenant |
| 9 | from core.xoslib.objects.cordsubscriber import CordSubscriber |
| 10 | from plus import PlusSerializerMixin |
| 11 | from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied |
| 12 | |
| 13 | if hasattr(serializers, "ReadOnlyField"): |
| 14 | # rest_framework 3.x |
Scott Baker | 808a15f | 2015-04-16 21:56:03 -0700 | [diff] [blame] | 15 | ReadOnlyField = serializers.ReadOnlyField |
Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 16 | else: |
| 17 | # rest_framework 2.x |
Scott Baker | 808a15f | 2015-04-16 21:56:03 -0700 | [diff] [blame] | 18 | ReadOnlyField = serializers.Field |
Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 19 | |
| 20 | class CordSubscriberIdSerializer(serializers.ModelSerializer, PlusSerializerMixin): |
Scott Baker | 808a15f | 2015-04-16 21:56:03 -0700 | [diff] [blame] | 21 | id = ReadOnlyField() |
Scott Baker | 297c138 | 2015-04-20 09:17:34 -0700 | [diff] [blame^] | 22 | vlan_id = ReadOnlyField() |
Scott Baker | 808a15f | 2015-04-16 21:56:03 -0700 | [diff] [blame] | 23 | vcpe_id = ReadOnlyField() |
| 24 | sliver = ReadOnlyField() |
| 25 | image = ReadOnlyField() |
Scott Baker | 297c138 | 2015-04-20 09:17:34 -0700 | [diff] [blame^] | 26 | vbng_id = ReadOnlyField() |
Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 27 | firewall_enable = serializers.BooleanField() |
Scott Baker | 808a15f | 2015-04-16 21:56:03 -0700 | [diff] [blame] | 28 | firewall_rules = serializers.CharField() |
| 29 | url_filter_enable = serializers.BooleanField() |
| 30 | url_filter_rules = serializers.CharField() |
| 31 | cdn_enable = serializers.BooleanField() |
| 32 | sliver_name = ReadOnlyField() |
| 33 | image_name = ReadOnlyField() |
Scott Baker | 297c138 | 2015-04-20 09:17:34 -0700 | [diff] [blame^] | 34 | routeable_subnet = serializers.CharField() |
Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 35 | |
| 36 | humanReadableName = serializers.SerializerMethodField("getHumanReadableName") |
| 37 | |
| 38 | class Meta: |
| 39 | model = CordSubscriber |
| 40 | fields = ('humanReadableName', 'id', |
Scott Baker | 297c138 | 2015-04-20 09:17:34 -0700 | [diff] [blame^] | 41 | 'vlan_id', |
| 42 | 'vcpe_id', 'sliver', 'sliver_name', 'image', 'image_name', 'firewall_enable', 'firewall_rules', 'url_filter_enable', 'url_filter_rules', 'cdn_enable', 'vbng_id', 'routeable_subnet',) |
Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 43 | |
| 44 | |
| 45 | def getHumanReadableName(self, obj): |
Scott Baker | 808a15f | 2015-04-16 21:56:03 -0700 | [diff] [blame] | 46 | return obj.__unicode__() |
Scott Baker | b0cfe52 | 2015-04-15 22:11:25 -0700 | [diff] [blame] | 47 | |
| 48 | class CordSubscriberList(XOSListCreateAPIView): |
| 49 | queryset = CordSubscriber.get_tenant_objects().select_related().all() |
| 50 | serializer_class = CordSubscriberIdSerializer |
| 51 | |
| 52 | method_kind = "list" |
| 53 | method_name = "cordsubscriber" |
| 54 | |
| 55 | class CordSubscriberDetail(XOSRetrieveUpdateDestroyAPIView): |
| 56 | queryset = CordSubscriber.get_tenant_objects().select_related().all() |
| 57 | serializer_class = CordSubscriberIdSerializer |
| 58 | |
| 59 | method_kind = "detail" |
| 60 | method_name = "cordsubscriber" |
| 61 | |
| 62 | |