feat(api): Add NodeInfo 2.1
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2604>
This commit is contained in:
parent
71140d5a9b
commit
a0ae9bbb70
9 changed files with 263 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import datetime
|
||||
|
||||
from django.db.models import Sum
|
||||
from django.db.models import Count, F, Sum
|
||||
from django.utils import timezone
|
||||
|
||||
from funkwhale_api.favorites.models import TrackFavorite
|
||||
|
|
@ -22,6 +22,39 @@ def get():
|
|||
}
|
||||
|
||||
|
||||
def get_content():
|
||||
return {
|
||||
"local": {
|
||||
"artists": get_artists(),
|
||||
"releases": get_albums(),
|
||||
"recordings": get_tracks(),
|
||||
"hoursOfContent": get_music_duration(),
|
||||
},
|
||||
"topMusicCategories": get_top_music_categories(),
|
||||
"topPodcastCategories": get_top_podcast_categories(),
|
||||
}
|
||||
|
||||
|
||||
def get_top_music_categories():
|
||||
return (
|
||||
models.Track.objects.filter(artist__content_category="music")
|
||||
.exclude(tagged_items__tag_id=None)
|
||||
.values(name=F("tagged_items__tag__name"))
|
||||
.annotate(count=Count("name"))
|
||||
.order_by("-count")[:3]
|
||||
)
|
||||
|
||||
|
||||
def get_top_podcast_categories():
|
||||
return (
|
||||
models.Track.objects.filter(artist__content_category="podcast")
|
||||
.exclude(tagged_items__tag_id=None)
|
||||
.values(name=F("tagged_items__tag__name"))
|
||||
.annotate(count=Count("name"))
|
||||
.order_by("-count")[:3]
|
||||
)
|
||||
|
||||
|
||||
def get_users():
|
||||
qs = User.objects.filter(is_active=True)
|
||||
now = timezone.now()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue