blob: 51aee080f387032aad0364288399e9e32ed4fed2 [file] [log] [blame]
Matteo Scandolo35113f72017-08-08 13:05:25 -07001
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
Scott Baker619de672016-06-20 12:49:38 -070017from rest_framework.decorators import api_view
18from rest_framework.response import Response
19from rest_framework.reverse import reverse
20from rest_framework import serializers
21from rest_framework import generics
22from rest_framework import viewsets
23from rest_framework import status
24from rest_framework.decorators import detail_route, list_route
25from rest_framework.views import APIView
26from core.models import *
27from django.forms import widgets
28from django.conf.urls import patterns, url
29from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
30from django.shortcuts import get_object_or_404
31from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
32from xos.exceptions import *
33import json
34import subprocess
35from services.exampleservice.models import ExampleService
36
37class ExampleServiceSerializer(PlusModelSerializer):
38 id = ReadOnlyField()
39 humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
40 service_message = serializers.CharField(required=False)
41
42 class Meta:
43 model = ExampleService
44 fields = ('humanReadableName',
45 'id',
46 'service_message')
47
48 def getHumanReadableName(self, obj):
49 return obj.__unicode__()
50
51class ExampleServiceViewSet(XOSViewSet):
52 base_name = "exampleservice"
53 method_name = "exampleservice"
54 method_kind = "viewset"
Scott Baker589e6c42017-05-25 16:55:18 -070055 queryset = ExampleService.objects.all()
Scott Baker619de672016-06-20 12:49:38 -070056 serializer_class = ExampleServiceSerializer
57
58 @classmethod
59 def get_urlpatterns(self, api_path="^"):
60 patterns = super(ExampleServiceViewSet, self).get_urlpatterns(api_path=api_path)
61
62 return patterns
63
64 def list(self, request):
65 object_list = self.filter_queryset(self.get_queryset())
66
67 serializer = self.get_serializer(object_list, many=True)
68
69 return Response(serializer.data)
70