Skip to content

Commit

Permalink
EOL fixer, ruff, isort: pre-commit :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Mar 12, 2024
1 parent d4bc8f0 commit 8605024
Show file tree
Hide file tree
Showing 51 changed files with 348 additions and 279 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ Om het lokaal te installeren:

6) start celery op: celery -A bro_hub worker -l INFO -P solo

7) Maak een organisatie, vul de KvK in
7) Maak een organisatie, vul de KvK in

8) Maak een user profile aan voor de superuser, en vul het project en evt bro authenticatie in

9) De bro auth gegevens worden geencrypt. Hiervoor is een FIELD_ENCRYPTION_KEY nodig. Om deze aan te maken, run hetvolgende:
9) De bro auth gegevens worden geencrypt. Hiervoor is een FIELD_ENCRYPTION_KEY nodig. Om deze aan te maken, run hetvolgende:

$ import os
import base64

new_key = base64.urlsafe_b64encode(os.urandom(32))
print(new_key)

Expand All @@ -58,4 +58,3 @@ Installatie frontend (temp strealit)
Start the frontend with:

$ streamlit run streamlit/Home.py
3 changes: 2 additions & 1 deletion api/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django import forms
from django.contrib import admin

from . import models


Expand Down
3 changes: 2 additions & 1 deletion api/bro_import/bulk_import.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import requests
import traceback

import requests
from django.conf import settings

from api import models
from api.bro_import import config

Expand Down
34 changes: 17 additions & 17 deletions api/bro_import/object_import.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import requests
import xmltodict

from abc import ABC, abstractmethod
from typing import IO, Dict, Any, List, Tuple
from typing import IO, Any

import requests
import xmltodict
from django.conf import settings
from gmn.models import GMN, Measuringpoint
from gmw.models import GMW, MonitoringTube

from api import models
from api.bro_import import config
from gmn.models import GMN, Measuringpoint
from gmw.models import GMW, MonitoringTube


def import_single_object(bro_domain: str, bro_id: str, data_owner: str) -> None:
Expand Down Expand Up @@ -58,19 +58,19 @@ def _download_xml(self, url: str) -> IO[bytes]:

return r.content

def _convert_xml_to_json(self, xml_data: IO[bytes]) -> Dict[str, Any]:
def _convert_xml_to_json(self, xml_data: IO[bytes]) -> dict[str, Any]:
json_data = xmltodict.parse(xml_data)

return json_data

@abstractmethod
def _save_data_to_database(self, json_data: Dict[str, Any]):
def _save_data_to_database(self, json_data: dict[str, Any]):
"""Saves the downloaded BRO data into the Django database."""
pass


class GMNObjectImporter(ObjectImporter):
def _save_data_to_database(self, json_data: Dict[str, Any]) -> None:
def _save_data_to_database(self, json_data: dict[str, Any]) -> None:
dispatch_document_data = json_data.get("dispatchDataResponse", {}).get(
"dispatchDocument", {}
)
Expand All @@ -85,8 +85,8 @@ def _save_data_to_database(self, json_data: Dict[str, Any]) -> None:
self._save_measuringpoint_data(measuringpoint_data)

def _split_json_data(
self, dispatch_document_data: Dict[str, Any]
) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]:
self, dispatch_document_data: dict[str, Any]
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
"""Takes in the json data and splits it up into GMN and Measuringpoint data"""

