From cb9bd581ce4c206ecb285c819752bad9e3d541ec Mon Sep 17 00:00:00 2001 From: Grant Ramsay Date: Wed, 15 May 2024 11:36:36 +0100 Subject: [PATCH] remove a lot of the django stuff Signed-off-by: Grant Ramsay --- uprn_mangle/{backend/api => }/__init__.py | 0 uprn_mangle/backend/api/admin.py | 3 - uprn_mangle/backend/api/apps.py | 5 - .../backend/api/management/__init__.py | 0 .../api/management/support/__init__.py | 0 .../backend/api/migrations/0001_initial.py | 160 ------------------ .../backend/api/migrations/__init__.py | 0 uprn_mangle/backend/api/serializers.py | 19 --- uprn_mangle/backend/api/tests.py | 3 - uprn_mangle/backend/api/urls.py | 11 -- uprn_mangle/backend/api/views.py | 35 ---- uprn_mangle/backend/backend/__init__.py | 0 uprn_mangle/backend/backend/asgi.py | 16 -- uprn_mangle/backend/backend/settings.py | 152 ----------------- uprn_mangle/backend/backend/urls.py | 7 - uprn_mangle/backend/backend/wsgi.py | 16 -- .../{api/management/support => }/constants.py | 1 + .../management/commands => }/import_uprn.py | 3 +- uprn_mangle/backend/manage.py | 22 --- .../backend/{api/models.py => old_models.py} | 4 +- 20 files changed, 4 insertions(+), 453 deletions(-) rename uprn_mangle/{backend/api => }/__init__.py (100%) delete mode 100644 uprn_mangle/backend/api/admin.py delete mode 100644 uprn_mangle/backend/api/apps.py delete mode 100644 uprn_mangle/backend/api/management/__init__.py delete mode 100644 uprn_mangle/backend/api/management/support/__init__.py delete mode 100644 uprn_mangle/backend/api/migrations/0001_initial.py delete mode 100644 uprn_mangle/backend/api/migrations/__init__.py delete mode 100644 uprn_mangle/backend/api/serializers.py delete mode 100644 uprn_mangle/backend/api/tests.py delete mode 100644 uprn_mangle/backend/api/urls.py delete mode 100644 uprn_mangle/backend/api/views.py delete mode 100644 uprn_mangle/backend/backend/__init__.py delete mode 100644 uprn_mangle/backend/backend/asgi.py delete mode 100644 uprn_mangle/backend/backend/settings.py delete mode 100644 uprn_mangle/backend/backend/urls.py delete mode 100644 uprn_mangle/backend/backend/wsgi.py rename uprn_mangle/backend/{api/management/support => }/constants.py (99%) rename uprn_mangle/backend/{api/management/commands => }/import_uprn.py (99%) delete mode 100755 uprn_mangle/backend/manage.py rename uprn_mangle/backend/{api/models.py => old_models.py} (95%) diff --git a/uprn_mangle/backend/api/__init__.py b/uprn_mangle/__init__.py similarity index 100% rename from uprn_mangle/backend/api/__init__.py rename to uprn_mangle/__init__.py diff --git a/uprn_mangle/backend/api/admin.py b/uprn_mangle/backend/api/admin.py deleted file mode 100644 index 45996fdc..00000000 --- a/uprn_mangle/backend/api/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin # noqa F401 - -# Register your models here. diff --git a/uprn_mangle/backend/api/apps.py b/uprn_mangle/backend/api/apps.py deleted file mode 100644 index d87006dd..00000000 --- a/uprn_mangle/backend/api/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class ApiConfig(AppConfig): - name = 'api' diff --git a/uprn_mangle/backend/api/management/__init__.py b/uprn_mangle/backend/api/management/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/uprn_mangle/backend/api/management/support/__init__.py b/uprn_mangle/backend/api/management/support/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/uprn_mangle/backend/api/migrations/0001_initial.py b/uprn_mangle/backend/api/migrations/0001_initial.py deleted file mode 100644 index e2e564e6..00000000 --- a/uprn_mangle/backend/api/migrations/0001_initial.py +++ /dev/null @@ -1,160 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 12:00 - -import django.contrib.postgres.indexes -import django.contrib.postgres.search -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [] - - operations = [ - migrations.CreateModel( - name="Addressbase", - fields=[ - ( - "uprn", - models.BigIntegerField( - db_column="UPRN", primary_key=True, serialize=False - ), - ), - ( - "full_address", - models.TextField( - blank=True, db_column="FULL_ADDRESS", null=True - ), - ), - ( - "sub_building_name", - models.TextField( - blank=True, db_column="SUB_BUILDING_NAME", null=True - ), - ), - ( - "building_name", - models.TextField( - blank=True, db_column="BUILDING_NAME", null=True - ), - ), - ( - "building_number", - models.TextField( - blank=True, db_column="BUILDING_NUMBER", null=True - ), - ), - ( - "thoroughfare", - models.TextField( - blank=True, db_column="THOROUGHFARE", null=True - ), - ), - ( - "post_town", - models.TextField( - blank=True, db_column="POST_TOWN", null=True - ), - ), - ( - "postcode", - models.TextField( - blank=True, db_column="POSTCODE", null=True - ), - ), - ( - "logical_status", - models.BigIntegerField( - blank=True, db_column="LOGICAL_STATUS", null=True - ), - ), - ( - "blpu_state", - models.TextField( - blank=True, db_column="BLPU_STATE", null=True - ), - ), - ( - "x_coordinate", - models.FloatField( - blank=True, db_column="X_COORDINATE", null=True - ), - ), - ( - "y_coordinate", - models.FloatField( - blank=True, db_column="Y_COORDINATE", null=True - ), - ), - ( - "latitude", - models.FloatField( - blank=True, db_column="LATITUDE", null=True - ), - ), - ( - "longitude", - models.FloatField( - blank=True, db_column="LONGITUDE", null=True - ), - ), - ( - "country", - models.TextField( - blank=True, db_column="COUNTRY", null=True - ), - ), - ( - "classification_code", - models.TextField( - blank=True, db_column="CLASSIFICATION_CODE", null=True - ), - ), - ( - "usrn", - models.TextField(blank=True, db_column="USRN", null=True), - ), - ( - "street_description", - models.TextField( - blank=True, db_column="STREET_DESCRIPTION", null=True - ), - ), - ( - "locality", - models.TextField( - blank=True, db_column="LOCALITY", null=True - ), - ), - ( - "town_name", - models.TextField( - blank=True, db_column="TOWN_NAME", null=True - ), - ), - ( - "administrative_area", - models.TextField( - blank=True, db_column="ADMINISTRATIVE_AREA", null=True - ), - ), - ( - "tsv", - django.contrib.postgres.search.SearchVectorField( - null=True - ), - ), - ], - options={ - "db_table": "addressbase", - "managed": True, - }, - ), - migrations.AddIndex( - model_name="addressbase", - index=django.contrib.postgres.indexes.GinIndex( - fields=["tsv"], name="addressbase_tsv_3d0d16_gin" - ), - ), - ] diff --git a/uprn_mangle/backend/api/migrations/__init__.py b/uprn_mangle/backend/api/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/uprn_mangle/backend/api/serializers.py b/uprn_mangle/backend/api/serializers.py deleted file mode 100644 index 2e24a084..00000000 --- a/uprn_mangle/backend/api/serializers.py +++ /dev/null @@ -1,19 +0,0 @@ -from rest_framework import serializers - -from .models import Addressbase - - -class AddressbaseSerializer(serializers.ModelSerializer): - class Meta: - model = Addressbase - fields = [ - "uprn", - "full_address", - "x_coordinate", - "y_coordinate", - "latitude", - "longitude", - "country", - "classification_code", - "street_description", - ] diff --git a/uprn_mangle/backend/api/tests.py b/uprn_mangle/backend/api/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/uprn_mangle/backend/api/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/uprn_mangle/backend/api/urls.py b/uprn_mangle/backend/api/urls.py deleted file mode 100644 index ec35eaf4..00000000 --- a/uprn_mangle/backend/api/urls.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.urls import path, include -from rest_framework import routers - -from . import views - -router = routers.DefaultRouter() -router.register(r"search", views.SearchViewSet, basename="search") - -urlpatterns = [ - path("v1/", include(router.urls)), -] diff --git a/uprn_mangle/backend/api/views.py b/uprn_mangle/backend/api/views.py deleted file mode 100644 index 18253756..00000000 --- a/uprn_mangle/backend/api/views.py +++ /dev/null @@ -1,35 +0,0 @@ -from rest_framework import viewsets - -from .models import Addressbase -from .serializers import AddressbaseSerializer - - -class SearchViewSet(viewsets.ModelViewSet): - # queryset = Addressbase.objects.all().order_by("uprn")[:10] - serializer_class = AddressbaseSerializer - - def get_queryset(self): - # This search is very fast, using the Postgresql Full-Text-Search and - # pre-computed ts_vectors from the 'tsv' column. These were manually - # added. We need to add this to the import scripts. This will not be - # needed to be implemented for real-time since the database is static. - - srch_param = self.request.query_params.get("q") - # get the requested sort order, default to uprn if not specified. - sort_order = self.request.query_params.get("order", "uprn") - - print(sort_order) - - # queryset = Addressbase.objects.all().order_by("uprn")[:20] - - if srch_param: - # queryset = Addressbase.objects.filter( - # full_address__search=srch_param - # ).order_by("uprn") - queryset = Addressbase.objects.filter(tsv=srch_param).order_by( - sort_order - ) - else: - queryset = Addressbase.objects.all().order_by(sort_order) - - return queryset diff --git a/uprn_mangle/backend/backend/__init__.py b/uprn_mangle/backend/backend/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/uprn_mangle/backend/backend/asgi.py b/uprn_mangle/backend/backend/asgi.py deleted file mode 100644 index 6dcedac7..00000000 --- a/uprn_mangle/backend/backend/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for backend project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') - -application = get_asgi_application() diff --git a/uprn_mangle/backend/backend/settings.py b/uprn_mangle/backend/backend/settings.py deleted file mode 100644 index 16e1e7c6..00000000 --- a/uprn_mangle/backend/backend/settings.py +++ /dev/null @@ -1,152 +0,0 @@ -""" -Django settings for backend project. - -Generated by 'django-admin startproject' using Django 3.1.7. - -For more information on this file, see -https://docs.djangoproject.com/en/3.1/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.1/ref/settings/ -""" - -import os -from pathlib import Path - -from dotenv import load_dotenv - -load_dotenv(override=True) # loads the configs from .env - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = str(os.getenv("SECRET_KEY")) - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = bool(int(os.getenv("DEBUG", 0))) - -ALLOWED_HOSTS = ["127.0.0.1", "localhost"] - - -# Application definition - -INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "django.contrib.postgres", - "rest_framework", - "api", -] - -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - "django.middleware.clickjacking.XFrameOptionsMiddleware", -] - -REST_FRAMEWORK = { - "DEFAULT_RENDERER_CLASSES": [ - "rest_framework.renderers.JSONRenderer", - ], - "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", # noqa: E501 - "PAGE_SIZE": 20, -} - -ROOT_URLCONF = "backend.urls" - -TEMPLATES = [ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], - "APP_DIRS": True, - "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", - ], - }, - }, -] - -WSGI_APPLICATION = "backend.wsgi.application" - - -# Database -# https://docs.djangoproject.com/en/3.1/ref/settings/#databases - -# DATABASES = { -# "default": { -# "ENGINE": "django.db.backends.sqlite3", -# "NAME": BASE_DIR / "db.sqlite3", -# } -# } - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": str(os.getenv("UPRN_DB_NAME")), - "USER": str(os.getenv("UPRN_DB_USER")), - "PASSWORD": str(os.getenv("UPRN_DB_PASSWORD")), - "HOST": str(os.getenv("UPRN_DB_HOST")), - "PORT": str(os.getenv("UPRN_DB_PORT")), - } -} - -# Password validation -# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501 - }, - { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", # noqa: E501 - }, - { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", # noqa: E501 - }, - { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", # noqa: E501 - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/3.1/topics/i18n/ - -LANGUAGE_CODE = "en-gb" - -TIME_ZONE = "UTC" - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.1/howto/static-files/ - -STATIC_URL = "static/" -STATIC_ROOT = "static" - -# Default primary key field type -# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/uprn_mangle/backend/backend/urls.py b/uprn_mangle/backend/backend/urls.py deleted file mode 100644 index ecdc8d98..00000000 --- a/uprn_mangle/backend/backend/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.contrib import admin -from django.urls import path, include - -urlpatterns = [ - path("admin/", admin.site.urls), - path("api/", include("api.urls")), -] diff --git a/uprn_mangle/backend/backend/wsgi.py b/uprn_mangle/backend/backend/wsgi.py deleted file mode 100644 index 006352d8..00000000 --- a/uprn_mangle/backend/backend/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for backend project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') - -application = get_wsgi_application() diff --git a/uprn_mangle/backend/api/management/support/constants.py b/uprn_mangle/backend/constants.py similarity index 99% rename from uprn_mangle/backend/api/management/support/constants.py rename to uprn_mangle/backend/constants.py index cdca1f88..9eed6f31 100644 --- a/uprn_mangle/backend/api/management/support/constants.py +++ b/uprn_mangle/backend/constants.py @@ -1,4 +1,5 @@ """Set some support constants etc we need for the import.""" + # get script path import os from inspect import getsourcefile diff --git a/uprn_mangle/backend/api/management/commands/import_uprn.py b/uprn_mangle/backend/import_uprn.py similarity index 99% rename from uprn_mangle/backend/api/management/commands/import_uprn.py rename to uprn_mangle/backend/import_uprn.py index 09dcc161..dcdf9b19 100644 --- a/uprn_mangle/backend/api/management/commands/import_uprn.py +++ b/uprn_mangle/backend/import_uprn.py @@ -1,4 +1,5 @@ """Django command to format and import UPRN data to our database.""" + import os from glob import glob from pathlib import Path @@ -11,7 +12,7 @@ from sqlalchemy import create_engine # load constants from external file so we can share it -from api.management.support.constants import ( +from uprn_mangle.backend.constants import ( CROSSREF_DIR, CROSSREF_NAME, HEADER_DIR, diff --git a/uprn_mangle/backend/manage.py b/uprn_mangle/backend/manage.py deleted file mode 100755 index eb6431e2..00000000 --- a/uprn_mangle/backend/manage.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == '__main__': - main() diff --git a/uprn_mangle/backend/api/models.py b/uprn_mangle/backend/old_models.py similarity index 95% rename from uprn_mangle/backend/api/models.py rename to uprn_mangle/backend/old_models.py index a7892cb1..567cfe8c 100644 --- a/uprn_mangle/backend/api/models.py +++ b/uprn_mangle/backend/old_models.py @@ -27,9 +27,7 @@ class Addressbase(models.Model): logical_status = models.BigIntegerField( db_column="LOGICAL_STATUS", blank=True, null=True ) - blpu_state = models.TextField( - db_column="BLPU_STATE", blank=True, null=True - ) + blpu_state = models.TextField(db_column="BLPU_STATE", blank=True, null=True) x_coordinate = models.FloatField( db_column="X_COORDINATE", blank=True, null=True )