# Path: apps/api/serializers.py
# class PoiSerializer(serializers.ModelSerializer):
#     photos = PhotoItemSerializer(many=True, read_only=True)
#     region = serializers.CharField(read_only=True)
#     region_url = serializers.SerializerMethodField()
#     url = serializers.SerializerMethodField()
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
# 
#         context = kwargs.get('context', None)
#         if context:
#             self.request = kwargs['context']['request']
# 
#     def get_url(self, obj):
#         scheme = self.request.scheme
#         host = self.request.get_host()
#         return f"{scheme}://{host}#misto={obj.marker.layer.slug}_{obj.id}/"
# 
#     def get_region_url(self, obj):
#         scheme = self.request.scheme
#         host = self.request.get_host()
#         region = Poi.objects.get(name=obj.region)
#         return f"{scheme}://{host}#misto={region.marker.layer.slug}_{region.id}/"
# 
#     class Meta:
#         model = Poi
#         fields = (
#             'name', 'url', 'last_modification', 'region',
#             'region_url', 'photos',
#         )


from django.contrib.gis.db.models.functions import Intersection
from django.db.models import (
    F, OuterRef, Subquery,
)
from oauth2_provider.contrib.rest_framework import (
    IsAuthenticatedOrTokenHasScope, OAuth2Authentication,
)
from rest_framework import routers, viewsets
from rest_framework.authentication import SessionAuthentication
from cyklomapa.models import Poi
from .serializers import PoiSerializer




# Create your views here.


class PoiViewSet(viewsets.ReadOnlyModelViewSet):
    permission_classes = ()
    # authentication_classes = [SessionAuthentication, OAuth2Authentication]
    # permission_classes = [IsAuthenticatedOrTokenHasScope]
    # required_scopes = ['can_read_poi_closures']

    queryset = Poi.objects.filter(
        status__show=True, marker__slug='vyluka_akt',
    )

# Path: apps/api/serializers.py
# class PoiSerializer(serializers.ModelSerializer):
#     photos = PhotoItemSerializer(many=True, read_only=True)
#     region = serializers.CharField(read_only=True)
#     region_url = serializers.SerializerMethodField()
#     url = serializers.SerializerMethodField()
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
# 
#         context = kwargs.get('context', None)
#         if context:
#             self.request = kwargs['context']['request']
# 
#     def get_url(self, obj):
#         scheme = self.request.scheme
#         host = self.request.get_host()
#         return f"{scheme}://{host}#misto={obj.marker.layer.slug}_{obj.id}/"
# 
#     def get_region_url(self, obj):
#         scheme = self.request.scheme
#         host = self.request.get_host()
#         region = Poi.objects.get(name=obj.region)
#         return f"{scheme}://{host}#misto={region.marker.layer.slug}_{region.id}/"
# 
#     class Meta:
#         model = Poi
#         fields = (
#             'name', 'url', 'last_modification', 'region',
#             'region_url', 'photos',
#         )


# Path: apps/api/views.py
from django.contrib.gis.db.models.functions import Intersection
from django.db.models import (
    F, OuterRef, Subquery,
)
from oauth2_provider.contrib.rest_framework import (
    IsAuthenticatedOrTokenHasScope, OAuth2Authentication,
)
from rest_framework import routers, viewsets
from rest_framework.authentication import SessionAuthentication
from cyklomapa.models import Poi
from .serializers import PoiSerializer





# Create your views here.


class PoiViewSet(viewsets.ReadOnlyModelViewSet):
    permission_classes = ()
    # authentication_classes = [SessionAuthentication, OAuth2Authentication]
    # permission_classes = [IsAuthenticatedOrTokenHasScope]
    # required_scopes = ['can_read_poi_closures']

    queryset = Poi.objects.filter(
        status__show=True, marker__slug='vyluka_akt',
    )

    serializer_class = PoiSerializer