src/notes/api/fields/category.py
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--
provide a realistic default protocol

'''
field serializing and deserializing metacategorization protocols
'''
import logging

from notes import settings
from rest_framework import serializers

logger = logging.getLogger(__name__)

class ProtocolField(serializers.Field):

    def get_attribute(self, obj):
        logger.debug("ProtocolField.get_attribute %r", obj)
        # We pass the object instance onto `to_representation`,
        # not just the field attribute.
        return obj

    def to_representation(self, obj):
        logger.debug("ProtocolField.to_representation %r", obj)
        return settings.NOTES_SETTINGS['PROTOCOL']

    def to_internal_value(self, data):
        logger.debug("ProtocolField.to_internal_value %r", data)
        return "base protocol"