def get_queryset(self): return self.queryset.filter( fields.privacy_level_query( self.request.user, lookup_field="playlist__privacy_level", user_field="playlist__user", )).for_nested_serialization( music_utils.get_actor_from_request(self.request))
def get_queryset(self): queryset = super().get_queryset() queryset = queryset.filter( fields.privacy_level_query(self.request.user, "user__privacy_level")) tracks = Track.objects.with_playable_uploads( music_utils.get_actor_from_request(self.request)).select_related( "artist", "album__artist", "attributed_to") return queryset.prefetch_related(Prefetch("track", queryset=tracks))
def get_activity(user, limit=20): query = fields.privacy_level_query(user, lookup_field="user__privacy_level") querysets = [ Listening.objects.filter(query).select_related("track", "user", "track__artist", "track__album__artist"), TrackFavorite.objects.filter(query).select_related( "track", "user", "track__artist", "track__album__artist"), ] records = combined_recent(limit=limit, querysets=querysets) return [r["object"] for r in records]
def get_queryset(self): return self.queryset.filter( fields.privacy_level_query(self.request.user)).with_playable_plts( music_utils.get_actor_from_request(self.request))
def get_playlist_qs(request): qs = playlists_models.Playlist.objects.filter( fields.privacy_level_query(request.user)) qs = qs.with_tracks_count().exclude(_tracks_count=0).select_related("user") return qs.order_by("-creation_date")
def test_privacy_level_query(user, expected): query = fields.privacy_level_query(user) assert query == expected