# Path: authors/serializers.py
# class OrganizationSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
# class PositionSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
# class JobSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
# class AuthorSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#     def get_is_current(self, obj):
#     def __init__(self, *args, **kwargs):


from rest_framework import serializers
from rest_framework.reverse import reverse
from django.contrib.contenttypes.models import ContentType
from authors import serializers as authors_serializers
from . import models
class MediaSerializer(serializers.HyperlinkedModelSerializer):
    credit = authors_serializers.AuthorSerializer(many=True)
    is_courtesy = serializers.SerializerMethodField()

    def get_is_courtesy(self, obj):
        return obj.is_courtesy()


class ImageSerializer(MediaSerializer):
    resized = serializers.SerializerMethodField()
    art_request = serializers.SerializerMethodField()

    class Meta:
        model = models.Image
        exclude = ('content_type', 'object_id')

    def get_resized(self, obj):
        """Provides the ability to specify optional resolution and crop
        parameters to return a URL to a resized version."""

        request = self.context['request']
        resolution = request.GET.get('resolution')
        crop = request.GET.get('crop')
        if resolution and crop:
            path =  obj.get_image_at_resolution(resolution, crop=crop)
        elif resolution:
            path = obj.get_image_at_resolution(resolution)
        else:
            return None
        # return an absolute link, including protocol, hostname, and path

# Path: authors/serializers.py
# class OrganizationSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
# class PositionSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
# class JobSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
# class AuthorSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#     def get_is_current(self, obj):
#     def __init__(self, *args, **kwargs):


# Path: attachments/serializers.py
from rest_framework import serializers
from rest_framework.reverse import reverse
from django.contrib.contenttypes.models import ContentType
from authors import serializers as authors_serializers
from . import models

class MediaSerializer(serializers.HyperlinkedModelSerializer):
    credit = authors_serializers.AuthorSerializer(many=True)
    is_courtesy = serializers.SerializerMethodField()

    def get_is_courtesy(self, obj):
        return obj.is_courtesy()


class ImageSerializer(MediaSerializer):
    resized = serializers.SerializerMethodField()
    art_request = serializers.SerializerMethodField()

    class Meta:
        model = models.Image
        exclude = ('content_type', 'object_id')

    def get_resized(self, obj):
        """Provides the ability to specify optional resolution and crop
        parameters to return a URL to a resized version."""

        request = self.context['request']
        resolution = request.GET.get('resolution')
        crop = request.GET.get('crop')
        if resolution and crop:
            path =  obj.get_image_at_resolution(resolution, crop=crop)
        elif resolution:
            path = obj.get_image_at_resolution(resolution)
        else:
            return None
        # return an absolute link, including protocol, hostname, and path

        return request.build_absolute_uri(path)