Matteo Scandolo | c3ca49b | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Murat Parlakisik | b224cc9 | 2017-02-16 16:27:12 -0800 | [diff] [blame] | 17 | from rest_framework.decorators import api_view |
| 18 | from rest_framework.response import Response |
| 19 | from rest_framework.reverse import reverse |
| 20 | from rest_framework import serializers |
| 21 | from rest_framework import generics |
| 22 | from rest_framework import status |
| 23 | from core.models import * |
| 24 | from django.forms import widgets |
| 25 | from services.progran.models import * |
| 26 | from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied |
| 27 | from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField |
| 28 | import json |
| 29 | |
| 30 | BASE_NAME = 'progran' |
| 31 | |
| 32 | |
| 33 | class VProgranProfileSerializer(PlusModelSerializer): |
| 34 | id = ReadOnlyField() |
| 35 | uiid = serializers.CharField(required=False) |
| 36 | profile = serializers.CharField(required=False) |
| 37 | dlrate = serializers.CharField(required=False) |
| 38 | ulrate = serializers.CharField(required=False) |
| 39 | |
| 40 | |
| 41 | class Meta: |
| 42 | model = VProgranProfile |
| 43 | fields = ('uiid','id', 'profile', 'dlrate' , 'ulrate') |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | class VProgranImsiSerializer(PlusModelSerializer): |
| 49 | id = ReadOnlyField() |
| 50 | uiid = serializers.CharField(required=False) |
| 51 | imsi = serializers.CharField(required=False) |
| 52 | profile = serializers.CharField(required=False) |
| 53 | |
| 54 | |
| 55 | class Meta: |
| 56 | model = VProgranImsi |
| 57 | fields = ('uiid','id', 'imsi', "profile") |
| 58 | |
| 59 | |
| 60 | class ProgranProfileViewSet(XOSViewSet): |
| 61 | base_name = "progran" |
| 62 | method_name = "profile" |
| 63 | method_kind = "viewset" |
| 64 | queryset = VProgranProfile.objects.all() |
| 65 | serializer_class = VProgranProfileSerializer |
| 66 | |
| 67 | @classmethod |
| 68 | def get_urlpatterns(self, api_path="^"): |
| 69 | patterns = super(ProgranProfileViewSet, self).get_urlpatterns(api_path=api_path) |
| 70 | |
| 71 | return patterns |
| 72 | |
| 73 | def list(self, request): |
| 74 | object_list = self.filter_queryset(self.get_queryset()) |
| 75 | |
| 76 | serializer = self.get_serializer(object_list, many=True) |
| 77 | |
| 78 | return Response(serializer.data) |
| 79 | |
| 80 | |
| 81 | class ProgranImsiViewSet(XOSViewSet): |
| 82 | base_name = "progran" |
| 83 | method_name = "imsi" |
| 84 | method_kind = "viewset" |
| 85 | queryset = VProgranImsi.objects.all() |
| 86 | serializer_class = VProgranImsiSerializer |
| 87 | |
| 88 | @classmethod |
| 89 | def get_urlpatterns(self, api_path="^"): |
| 90 | patterns = super(ProgranImsiViewSet, self).get_urlpatterns(api_path=api_path) |
| 91 | |
| 92 | return patterns |
| 93 | |
| 94 | def list(self, request): |
| 95 | object_list = self.filter_queryset(self.get_queryset()) |
| 96 | |
| 97 | serializer = self.get_serializer(object_list, many=True) |
| 98 | |
| 99 | return Response(serializer.data) |