Murat Parlakisik | b224cc9 | 2017-02-16 16:27:12 -0800 | [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 rest_framework import status |
| 7 | from core.models import * |
| 8 | from django.forms import widgets |
| 9 | from services.progran.models import * |
| 10 | from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied |
| 11 | from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField |
| 12 | import json |
| 13 | |
| 14 | BASE_NAME = 'progran' |
| 15 | |
| 16 | |
| 17 | class VProgranProfileSerializer(PlusModelSerializer): |
| 18 | id = ReadOnlyField() |
| 19 | uiid = serializers.CharField(required=False) |
| 20 | profile = serializers.CharField(required=False) |
| 21 | dlrate = serializers.CharField(required=False) |
| 22 | ulrate = serializers.CharField(required=False) |
| 23 | |
| 24 | |
| 25 | class Meta: |
| 26 | model = VProgranProfile |
| 27 | fields = ('uiid','id', 'profile', 'dlrate' , 'ulrate') |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | class VProgranImsiSerializer(PlusModelSerializer): |
| 33 | id = ReadOnlyField() |
| 34 | uiid = serializers.CharField(required=False) |
| 35 | imsi = serializers.CharField(required=False) |
| 36 | profile = serializers.CharField(required=False) |
| 37 | |
| 38 | |
| 39 | class Meta: |
| 40 | model = VProgranImsi |
| 41 | fields = ('uiid','id', 'imsi', "profile") |
| 42 | |
| 43 | |
| 44 | class ProgranProfileViewSet(XOSViewSet): |
| 45 | base_name = "progran" |
| 46 | method_name = "profile" |
| 47 | method_kind = "viewset" |
| 48 | queryset = VProgranProfile.objects.all() |
| 49 | serializer_class = VProgranProfileSerializer |
| 50 | |
| 51 | @classmethod |
| 52 | def get_urlpatterns(self, api_path="^"): |
| 53 | patterns = super(ProgranProfileViewSet, self).get_urlpatterns(api_path=api_path) |
| 54 | |
| 55 | return patterns |
| 56 | |
| 57 | def list(self, request): |
| 58 | object_list = self.filter_queryset(self.get_queryset()) |
| 59 | |
| 60 | serializer = self.get_serializer(object_list, many=True) |
| 61 | |
| 62 | return Response(serializer.data) |
| 63 | |
| 64 | |
| 65 | class ProgranImsiViewSet(XOSViewSet): |
| 66 | base_name = "progran" |
| 67 | method_name = "imsi" |
| 68 | method_kind = "viewset" |
| 69 | queryset = VProgranImsi.objects.all() |
| 70 | serializer_class = VProgranImsiSerializer |
| 71 | |
| 72 | @classmethod |
| 73 | def get_urlpatterns(self, api_path="^"): |
| 74 | patterns = super(ProgranImsiViewSet, self).get_urlpatterns(api_path=api_path) |
| 75 | |
| 76 | return patterns |
| 77 | |
| 78 | def list(self, request): |
| 79 | object_list = self.filter_queryset(self.get_queryset()) |
| 80 | |
| 81 | serializer = self.get_serializer(object_list, many=True) |
| 82 | |
| 83 | return Response(serializer.data) |