From d26820c4634e0a42467488375f38ad0d37f94e93 Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Fri, 12 Jun 2020 10:12:09 +0200 Subject: [PATCH] TMSS-207: return the normal list of urls, but then sorted by url so they are easier to find in a list for us humble humans --- SAS/TMSS/src/tmss/urls.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/SAS/TMSS/src/tmss/urls.py b/SAS/TMSS/src/tmss/urls.py index 4231fe33b0d..d63bd5467b9 100644 --- a/SAS/TMSS/src/tmss/urls.py +++ b/SAS/TMSS/src/tmss/urls.py @@ -20,6 +20,7 @@ from django.urls import path, re_path from django.conf.urls import url, include from django.views.generic.base import TemplateView +from collections import OrderedDict from rest_framework import routers, permissions from .tmssapp import viewsets, models, serializers, views from rest_framework.documentation import include_docs_urls @@ -60,7 +61,21 @@ urlpatterns = [ # REST Router # +class TMSSAPIRootView(routers.APIRootView): + def get(self, request, *args, **kwargs): + '''return the normal list of urls, but then sorted by url so they are easier to find in a list for us humble humans''' + response = super().get(request, *args, **kwargs) + sorted_by_key_urls = OrderedDict() + + for key in sorted(response.data.keys()): + sorted_by_key_urls[key] = response.data[key] + + response.data = sorted_by_key_urls + + return response + router = routers.DefaultRouter() +router.APIRootView = TMSSAPIRootView router.register(r'tags', viewsets.TagsViewSet) # SPECIFICATION -- GitLab