From cb2ff90d8a32c47fd705a2a84943376aecfc35af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Tue, 12 Jul 2022 19:00:50 +0200 Subject: [PATCH] Review roster API --- ram/portal/templates/includes/footer.html | 6 ++--- ram/ram/urls.py | 30 +++++++++++------------ ram/roster/urls.py | 4 +-- ram/roster/views.py | 27 ++++++++++++++++---- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/ram/portal/templates/includes/footer.html b/ram/portal/templates/includes/footer.html index 84568c8..cd8d828 100644 --- a/ram/portal/templates/includes/footer.html +++ b/ram/portal/templates/includes/footer.html @@ -12,9 +12,9 @@ {{ site_conf.footer_extended | markdown | safe }} - {% if site_conf.show_version %} +
-

Made with ❤️ and django-ram version {{ site_conf.version }}

+

Made with ❤️ for 🚂 and django-ram + {% if site_conf.show_version %}
Version {{ site_conf.version }}{% endif %}

- {% endif %} diff --git a/ram/ram/urls.py b/ram/ram/urls.py index 6eee403..8a2344c 100644 --- a/ram/ram/urls.py +++ b/ram/ram/urls.py @@ -29,18 +29,18 @@ urlpatterns = [ path("api/v1/dcc/", include("driver.urls")), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -# if settings.DEBUG: -# from django.views.generic import TemplateView -# from rest_framework.schemas import get_schema_view -# -# urlpatterns += [ -# path('swagger/', TemplateView.as_view( -# template_name='swagger.html', -# extra_context={'schema_url': 'openapi-schema'} -# ), name='swagger'), -# path('openapi', get_schema_view( -# title="BITE - A Basic/IoT/Example", -# description="BITE API for IoT", -# version="1.0.0" -# ), name='openapi-schema'), -# ] +if settings.DEBUG: + from django.views.generic import TemplateView + from rest_framework.schemas import get_schema_view + + urlpatterns += [ + path('swagger/', TemplateView.as_view( + template_name='swagger.html', + extra_context={'schema_url': 'openapi-schema'} + ), name='swagger'), + path('openapi', get_schema_view( + title="RAM - Railroad Assets Manager", + description="RAM API", + version="1.0.0" + ), name='openapi-schema'), + ] diff --git a/ram/roster/urls.py b/ram/roster/urls.py index 87ccf38..1779f5b 100644 --- a/ram/roster/urls.py +++ b/ram/roster/urls.py @@ -1,9 +1,9 @@ from django.urls import path -from roster.views import RosterList, RosterGet, RosterAddress, RosterIdentifier +from roster.views import RosterList, RosterGet, RosterAddress, RosterClass urlpatterns = [ path("list", RosterList.as_view()), path("get/", RosterGet.as_view()), path("address/", RosterAddress.as_view()), - path("identifier/", RosterIdentifier.as_view()), + path("class/", RosterClass.as_view()), ] diff --git a/ram/roster/views.py b/ram/roster/views.py index a11ac45..569b6ac 100644 --- a/ram/roster/views.py +++ b/ram/roster/views.py @@ -1,4 +1,5 @@ from rest_framework.generics import ListAPIView, RetrieveAPIView +from rest_framework.schemas.openapi import AutoSchema from roster.models import RollingStock from roster.serializers import RollingStockSerializer @@ -14,14 +15,30 @@ class RosterGet(RetrieveAPIView): serializer_class = RollingStockSerializer lookup_field = "uuid" + schema = AutoSchema( + operation_id_base="retrieveRollingStockByUUID" + ) + class RosterAddress(ListAPIView): - queryset = RollingStock.objects.all() serializer_class = RollingStockSerializer - lookup_field = "address" + + schema = AutoSchema( + operation_id_base="retrieveRollingStockByAddress" + ) + + def get_queryset(self): + address = self.kwargs["address"] + return RollingStock.objects.filter(address=address) -class RosterIdentifier(RetrieveAPIView): - queryset = RollingStock.objects.all() +class RosterClass(ListAPIView): serializer_class = RollingStockSerializer - lookup_field = "identifier" + + schema = AutoSchema( + operation_id_base="retrieveRollingStockByClass" + ) + + def get_queryset(self): + _class = self.kwargs["class"] + return RollingStock.objects.filter(rolling_class__identifier=_class)