blob: 467a4bd771dbadefb8dcfb7dc1ccf14450ed3e9f [file] [log] [blame]
Scott Baker619de672016-06-20 12:49:38 -07001from rest_framework.decorators import api_view
2from rest_framework.response import Response
3from rest_framework.reverse import reverse
4from rest_framework import serializers
5from rest_framework import generics
6from rest_framework import viewsets
7from rest_framework import status
8from rest_framework.decorators import detail_route, list_route
9from rest_framework.views import APIView
10from core.models import *
11from django.forms import widgets
12from django.conf.urls import patterns, url
13from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
14from django.shortcuts import get_object_or_404
15from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
16from xos.exceptions import *
17import json
18import subprocess
19from services.exampleservice.models import ExampleService
20
21class ExampleServiceSerializer(PlusModelSerializer):
22 id = ReadOnlyField()
23 humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
24 service_message = serializers.CharField(required=False)
25
26 class Meta:
27 model = ExampleService
28 fields = ('humanReadableName',
29 'id',
30 'service_message')
31
32 def getHumanReadableName(self, obj):
33 return obj.__unicode__()
34
35class ExampleServiceViewSet(XOSViewSet):
36 base_name = "exampleservice"
37 method_name = "exampleservice"
38 method_kind = "viewset"
Scott Baker589e6c42017-05-25 16:55:18 -070039 queryset = ExampleService.objects.all()
Scott Baker619de672016-06-20 12:49:38 -070040 serializer_class = ExampleServiceSerializer
41
42 @classmethod
43 def get_urlpatterns(self, api_path="^"):
44 patterns = super(ExampleServiceViewSet, self).get_urlpatterns(api_path=api_path)
45
46 return patterns
47
48 def list(self, request):
49 object_list = self.filter_queryset(self.get_queryset())
50
51 serializer = self.get_serializer(object_list, many=True)
52
53 return Response(serializer.data)
54