src/notes/api/fields/category.py
author ymh <ymh.work@gmail.com>
Tue, 10 Jul 2018 15:18:03 +0200
changeset 141 cd5e8fb64b74
parent 139 d3738ac909d8
child 142 56850f5c73f6
permissions -rw-r--r--
Add design Gemfiles

'''
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"