Scott Baker | dcf6fbf | 2015-01-11 13:45:19 -0800 | [diff] [blame] | 1 | from rest_framework import generics |
Scott Baker | e791dc6 | 2014-08-28 14:02:54 -0700 | [diff] [blame] | 2 | from rest_framework import serializers |
Scott Baker | dcf6fbf | 2015-01-11 13:45:19 -0800 | [diff] [blame] | 3 | from rest_framework.response import Response |
| 4 | from rest_framework import status |
Scott Baker | 8974e55 | 2015-02-10 19:26:00 -0800 | [diff] [blame] | 5 | from xosapibase import XOSRetrieveUpdateDestroyAPIView, XOSListCreateAPIView |
Scott Baker | e791dc6 | 2014-08-28 14:02:54 -0700 | [diff] [blame] | 6 | |
| 7 | """ PlusSerializerMixin |
| 8 | |
| 9 | Implements Serializer fields that are common to all OpenCloud objects. For |
| 10 | example, stuff related to backend fields. |
| 11 | """ |
| 12 |
|
| 13 | class PlusSerializerMixin(): |
| 14 | backendIcon = serializers.SerializerMethodField("getBackendIcon") |
| 15 | backendHtml = serializers.SerializerMethodField("getBackendHtml") |
| 16 | |
| 17 | # This will cause a descendant class to pull in the methods defined |
| 18 | # above. See rest_framework/serializers.py: _get_declared_fields(). |
| 19 | base_fields = {"backendIcon": backendIcon, "backendHtml": backendHtml} |
Scott Baker | a4ac3a8 | 2014-12-23 11:04:27 -0800 | [diff] [blame] | 20 | # Rest_framework 3.0 uses _declared_fields instead of base_fields |
| 21 | _declared_fields = {"backendIcon": backendIcon, "backendHtml": backendHtml} |
Scott Baker | e791dc6 | 2014-08-28 14:02:54 -0700 | [diff] [blame] | 22 | |
| 23 | def getBackendIcon(self, obj): |
| 24 | return obj.getBackendIcon() |
| 25 | |
| 26 | def getBackendHtml(self, obj): |
| 27 | return obj.getBackendHtml() |
| 28 | |
Scott Baker | cba0ffe | 2015-02-03 15:02:17 -0800 | [diff] [blame] | 29 | |
Scott Baker | cba0ffe | 2015-02-03 15:02:17 -0800 | [diff] [blame] | 30 | |
Scott Baker | bbc8a5b | 2015-01-12 12:57:22 -0800 | [diff] [blame] | 31 | |
Scott Baker | dcf6fbf | 2015-01-11 13:45:19 -0800 | [diff] [blame] | 32 | |