Add module list to API
This commit is contained in:
parent
68b344904a
commit
801e8929c7
@ -18,5 +18,6 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('download/<str:req_mod>/<str:req_ver>/', views.ModuleDownloadView.as_view(), name="api_zip_dl"),
|
path('download/<str:req_mod>/<str:req_ver>/', views.ModuleDownloadView.as_view(), name="api_zip_dl"),
|
||||||
path('toml_download/<str:req_mod>/<str:req_ver>/', views.TomlDownloadView.as_view(), name="api_toml_dl")
|
path('toml_download/<str:req_mod>/<str:req_ver>/', views.TomlDownloadView.as_view(), name="api_toml_dl"),
|
||||||
|
path('modules/', views.ApiModuleListView.as_view(), name="api_modules_list"),
|
||||||
]
|
]
|
||||||
|
@ -3,6 +3,7 @@ from django.views import View
|
|||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
from store.models import Module, Version
|
from store.models import Module, Version
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.core import serializers
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import zipfile, os
|
import zipfile, os
|
||||||
|
|
||||||
@ -31,3 +32,14 @@ class TomlDownloadView(View):
|
|||||||
response = HttpResponse(f, content_type="application/toml")
|
response = HttpResponse(f, content_type="application/toml")
|
||||||
response['Content-Disposition'] = f'attachment; filename={module.name}-{version.ver}.toml'
|
response['Content-Disposition'] = f'attachment; filename={module.name}-{version.ver}.toml'
|
||||||
return response
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user