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