Add module versions list to API
This commit is contained in:
parent
801e8929c7
commit
1a1137598e
@ -20,4 +20,5 @@ 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"),
|
path('modules/', views.ApiModuleListView.as_view(), name="api_modules_list"),
|
||||||
|
path('versions/<str:name>/', views.ModuleVersionsView.as_view(), name="api_modules_versions"),
|
||||||
]
|
]
|
||||||
|
@ -43,3 +43,15 @@ class ApiModuleListView(View):
|
|||||||
for mod in Module.objects.all():
|
for mod in Module.objects.all():
|
||||||
mod_list['modules'].append(mod.name)
|
mod_list['modules'].append(mod.name)
|
||||||
return JsonResponse(mod_list)
|
return JsonResponse(mod_list)
|
||||||
|
|
||||||
|
class ModuleVersionsView(View):
|
||||||
|
"""
|
||||||
|
Module versions view : returns jsons response with all versions of a single
|
||||||
|
module, using module name
|
||||||
|
"""
|
||||||
|
def get(self, request, name):
|
||||||
|
mod = get_object_or_404(Module, name=name)
|
||||||
|
versions = {mod.name: []}
|
||||||
|
for ver in Version.objects.filter(module=mod):
|
||||||
|
versions[mod.name].append(ver.ver)
|
||||||
|
return JsonResponse(versions)
|
||||||
|
Loading…
Reference in New Issue
Block a user