|
133
|
1 |
''' |
|
|
2 |
field serializing and deserializing metacategorization protocols |
|
|
3 |
''' |
|
|
4 |
import logging |
|
|
5 |
|
|
|
6 |
from rest_framework import serializers |
|
|
7 |
|
|
|
8 |
logger = logging.getLogger(__name__) |
|
|
9 |
|
|
|
10 |
class ProtocolField(serializers.Field): |
|
|
11 |
|
|
|
12 |
def get_attribute(self, obj): |
|
|
13 |
logger.debug("ProtocolField.get_attribute %r", obj) |
|
|
14 |
# We pass the object instance onto `to_representation`, |
|
|
15 |
# not just the field attribute. |
|
|
16 |
return obj |
|
|
17 |
|
|
|
18 |
def to_representation(self, obj): |
|
|
19 |
logger.debug("ProtocolField.to_representation %r", obj) |
|
|
20 |
return { |
|
|
21 |
"id": "a4977c1f-4752-4aff-b724-eec4033af25c", |
|
|
22 |
"owner": "group1", |
|
|
23 |
"revision": "1", |
|
|
24 |
"description": "Cras rutrum lacinia pretium. Suspendisse justo est, tincidunt sed tellus a, sodales suscipit risus. Curabitur odio tortor, tincidunt sed est nec, ullamcorper sodales velit.", |
|
|
25 |
"metacategories": [{ |
|
|
26 |
"id": "e5712a76-857a-4769-b27e-a3ac3fb38b4d", |
|
|
27 |
"revision": 2, |
|
|
28 |
"base": "ef14bcce-52ac-44ba-a7d1-f1441bab94de", |
|
|
29 |
"name": "référence", |
|
|
30 |
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin massa nibh, hendrerit quis justo vitae, luctus tempor dolor. Nam quis fringilla diam.", |
|
|
31 |
"color": "#2cbfff", |
|
|
32 |
"has_comment": False |
|
|
33 |
}] |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
def to_internal_value(self, data): |
|
|
37 |
logger.debug("ProtocolField.to_internal_value %r", data) |
|
|
38 |
return "base protocol" |
|
|
39 |
|