Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jd 2023 05 add linting #587

Merged
merged 3 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

make lint-quick
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VIRTUAL_ENV ?= venv
SOURCE_DIRS = bplan django_zbp

.PHONY: install
install:
Expand Down Expand Up @@ -39,3 +40,33 @@ clean:
if [ -f package-lock.json ]; then rm package-lock.json; fi
if [ -d node_modules ]; then rm -rf node_modules; fi
if [ -d venv ]; then rm -rf venv; fi

.PHONY: lint
lint:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/isort --diff -c $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/flake8 $(SOURCE_DIRS) --exclude migrations,settings || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}

.PHONY: lint-quick
lint-quick:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}

.PHONY: lint-python-files
lint-python-files:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/black $(ARGUMENTS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/isort --diff -c $(ARGUMENTS) --filter-files || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/flake8 $(ARGUMENTS) || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}

.PHONY: lint-fix
lint-fix:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/isort $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}


7 changes: 4 additions & 3 deletions bplan/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django.contrib.gis import admin

from .models import Address
from .models import Bezirk
from .models import Ortsteil
from .models import BPlan
from .models import Download
from .models import Address
from .models import Ortsteil


class DownloadAdmin(admin.ModelAdmin):
list_filter = ('bplan', )
list_filter = ("bplan",)


admin.site.register(Bezirk, admin.GeoModelAdmin)
Expand Down
122 changes: 81 additions & 41 deletions bplan/api.py
Original file line number Diff line number Diff line change
@@ -1,110 +1,150 @@
from rest_framework import viewsets
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from rest_framework_gis.pagination import GeoJsonPagination
from .filters import StatusFilter, OrtsteilFilter
from rest_framework_gis.filters import InBBoxFilter
from rest_framework_gis.filters import DistanceToPointFilter
from .filters import StatusFilter
from .filters import OrtsteilFilter
from rest_framework_gis.pagination import GeoJsonPagination

from .filters import AddressFilter
from .filters import BezirkFilter
from .filters import BPlanAddressFilter
from .filters import BplanFilter
from .filters import OrtsteilFilter
from .filters import PlzFilter
from .filters import StatusFilter
from .models import Address
from .models import Bezirk
from .models import BPlan
from .models import Ortsteil
from .serializers import AddressSerializer
from .serializers import BezirkSerializer
from .serializers import OrtsteilSerializer
from .serializers import BPlanPointSerializer
from .serializers import SimpleBPlanSerializer
from .serializers import BPlanMultipolygonSerializer
from .serializers import BPlanPointSerializer
from .serializers import BPlanSerializer
from .serializers import AddressSerializer
from .models import Bezirk
from .models import Ortsteil
from .models import BPlan
from .models import Address
from .serializers import OrtsteilSerializer
from .serializers import SimpleBPlanSerializer


class CustomGeoJsonPagination(GeoJsonPagination):
page_size = 4000
page_size_query_param = 'page_size'
page_size_query_param = "page_size"
max_page_size = 10000


class CustomAddressGeoJsonPagination(GeoJsonPagination):
page_size = 100
page_size_query_param = 'page_size'
page_size_query_param = "page_size"
max_page_size = 10000


class CustomPagination(PageNumberPagination):
page_size = 4000
page_size_query_param = 'page_size'
page_size_query_param = "page_size"
max_page_size = 10000


class AddressViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Address.objects.all().order_by('plz')
queryset = Address.objects.all().order_by("plz")
pagination_class = CustomAddressGeoJsonPagination
serializer_class = AddressSerializer
filter_backends = (DjangoFilterBackend, AddressFilter, BezirkFilter,
PlzFilter)
filter_backends = (DjangoFilterBackend, AddressFilter, BezirkFilter, PlzFilter)


class BezirkViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Bezirk.objects.all()
serializer_class = BezirkSerializer
filter_backends = (DjangoFilterBackend, )
filter_fields = ('name', 'slug')
filter_backends = (DjangoFilterBackend,)
filter_fields = ("name", "slug")


class OrtsteilViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Ortsteil.objects.all()
serializer_class = OrtsteilSerializer
filter_backends = (DjangoFilterBackend, )
filter_fields = ('name', )
filter_backends = (DjangoFilterBackend,)
filter_fields = ("name",)


class BPlanViewSet(viewsets.ReadOnlyModelViewSet):
queryset = BPlan.objects.all()
serializer_class = BPlanSerializer
pagination_class = CustomGeoJsonPagination
filter_backends = (DjangoFilterBackend, StatusFilter, OrtsteilFilter,
InBBoxFilter, BPlanAddressFilter, BplanFilter)
filter_backends = (
DjangoFilterBackend,
StatusFilter,
OrtsteilFilter,
InBBoxFilter,
BPlanAddressFilter,
BplanFilter,
)
bbox_filter_include_overlapping = True
bbox_filter_field = 'multipolygon'
filter_fields = ('bplanID', 'planname', 'bezirk', 'festg', 'bezirk__slug',
'afs_behoer')
bbox_filter_field = "multipolygon"
filter_fields = (
"bplanID",
"planname",
"bezirk",
"festg",
"bezirk__slug",
"afs_behoer",
)


class BPlanDataViewSet(viewsets.ReadOnlyModelViewSet):
queryset = BPlan.objects.all()
serializer_class = SimpleBPlanSerializer
pagination_class = CustomPagination
filter_backends = (DjangoFilterBackend, StatusFilter, OrtsteilFilter)
filter_fields = ('bplanID', 'planname', 'bezirk', 'festg', 'bezirk__slug',
'afs_behoer')
filter_fields = (
"bplanID",
"planname",
"bezirk",
"festg",
"bezirk__slug",
"afs_behoer",
)


class BPlanPointViewSet(viewsets.ReadOnlyModelViewSet):
queryset = BPlan.objects.all()
serializer_class = BPlanPointSerializer
pagination_class = CustomGeoJsonPagination
filter_backends = (DjangoFilterBackend, StatusFilter, OrtsteilFilter,
InBBoxFilter, BPlanAddressFilter, BplanFilter)
bbox_filter_field = 'point'
filter_backends = (
DjangoFilterBackend,
StatusFilter,
OrtsteilFilter,
InBBoxFilter,
BPlanAddressFilter,
BplanFilter,
)
bbox_filter_field = "point"
bbox_filter_include_overlapping = True
filter_fields = ('bplanID', 'planname', 'bezirk', 'festg', 'bezirk__slug',
'afs_behoer')
filter_fields = (
"bplanID",
"planname",
"bezirk",
"festg",
"bezirk__slug",
"afs_behoer",
)


class BPlanMultipolygonViewSet(viewsets.ReadOnlyModelViewSet):
queryset = BPlan.objects.all()
serializer_class = BPlanMultipolygonSerializer
pagination_class = CustomGeoJsonPagination
filter_backends = (DjangoFilterBackend, StatusFilter, OrtsteilFilter,
InBBoxFilter, BPlanAddressFilter, BplanFilter)
filter_backends = (
DjangoFilterBackend,
StatusFilter,
OrtsteilFilter,
InBBoxFilter,
BPlanAddressFilter,
BplanFilter,
)
bbox_filter_include_overlapping = True
bbox_filter_field = 'multipolygon'
filter_fields = ('bplanID', 'planname', 'bezirk', 'festg', 'bezirk__slug',
'afs_behoer')
bbox_filter_field = "multipolygon"
filter_fields = (
"bplanID",
"planname",
"bezirk",
"festg",
"bezirk__slug",
"afs_behoer",
)
2 changes: 1 addition & 1 deletion bplan/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class BplanConfig(AppConfig):
name = 'bplan'
name = "bplan"
Loading