Scott Baker | 619de67 | 2016-06-20 12:49:38 -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 rest_framework import viewsets |
| 7 | from rest_framework import status |
| 8 | from rest_framework.decorators import detail_route, list_route |
| 9 | from rest_framework.views import APIView |
| 10 | from core.models import * |
| 11 | from django.forms import widgets |
| 12 | from django.conf.urls import patterns, url |
| 13 | from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField |
| 14 | from django.shortcuts import get_object_or_404 |
| 15 | from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied |
| 16 | from xos.exceptions import * |
| 17 | import json |
| 18 | import subprocess |
| 19 | from services.exampleservice.models import ExampleService |
| 20 | |
| 21 | class 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 | |
| 35 | class ExampleServiceViewSet(XOSViewSet): |
| 36 | base_name = "exampleservice" |
| 37 | method_name = "exampleservice" |
| 38 | method_kind = "viewset" |
Scott Baker | 589e6c4 | 2017-05-25 16:55:18 -0700 | [diff] [blame] | 39 | queryset = ExampleService.objects.all() |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 40 | 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 | |