| author | ymh <ymh.work@gmail.com> |
| Fri, 04 Aug 2017 10:46:17 +0200 | |
| changeset 139 | d3738ac909d8 |
| parent 133 | 6f3078f7fd47 |
| child 142 | 56850f5c73f6 |
| permissions | -rw-r--r-- |
| 133 | 1 |
''' |
2 |
field serializing and deserializing metacategorization protocols |
|
3 |
''' |
|
4 |
import logging |
|
5 |
||
|
139
d3738ac909d8
provide a realistic default protocol
ymh <ymh.work@gmail.com>
parents:
133
diff
changeset
|
6 |
from notes import settings |
| 133 | 7 |
from rest_framework import serializers |
8 |
||
9 |
logger = logging.getLogger(__name__) |
|
10 |
||
11 |
class ProtocolField(serializers.Field): |
|
12 |
||
13 |
def get_attribute(self, obj): |
|
14 |
logger.debug("ProtocolField.get_attribute %r", obj) |
|
15 |
# We pass the object instance onto `to_representation`, |
|
16 |
# not just the field attribute. |
|
17 |
return obj |
|
18 |
||
19 |
def to_representation(self, obj): |
|
20 |
logger.debug("ProtocolField.to_representation %r", obj) |
|
|
139
d3738ac909d8
provide a realistic default protocol
ymh <ymh.work@gmail.com>
parents:
133
diff
changeset
|
21 |
return settings.NOTES_SETTINGS['PROTOCOL'] |
| 133 | 22 |
|
23 |
def to_internal_value(self, data): |
|
24 |
logger.debug("ProtocolField.to_internal_value %r", data) |
|
25 |
return "base protocol" |
|
26 |