# Path: electionleaflets/apps/api/serializers.py
# class ConstituencySerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#         model = Constituency
#         fields = (
#             'name',
#         )
# 
# class PartySerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#         model = Party
#         fields = (
#             'pk',
#             'party_name',
#             'party_type',
#             'status',
#         )
# 
# class LeafletSerializer(serializers.HyperlinkedModelSerializer):
#     # images = LeafletImageSerializer(many=True, required=False)
#     # constituency = ConstituencySerializer(many=True, required=False)
#     # publisher_party = PartySerializer(required=False)
# 
#     def validate(self, data):
#         if not data.get('status') or not data.get('images'):
#             data['status'] = 'draft'
#         return data
# 
# 
# 
#     class Meta:
#         model = Leaflet
#         depth = 1
#         fields = (
#             'pk',
#             'title',
#             'description',
#             'publisher_party',
#             'constituency',
#             'images',
#             'date_uploaded',
#             'date_delivered',
#             'status',
#         )
# 
# class LeafletImageSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = LeafletImage
#         fields = (
#             'leaflet',
#             'image',
#         )
#     image = serializers.ImageField()


from django.http import HttpResponse
from django.contrib.sites.models import Site
from django.utils.html import escape
from leaflets.models import Leaflet, LeafletImage
from constituencies.models import Constituency
from uk_political_parties.models import Party
from rest_framework import viewsets
from .serializers import (ConstituencySerializer, PartySerializer,
    LeafletSerializer, LeafletImageSerializer)
    from leaflets.models import Leaflet





class ConstituencyViewSet(viewsets.ModelViewSet):
    queryset = Constituency.objects.all()
    serializer_class = ConstituencySerializer


class PartyViewSet(viewsets.ModelViewSet):
    queryset = Party.objects.all()
    serializer_class = PartySerializer


class LeafletImageViewSet(viewsets.ModelViewSet):
    queryset = LeafletImage.objects.all()

# Path: electionleaflets/apps/api/serializers.py
# class ConstituencySerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#         model = Constituency
#         fields = (
#             'name',
#         )
# 
# class PartySerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#         model = Party
#         fields = (
#             'pk',
#             'party_name',
#             'party_type',
#             'status',
#         )
# 
# class LeafletSerializer(serializers.HyperlinkedModelSerializer):
#     # images = LeafletImageSerializer(many=True, required=False)
#     # constituency = ConstituencySerializer(many=True, required=False)
#     # publisher_party = PartySerializer(required=False)
# 
#     def validate(self, data):
#         if not data.get('status') or not data.get('images'):
#             data['status'] = 'draft'
#         return data
# 
# 
# 
#     class Meta:
#         model = Leaflet
#         depth = 1
#         fields = (
#             'pk',
#             'title',
#             'description',
#             'publisher_party',
#             'constituency',
#             'images',
#             'date_uploaded',
#             'date_delivered',
#             'status',
#         )
# 
# class LeafletImageSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = LeafletImage
#         fields = (
#             'leaflet',
#             'image',
#         )
#     image = serializers.ImageField()


# Path: electionleaflets/apps/api/views.py
from django.http import HttpResponse
from django.contrib.sites.models import Site
from django.utils.html import escape
from leaflets.models import Leaflet, LeafletImage
from constituencies.models import Constituency
from uk_political_parties.models import Party
from rest_framework import viewsets
from .serializers import (ConstituencySerializer, PartySerializer,
    LeafletSerializer, LeafletImageSerializer)
    from leaflets.models import Leaflet






class ConstituencyViewSet(viewsets.ModelViewSet):
    queryset = Constituency.objects.all()
    serializer_class = ConstituencySerializer


class PartyViewSet(viewsets.ModelViewSet):
    queryset = Party.objects.all()
    serializer_class = PartySerializer


class LeafletImageViewSet(viewsets.ModelViewSet):
    queryset = LeafletImage.objects.all()

    serializer_class = LeafletImageSerializer