Skip to content

Commit

Permalink
feat: Remove django-filter and list view. Unclear why it was added in 1…
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Apr 19, 2024
1 parent e3e1293 commit 20a827b
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 101 deletions.
2 changes: 0 additions & 2 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"corsheaders",
"django_filters",
"drf_spectacular",
"rest_framework",
"process.apps.ProcessConfig",
Expand Down Expand Up @@ -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",
}

Expand Down
88 changes: 4 additions & 84 deletions process/views.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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],
)

Expand Down
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion requirements_nongpl.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dj-database-url
django-cors-headers
django-filter
Django<5
djangorestframework
drf-spectacular
Expand Down
3 changes: 0 additions & 3 deletions requirements_nongpl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 20a827b

Please sign in to comment.