diff --git a/PDMI/api/urls.py b/PDMI/api/urls.py index e19072a..b18e3e9 100644 --- a/PDMI/api/urls.py +++ b/PDMI/api/urls.py @@ -18,5 +18,6 @@ from . import views urlpatterns = [ path('download///', views.ModuleDownloadView.as_view(), name="api_zip_dl"), - path('toml_download///', views.TomlDownloadView.as_view(), name="api_toml_dl") + path('toml_download///', views.TomlDownloadView.as_view(), name="api_toml_dl"), + path('modules/', views.ApiModuleListView.as_view(), name="api_modules_list"), ] diff --git a/PDMI/api/views.py b/PDMI/api/views.py index 1b99edb..3033a1b 100644 --- a/PDMI/api/views.py +++ b/PDMI/api/views.py @@ -3,6 +3,7 @@ from django.views import View from django.http import HttpResponse, JsonResponse from store.models import Module, Version from django.shortcuts import get_object_or_404 +from django.core import serializers from io import BytesIO import zipfile, os @@ -31,3 +32,14 @@ class TomlDownloadView(View): response = HttpResponse(f, content_type="application/toml") response['Content-Disposition'] = f'attachment; filename={module.name}-{version.ver}.toml' return response + +class ApiModuleListView(View): + """ + Api module list view : returns json response with all available modules, + which requires no argument + """ + def get(self, request): + mod_list = {'modules': []} + for mod in Module.objects.all(): + mod_list['modules'].append(mod.name) + return JsonResponse(mod_list)