<filename>changes/api/serializer/models/source.py
from __future__ import absolute_import

from changes.api.serializer import Crumbler, register
from changes.models import Source


@register(Source)
class SourceCrumbler(Crumbler):
    def crumble(self, instance, attrs):
        if instance.patch_id:
            if instance.data.get('phabricator.revisionURL'):
                external = {
                    'link': instance.data['phabricator.revisionURL'],
                    'label': 'D{}'.format(instance.data['phabricator.revisionID']),
                }
            else:
                external = None

            patch = {
                'id': instance.patch_id.hex,
                'external': external,
            }
        else:
            patch = None

        return {
            'id': instance.id.hex,
            'patch': patch,
            'revision': instance.revision,
            'isCommit': instance.is_commit(),
            'dateCreated': instance.date_created,
            'data': dict(instance.data or {}),
        }

<filename>changes/api/serializer/models/source.py
from __future__ import absolute_import

from changes.api.serializer import Crumbler, register
from changes.models import Source


@register(Source)
class SourceCrumbler(Crumbler):
    def crumble(self, instance, attrs):
        if instance.patch_id:
            if instance.data.get('phabricator.revisionURL'):
                external = {
                    'link': instance.data['phabricator.revisionURL'],
                    'label': 'D{}'.format(instance.data['phabricator.revisionID']),
                }
            else:
                external = None

            patch = {
                'id': instance.patch_id.hex,
                'external': external,
            }
        else:
            patch = None

        return {
            'id': instance.id.hex,
            'patch': patch,
            'revision': instance.revision,
            'isCommit': instance.is_commit(),
            'dateCreated': instance.date_created,
            'data': dict(instance.data or {}),
        }