measuringpoint_data = dispatch_document_data["GMN_PPO"].get(
Expand All @@ -98,7 +98,7 @@ def _split_json_data(

return gmn_data, measuringpoint_data

def _save_gmn_data(self, gmn_data: Dict[str, Any]) -> None:
def _save_gmn_data(self, gmn_data: dict[str, Any]) -> None:
self.gmn_obj, created = GMN.objects.update_or_create(
bro_id=gmn_data.get("brocom:broId", None),
data_owner=self.data_owner,
Expand Down Expand Up @@ -131,7 +131,7 @@ def _save_gmn_data(self, gmn_data: Dict[str, Any]) -> None:

self.gmn_obj.save()

def _save_measuringpoint_data(self, measuringpoint_data: Dict[str, Any]) -> None:
def _save_measuringpoint_data(self, measuringpoint_data: dict[str, Any]) -> None:
for measuringpoint in measuringpoint_data:
mp_data = measuringpoint.get("MeasuringPoint", {})
monitoring_tube_data = mp_data.get("monitoringTube", {}).get(
Expand All @@ -158,7 +158,7 @@ def _save_measuringpoint_data(self, measuringpoint_data: Dict[str, Any]) -> None


class GMWObjectImporter(ObjectImporter):
def _save_data_to_database(self, json_data: Dict[str, Any]) -> None:
def _save_data_to_database(self, json_data: dict[str, Any]) -> None:
dispatch_document_data = json_data.get("dispatchDataResponse", {}).get(
"dispatchDocument", {}
)
Expand All @@ -173,8 +173,8 @@ def _save_data_to_database(self, json_data: Dict[str, Any]) -> None:
self._save_monitoringtubes_data(monitoringtubes_data)

def _split_json_data(
self, dispatch_document_data: Dict[str, Any]
) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]:
self, dispatch_document_data: dict[str, Any]
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
"""Takes in the json data and splits it up into GMW and tubes data"""

monitoringtubes_data = dispatch_document_data["GMW_PPO"].get(
Expand All @@ -186,7 +186,7 @@ def _split_json_data(

return gmw_data, monitoringtubes_data

def _save_gmw_data(self, gmw_data: Dict[str, Any]) -> None:
def _save_gmw_data(self, gmw_data: dict[str, Any]) -> None:
self.gmw_obj, created = GMW.objects.update_or_create(
bro_id=gmw_data.get("brocom:broId", None),
data_owner=self.data_owner,
Expand Down
4 changes: 1 addition & 3 deletions api/bro_upload/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import traceback
from typing import Union

from . import config

from . import utils
from . import config, utils


class XMLValidationError(Exception):
Expand Down
7 changes: 3 additions & 4 deletions api/bro_upload/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import requests
import json
import traceback
from typing import Any

from typing import Dict, Any

import requests
from django.conf import settings


def validate_xml_file(
xml_file: bytes, bro_username: str, bro_password: str, project_number: str
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Validates a XML file with the Bronhouderportaal api."""
url = f"{settings.BRONHOUDERSPORTAAL_URL}/api/v2/{project_number}/validatie"

Expand Down
6 changes: 3 additions & 3 deletions api/bro_upload/xml_generators/base_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Dict, Any
from typing import Any

from lxml import etree
from lxml.etree import tostring
Expand All @@ -21,8 +21,8 @@ def __init__(
self,
registration_type: str,
request_type: str,
metadata: Dict[str, Any],
sourcedocs_data: Dict[str, Any],
metadata: dict[str, Any],
sourcedocs_data: dict[str, Any],
) -> None:
self.registration_type = registration_type
self.request_type = request_type
Expand Down
1 change: 1 addition & 0 deletions api/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django_filters import rest_framework as filters

from . import models


Expand Down
3 changes: 2 additions & 1 deletion api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 5.0.1 on 2024-02-05 12:43

import django.db.models.deletion
import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

Expand Down
1 change: 1 addition & 0 deletions api/migrations/0007_uploadtask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 5.0.1 on 2024-02-14 17:54

import uuid

from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("api", "0018_alter_userprofile_first_name_and_more"),
]
Expand Down
2 changes: 1 addition & 1 deletion api/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uuid

from django.contrib.auth.models import User
from django.db import models
from django.db.models import JSONField
from encrypted_model_fields.fields import EncryptedCharField

from . import choices
from django.db import models


class Organisation(models.Model):
Expand Down
3 changes: 2 additions & 1 deletion api/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from celery import shared_task

from . import models
from .bro_import import bulk_import, object_import
from .bro_import import bulk_import
from .bro_upload.delivery import BRODelivery


Expand Down
8 changes: 5 additions & 3 deletions api/tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest
import uuid
from unittest.mock import patch
from api.bro_import import bulk_import, object_import

import pytest

from api import models
import uuid
from api.bro_import import bulk_import, object_import


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion api/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
import uuid

import pytest
from django.contrib.auth.models import User
from django.test import TestCase

from api import models


Expand Down
5 changes: 3 additions & 2 deletions api/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import uuid

from django.test import TestCase
from api import models
from api import serializers

from api import models, serializers


class ImportTaskSerializerTest(TestCase):
Expand Down
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import path, include
from django.urls import include, path

from . import views

app_name = "api"
Expand Down
19 changes: 7 additions & 12 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from rest_framework import status, generics, views
from rest_framework.response import Response
from django.urls import reverse
from rest_framework.reverse import reverse as drf_reverse
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import permissions
from django.contrib.auth import logout
from django.shortcuts import redirect
from django.urls import reverse
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import generics, permissions, status, views
from rest_framework.response import Response
from rest_framework.reverse import reverse as drf_reverse

from . import tasks
from . import serializers
from . import models
from . import mixins
from . import filters
from . import filters, mixins, models, serializers, tasks


class LogoutView(views.APIView):
Expand Down Expand Up @@ -114,13 +109,13 @@ class ImportTaskListView(mixins.UserOrganizationMixin, generics.ListAPIView):
`kvk_number`:
string (*optional*). When not filled in, the kvk of the organisation linked to the user is used.
"""

queryset = models.ImportTask.objects.all().order_by("-created")
serializer_class = serializers.ImportTaskSerializer
permission_classes = [permissions.IsAuthenticated]
filter_backends = [DjangoFilterBackend]
filterset_fields = "__all__"


def get(self, request, *args, **kwargs):
"""List of all Import Tasks."""
return self.list(request, *args, **kwargs)
Expand Down
2 changes: 2 additions & 0 deletions bro_hub/celery.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from celery import Celery

from bro_hub.settings.base import ENVIRONMENT

if ENVIRONMENT == "production":
Expand Down
9 changes: 5 additions & 4 deletions bro_hub/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

from pathlib import Path
from dotenv import load_dotenv
import os
from datetime import timedelta
from pathlib import Path

from dotenv import load_dotenv

# Load environment variables from .env
load_dotenv()
Expand Down Expand Up @@ -139,8 +140,8 @@

# DRF configuration
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100,
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 100,
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.BasicAuthentication",
Expand Down
1 change: 1 addition & 0 deletions bro_hub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
TokenObtainPairView,
TokenRefreshView,
)

from api import views

urlpatterns = [
Expand Down
1 change: 1 addition & 0 deletions gmn/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin

from . import models

admin.site.register(models.GMN)
Expand Down
1 change: 1 addition & 0 deletions gmn/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 5.0.1 on 2024-02-05 12:43

import uuid

from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 5.0.1 on 2024-02-06 09:09

import uuid

from django.db import migrations, models


Expand Down
1 change: 1 addition & 0 deletions gmn/migrations/0007_gmnstartregistration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 5.0.1 on 2024-02-13 16:02

import uuid

from django.db import migrations, models


Expand Down
Loading

0 comments on commit 8605024

Please sign in to comment.