Skip to content

Commit

Permalink
Remove remaining DRF imports and uninstall it (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandenburgh authored Aug 23, 2023
1 parent bc0d549 commit d60e8b9
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 217 deletions.
33 changes: 1 addition & 32 deletions django/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions django/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ packages = [
[tool.poetry.dependencies]
python = "~3.10.0"
django = ">=4.1,<4.2"
djangorestframework = "~3.13.1"
psycopg2 = "~2.9.3"
redis = { version = "~4.3.4", extras = [ "hiredis" ] }
uritemplate = "^4.1.1"
iso3166 = "^2.1.1"
rio-tiler = "^3.1.6"
mercantile = "^1.2.1"
django-filter = "^22.1"
django-ninja = "^0.21.0"
celery = "^5.2.7"
django-extensions = "^3.2.1"
Expand Down Expand Up @@ -84,7 +82,6 @@ plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"]

[[tool.mypy.overrides]]
module = [
"django_filters",
"mercantile"
]
ignore_missing_imports = true
Expand Down
16 changes: 0 additions & 16 deletions django/src/rdwatch/serializers/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions django/src/rdwatch/serializers/generics.py

This file was deleted.

7 changes: 0 additions & 7 deletions django/src/rdwatch/serializers/performer.py

This file was deleted.

26 changes: 0 additions & 26 deletions django/src/rdwatch/serializers/region.py

This file was deleted.

45 changes: 0 additions & 45 deletions django/src/rdwatch/serializers/site_evaluation.py

This file was deleted.

42 changes: 0 additions & 42 deletions django/src/rdwatch/serializers/site_image.py

This file was deleted.

10 changes: 1 addition & 9 deletions django/src/rdwatch/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def INSTALLED_APPS(self):
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.postgres',
'django_filters',
'rest_framework',
'django_extensions',
'rdwatch',
'django_celery_results',
Expand Down Expand Up @@ -97,14 +95,8 @@ def DATABASES(self):
db_dict.update(scoring_dict)
return db_dict

REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': ['rest_framework.renderers.JSONRenderer'],
'DEFAULT_PARSER_CLASSES': ['rest_framework.parsers.JSONParser'],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 25,
}

NINJA_PAGINATION_CLASS = 'ninja.pagination.PageNumberPagination'
NINJA_PAGINATION_PAGE_SIZE = 100

CACHES = {
'default': {
Expand Down
12 changes: 0 additions & 12 deletions django/src/rdwatch/urls.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
from django.urls import path
from rest_framework.renderers import CoreJSONRenderer
from rest_framework.schemas import get_schema_view

from rdwatch import views
from rdwatch.api import api

urlpatterns = [
path('', api.urls),
path(
'openapi.json',
get_schema_view(
title='RD-WATCH',
description='RD-WATCH API',
version='0.0.0dev0',
renderer_classes=[CoreJSONRenderer],
),
name='openapi-schema',
),
path('satellite-image/timestamps', views.satelliteimage_time_list),
path('satellite-image/all-timestamps', views.all_satellite_timestamps),
path(
Expand Down
2 changes: 1 addition & 1 deletion django/src/rdwatch/views/satellite_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
HttpResponsePermanentRedirect,
JsonResponse,
)
from django.urls import reverse
from django.views.decorators.cache import cache_page
from rest_framework.reverse import reverse

from rdwatch.models.lookups import Constellation
from rdwatch.utils.raster_tile import get_raster_bbox, get_raster_tile
Expand Down
11 changes: 8 additions & 3 deletions django/src/rdwatch/views/site_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import iso3166
from ninja import Field, FilterSchema, Query, Router, Schema

from django.conf import settings
from django.contrib.gis.db.models.aggregates import Collect
from django.contrib.gis.db.models.functions import Transform
from django.contrib.postgres.aggregates import JSONBAgg
Expand All @@ -15,7 +16,6 @@
from django.db.models.functions import JSONObject # type: ignore
from django.http import HttpRequest, HttpResponse
from django.shortcuts import get_object_or_404
from rest_framework.settings import api_settings

from rdwatch.db.functions import BoundingBox, ExtractEpoch
from rdwatch.models import SiteEvaluation, SiteEvaluationTracking, lookups
Expand Down Expand Up @@ -115,8 +115,13 @@ def list_site_evaluations(
)

# Pagination
assert api_settings.PAGE_SIZE, 'PAGE_SIZE must be set.'
limit = int(request.GET.get('limit', api_settings.PAGE_SIZE)) or sys.maxsize
assert (
settings.NINJA_PAGINATION_PAGE_SIZE
), 'NINJA_PAGINATION_PAGE_SIZE must be set.'
limit = (
int(request.GET.get('limit', settings.NINJA_PAGINATION_PAGE_SIZE))
or sys.maxsize
)
paginator = Paginator(queryset, limit)
page = paginator.page(request.GET.get('page', 1))

Expand Down
5 changes: 2 additions & 3 deletions django/src/rdwatch/views/site_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from django.core.files.storage import default_storage
from django.db.models import Count, F
from django.db.models.functions import JSONObject # type: ignore
from django.http import HttpRequest
from rest_framework.exceptions import NotFound
from django.http import Http404, HttpRequest

from rdwatch.db.functions import BoundingBox, ExtractEpoch
from rdwatch.models import SiteEvaluation, SiteImage, SiteObservation
Expand Down Expand Up @@ -57,7 +56,7 @@ class SiteImageResponse(Schema):
@router.get('/{id}/', response=SiteImageResponse)
def site_images(request: HttpRequest, id: int):
if not SiteEvaluation.objects.filter(pk=id).exists():
raise NotFound()
raise Http404()
else:
site_eval_obj = SiteEvaluation.objects.get(pk=id)
image_queryset = (
Expand Down
8 changes: 3 additions & 5 deletions django/src/rdwatch/views/site_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
from django.db import transaction
from django.db.models import Count, Max, Min
from django.db.models.functions import JSONObject # type: ignore
from django.http import HttpRequest
from django.http import Http404, HttpRequest
from django.shortcuts import get_object_or_404
from rest_framework import status
from rest_framework.exceptions import NotFound

from rdwatch.db.functions import BoundingBox, ExtractEpoch
from rdwatch.models import (
Expand Down Expand Up @@ -87,7 +85,7 @@ class SiteObservationsListSchema(Schema):
@router.get('/{evaluation_id}/', response={200: SiteObservationsListSchema})
def site_observations(request: HttpRequest, evaluation_id: int):
if not SiteEvaluation.objects.filter(pk=evaluation_id).exists():
raise NotFound()
raise Http404()
site_eval_data = SiteEvaluation.objects.filter(pk=evaluation_id).aggregate(
timerange=JSONObject(
min=ExtractEpoch(Min('start_date')),
Expand Down Expand Up @@ -193,7 +191,7 @@ def get_site_observation_images(
# If the task already exists and is running, return a 409 and do not
# start another one.
if fetching_task.status == SatelliteFetching.Status.RUNNING:
return status.HTTP_409_CONFLICT, 'Image generation already in progress.'
return 409, 'Image generation already in progress.'
# Otherwise, if the task exists but is *not* running, set the status
# to running and kick off the task
fetching_task.status = SatelliteFetching.Status.RUNNING
Expand Down

0 comments on commit d60e8b9

Please sign in to comment.