diff --git a/core/settings.py b/core/settings.py index f00626d0..6bc8cbb1 100644 --- a/core/settings.py +++ b/core/settings.py @@ -49,7 +49,6 @@ "django.contrib.messages", "django.contrib.staticfiles", "corsheaders", - "django_filters", "drf_spectacular", "rest_framework", "process.apps.ProcessConfig", @@ -222,7 +221,6 @@ CORS_EXPOSE_HEADERS = ["Content-Disposition"] REST_FRAMEWORK = { - "DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"], "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", } diff --git a/process/views.py b/process/views.py index 30dada2e..873fadd0 100644 --- a/process/views.py +++ b/process/views.py @@ -1,64 +1,22 @@ import logging from django.db import connection, transaction -from django.db.models import Case, Count, IntegerField, When from django.db.models.functions import Now from django.http.response import Http404 from django.shortcuts import get_object_or_404 -from django_filters.rest_framework import DjangoFilterBackend from rest_framework import serializers, status, viewsets from rest_framework.decorators import action -from rest_framework.generics import ListAPIView, RetrieveAPIView +from rest_framework.generics import RetrieveAPIView from rest_framework.response import Response from core import settings -from process.models import Collection, CollectionNote, ProcessingStep +from process.models import Collection, CollectionNote from process.processors.loader import create_collections from process.util import create_note, get_publisher logger = logging.getLogger(__name__) -class CollectionSerializer(serializers.ModelSerializer): - steps_remaining_LOAD = serializers.SerializerMethodField() - steps_remaining_COMPILE = serializers.SerializerMethodField() - steps_remaining_CHECK = serializers.SerializerMethodField() - - def get_steps_remaining_LOAD(self, obj) -> int: - return obj.steps_remaining_LOAD - - def get_steps_remaining_COMPILE(self, obj) -> int: - return obj.steps_remaining_COMPILE - - def get_steps_remaining_CHECK(self, obj) -> int: - return obj.steps_remaining_CHECK - - class Meta: - model = Collection - fields = [ - "source_id", - "data_version", - "sample", - "steps", - "options", - "expected_files_count", - "compilation_started", - "parent", - "transform_type", - "data_type", - "cached_releases_count", - "cached_records_count", - "cached_compiled_releases_count", - "store_start_at", - "store_end_at", - "deleted_at", - "completed_at", - "steps_remaining_LOAD", - "steps_remaining_COMPILE", - "steps_remaining_CHECK", - ] - - class CreateCollectionSerializer(serializers.Serializer): source_id = serializers.CharField(help_text="The spider name from Kingfisher Collect") data_version = serializers.CharField(help_text="The date when the collection's data was downloaded") @@ -77,45 +35,7 @@ class CloseCollectionSerializer(serializers.Serializer): reason = serializers.CharField(help_text="The reason the crawl was finished", required=False) -class CollectionViewSet(viewsets.ViewSet, ListAPIView): - queryset = ( - Collection.objects.annotate( - steps_remaining_LOAD=Count( - Case( - When(processing_steps__name=ProcessingStep.Name.LOAD, then=1), - output_field=IntegerField(), - ) - ) - ) - .annotate( - steps_remaining_COMPILE=Count( - Case( - When(processing_steps__name=ProcessingStep.Name.COMPILE, then=1), - output_field=IntegerField(), - ) - ) - ) - .annotate( - steps_remaining_CHECK=Count( - Case( - When(processing_steps__name=ProcessingStep.Name.CHECK, then=1), - output_field=IntegerField(), - ) - ) - ) - ) - - serializer_class = CollectionSerializer - filter_backends = [DjangoFilterBackend] - filterset_fields = [ - "source_id", - "data_version", - "store_start_at", - "store_end_at", - "transform_type", - "completed_at", - ] - +class CollectionViewSet(viewsets.ViewSet): def create(self, request): serializer = CreateCollectionSerializer(data=request.data) serializer.is_valid(raise_exception=True) @@ -277,7 +197,7 @@ def retrieve(self, request, pk=None): JOIN collection c on (t.id = c.id) WHERE t.root = %s ORDER BY deep ASC; - """, + """, [pk], ) diff --git a/requirements.txt b/requirements.txt index 9b652ee8..3fc7b4fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,13 +47,10 @@ django==4.2.11 # -r requirements_nongpl.txt # dj-database-url # django-cors-headers - # django-filter # djangorestframework # drf-spectacular django-cors-headers==4.1.0 # via -r requirements_nongpl.txt -django-filter==24.2 - # via -r requirements_nongpl.txt djangorestframework==3.15.1 # via # -r requirements_nongpl.txt diff --git a/requirements_dev.txt b/requirements_dev.txt index b724fc13..3c1e6831 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -75,13 +75,10 @@ django==4.2.11 # -r requirements.txt # dj-database-url # django-cors-headers - # django-filter # djangorestframework # drf-spectacular django-cors-headers==4.1.0 # via -r requirements.txt -django-filter==24.2 - # via -r requirements.txt djangorestframework==3.15.1 # via # -r requirements.txt diff --git a/requirements_nongpl.in b/requirements_nongpl.in index 19de24cb..d884808f 100644 --- a/requirements_nongpl.in +++ b/requirements_nongpl.in @@ -1,6 +1,5 @@ dj-database-url django-cors-headers -django-filter Django<5 djangorestframework drf-spectacular diff --git a/requirements_nongpl.txt b/requirements_nongpl.txt index 2716312c..b682c492 100644 --- a/requirements_nongpl.txt +++ b/requirements_nongpl.txt @@ -27,13 +27,10 @@ django==4.2.11 # -r requirements_nongpl.in # dj-database-url # django-cors-headers - # django-filter # djangorestframework # drf-spectacular django-cors-headers==4.1.0 # via -r requirements_nongpl.in -django-filter==24.2 - # via -r requirements_nongpl.in djangorestframework==3.15.1 # via # -r requirements_nongpl.in diff --git a/tests/test_views.py b/tests/test_views.py index 01e2ac77..0371c512 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -23,11 +23,6 @@ def test_redoc(self): self.assertEqual(response.status_code, 200) - def test_collection_list_ok(self): - response = self.client.get(f"{base_url}/?format=json") - self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.data), 3) - def test_collection_metadata_404(self): response = self.client.get(f"{base_url}/900/metadata/?format=json") self.assertEqual(response.status_code, 404)