<commit_before>import json

from django.http import HttpResponse
from rest_framework import viewsets

from osmaxx.api_client import ConversionApiClient
from osmaxx.contrib.auth.frontend_permissions import AuthenticatedAndAccessPermission, HasExcerptAccessPermission
from osmaxx.excerptexport.models import Excerpt
from osmaxx.excerptexport.rest_api.serializers import ExcerptGeometrySerializer


class ExcerptViewSet(viewsets.mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    permission_classes = (
        HasExcerptAccessPermission,
        AuthenticatedAndAccessPermission,
    )
    queryset = Excerpt.objects.all()
    serializer_class = ExcerptGeometrySerializer
excerpt_detail = ExcerptViewSet.as_view({'get': 'retrieve'})


def estimated_file_size(request):
    bbox = {bound: request.GET[bound] for bound in ['north', 'east', 'west', 'south']}
    client = ConversionApiClient()
    response_content = json.dumps(client.estimated_file_size(**bbox))
    return HttpResponse(response_content, content_type="application/json")<commit_msg>use etags so browsers do not refetch existing geometries<commit_after>import json

from django.http import HttpResponse
from rest_framework import viewsets
from rest_framework_extensions.etag.mixins import ETAGMixin

from osmaxx.api_client import ConversionApiClient
from osmaxx.contrib.auth.frontend_permissions import AuthenticatedAndAccessPermission, HasExcerptAccessPermission
from osmaxx.excerptexport.models import Excerpt
from osmaxx.excerptexport.rest_api.serializers import ExcerptGeometrySerializer


class ExcerptViewSet(ETAGMixin, viewsets.mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    permission_classes = (
        HasExcerptAccessPermission,
        AuthenticatedAndAccessPermission,
    )
    queryset = Excerpt.objects.all()
    serializer_class = ExcerptGeometrySerializer
excerpt_detail = ExcerptViewSet.as_view({'get': 'retrieve'})


def estimated_file_size(request):
    bbox = {bound: request.GET[bound] for bound in ['north', 'east', 'west', 'south']}
    client = ConversionApiClient()
    response_content = json.dumps(client.estimated_file_size(**bbox))
    return HttpResponse(response_content, content_type="application/json")
{'fraction_non_alphanumeric': 0.07806859205776173, 'fraction_numerical': 0.0, 'mean_word_length': 6.439597315436242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2257036', 'n_tokens_mistral': 665, 'n_tokens_neox': 625, 'n_words': 130}