Skip to content

Commit

Permalink
Add API for badges
Browse files Browse the repository at this point in the history
This will allow the trovi dashboard to integrate and use our
authoritative badges.
  • Loading branch information
Mark-Powers committed Oct 8, 2024
1 parent dbdb10a commit bee3f8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions sharing_portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
path("import/git/<pk>", views.create_git_version, name="create_git_version"),
path("create", views.create_artifact, name="create_artifact"),
path("api/git/", views.get_remote_data, name="get_remote_git_data"),
path("api/badges", views.badges_api, name="badges"),
path("<pk>", views.artifact, name="detail"),
path("<pk>/launch", views.launch, name="launch"),
path("<pk>/download", views.download, name="download"),
Expand Down
26 changes: 26 additions & 0 deletions sharing_portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,3 +1393,29 @@ def download(request, artifact, version_slug=None):
return HttpResponseRedirect(
reverse("sharing_portal:detail", args=[artifact["uuid"]])
)


def badges_api(request):
return HttpResponse(
json.dumps({
"badges": [
{
"name": b.name,
"description": b.description,
"redirect_link": b.redirect_link,
}
for b in Badge.objects.filter()
],
"artifact_badges": [
{
"artifact_uuid": a.artifact_uuid,
"badge": a.badge.name,
} for a in
ArtifactBadge.objects.filter(
status=ArtifactBadge.STATUS_APPROVED,
deleted_at=None
)
]
}),
content_type="application/json",
)

0 comments on commit bee3f8f

Please sign in to comment.