diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 3f7cc7503..6a2299bb4 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -54,6 +54,7 @@ THIRD_PARTY_APPS = ( 'rest_auth.registration', 'mptt', 'dynamic_preferences', + 'django_filters', ) # Apps specific for this project go here. @@ -298,7 +299,7 @@ REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), - 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'DEFAULT_PAGINATION_CLASS': 'funkwhale_api.common.pagination.FunkwhalePagination', 'PAGE_SIZE': 25, 'DEFAULT_AUTHENTICATION_CLASSES': ( @@ -309,6 +310,7 @@ REST_FRAMEWORK = { ), 'DEFAULT_FILTER_BACKENDS': ( 'rest_framework.filters.OrderingFilter', + 'django_filters.rest_framework.DjangoFilterBackend', ) } diff --git a/api/funkwhale_api/common/pagination.py b/api/funkwhale_api/common/pagination.py new file mode 100644 index 000000000..224c470dc --- /dev/null +++ b/api/funkwhale_api/common/pagination.py @@ -0,0 +1,6 @@ +from rest_framework.pagination import PageNumberPagination + + +class FunkwhalePagination(PageNumberPagination): + page_size_query_param = 'page_size' + max_page_size = 25 diff --git a/api/funkwhale_api/music/filters.py b/api/funkwhale_api/music/filters.py new file mode 100644 index 000000000..ba3fa453d --- /dev/null +++ b/api/funkwhale_api/music/filters.py @@ -0,0 +1,12 @@ +import django_filters + +from . import models + + +class ArtistFilter(django_filters.FilterSet): + + class Meta: + model = models.Artist + fields = { + 'name': ['exact', 'iexact', 'startswith'] + } diff --git a/api/funkwhale_api/music/tests/test_api.py b/api/funkwhale_api/music/tests/test_api.py index 21a567084..b7c25424f 100644 --- a/api/funkwhale_api/music/tests/test_api.py +++ b/api/funkwhale_api/music/tests/test_api.py @@ -182,6 +182,21 @@ class TestAPI(TMPDirTestCaseMixin, TestCase): self.assertJSONEqual(expected, json.loads(response.content.decode('utf-8'))) + def test_can_search_artist_by_name_start(self): + artist1 = factories.ArtistFactory(name='alpha') + artist2 = factories.ArtistFactory(name='beta') + results = { + 'next': None, + 'previous': None, + 'count': 1, + 'results': [serializers.ArtistSerializerNested(artist1).data] + } + expected = json.dumps(results) + url = self.reverse('api:v1:artists-list') + response = self.client.get(url, {'name__startswith': 'a'}) + + self.assertJSONEqual(expected, json.loads(response.content.decode('utf-8'))) + def test_can_search_tracks(self): artist1 = models.Artist.objects.create(name='Test1') artist2 = models.Artist.objects.create(name='Test2') diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index 983192552..d149b5d1b 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -21,8 +21,10 @@ from taggit.models import Tag from . import models from . import serializers from . import importers +from . import filters from . import utils + class SearchMixin(object): search_fields = [] @@ -52,7 +54,8 @@ class ArtistViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet): serializer_class = serializers.ArtistSerializerNested permission_classes = [ConditionalAuthentication] search_fields = ['name'] - ordering_fields = ('creation_date',) + ordering_fields = ('creation_date', 'name') + filter_class = filters.ArtistFilter class AlbumViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet): diff --git a/api/requirements/base.txt b/api/requirements/base.txt index e7bc870cf..3a11afadf 100644 --- a/api/requirements/base.txt +++ b/api/requirements/base.txt @@ -45,6 +45,7 @@ django-taggit==0.22.1 persisting-theory==0.2.1 django-versatileimagefield==1.7.1 django-cachalot==1.5.0 +django-filter==1.1 django-rest-auth==0.9.1 beautifulsoup4==4.6.0 Markdown==2.6.8 diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 72b7d7ef9..423c9d12f 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -7,14 +7,14 @@
- + {{ queue.currentTrack.title }}
- + {{ queue.currentTrack.artist.name }} / - + {{ queue.currentTrack.album.title }}
diff --git a/front/src/components/audio/SearchBar.vue b/front/src/components/audio/SearchBar.vue index 6f4629296..2324c8839 100644 --- a/front/src/components/audio/SearchBar.vue +++ b/front/src/components/audio/SearchBar.vue @@ -35,7 +35,7 @@ export default { let categories = [ { code: 'artists', - route: 'library.artist', + route: 'library.artists.detail', name: 'Artist', getTitle (r) { return r.name @@ -46,7 +46,7 @@ export default { }, { code: 'albums', - route: 'library.album', + route: 'library.albums.detail', name: 'Album', getTitle (r) { return r.title @@ -57,7 +57,7 @@ export default { }, { code: 'tracks', - route: 'library.track', + route: 'library.tracks.detail', name: 'Track', getTitle (r) { return r.title diff --git a/front/src/components/audio/album/Card.vue b/front/src/components/audio/album/Card.vue index 7fd60d963..6902612dd 100644 --- a/front/src/components/audio/album/Card.vue +++ b/front/src/components/audio/album/Card.vue @@ -6,10 +6,10 @@
- {{ album.title }} + {{ album.title }}
- By + By {{ album.artist.name }}
@@ -21,7 +21,7 @@ - + diff --git a/front/src/components/audio/artist/Card.vue b/front/src/components/audio/artist/Card.vue index a9701c07e..8a02163fb 100644 --- a/front/src/components/audio/artist/Card.vue +++ b/front/src/components/audio/artist/Card.vue @@ -2,7 +2,7 @@
- + {{ artist.name }}
@@ -15,7 +15,7 @@ - + {{ album.title }}
{{ album.tracks.length }} tracks diff --git a/front/src/components/audio/track/Table.vue b/front/src/components/audio/track/Table.vue index e9beaa05a..ac903ad52 100644 --- a/front/src/components/audio/track/Table.vue +++ b/front/src/components/audio/track/Table.vue @@ -20,7 +20,7 @@ - + @@ -28,12 +28,12 @@ - + {{ track.artist.name }} - + {{ track.album.title }} diff --git a/front/src/components/favorites/List.vue b/front/src/components/favorites/List.vue index 053f62bc6..7e3e23505 100644 --- a/front/src/components/favorites/List.vue +++ b/front/src/components/favorites/List.vue @@ -17,6 +17,7 @@
@@ -48,6 +49,7 @@ export default { nextLink: null, previousLink: null, page: 1, + paginateBy: 25, favoriteTracks } }, @@ -60,7 +62,8 @@ export default { this.isLoading = true let params = { favorites: 'true', - page: this.page + page: this.page, + page_size: this.paginateBy } logger.default.time('Loading user favorites') this.$http.get(url, {params: params}).then((response) => { diff --git a/front/src/components/library/Album.vue b/front/src/components/library/Album.vue index cf3403400..dcfea5600 100644 --- a/front/src/components/library/Album.vue +++ b/front/src/components/library/Album.vue @@ -12,7 +12,7 @@ {{ album.title }}
Album containing {{ album.tracks.length }} tracks, - by + by {{ album.artist.name }}
diff --git a/front/src/components/library/Artists.vue b/front/src/components/library/Artists.vue new file mode 100644 index 000000000..a9890dada --- /dev/null +++ b/front/src/components/library/Artists.vue @@ -0,0 +1,86 @@ + + + + + + diff --git a/front/src/components/library/Library.vue b/front/src/components/library/Library.vue index 56b750a4a..da9ac19b3 100644 --- a/front/src/components/library/Library.vue +++ b/front/src/components/library/Library.vue @@ -2,8 +2,11 @@
diff --git a/front/src/components/library/Track.vue b/front/src/components/library/Track.vue index 3c627c13c..36a76e822 100644 --- a/front/src/components/library/Track.vue +++ b/front/src/components/library/Track.vue @@ -12,10 +12,10 @@ {{ track.title }}
From album - + {{ track.album.title }} - by + by {{ track.artist.name }}
diff --git a/front/src/router/index.js b/front/src/router/index.js index b3d90731f..e546172b5 100644 --- a/front/src/router/index.js +++ b/front/src/router/index.js @@ -7,6 +7,7 @@ import Logout from '@/components/auth/Logout' import Library from '@/components/library/Library' import LibraryHome from '@/components/library/Home' import LibraryArtist from '@/components/library/Artist' +import LibraryArtists from '@/components/library/Artists' import LibraryAlbum from '@/components/library/Album' import LibraryTrack from '@/components/library/Track' import LibraryImport from '@/components/library/import/Main' @@ -51,9 +52,10 @@ export default new Router({ component: Library, children: [ { path: '', component: LibraryHome }, - { path: 'artist/:id', name: 'library.artist', component: LibraryArtist, props: true }, - { path: 'album/:id', name: 'library.album', component: LibraryAlbum, props: true }, - { path: 'track/:id', name: 'library.track', component: LibraryTrack, props: true }, + { path: 'artists/', name: 'library.artists.browse', component: LibraryArtists }, + { path: 'artists/:id', name: 'library.artists.detail', component: LibraryArtist, props: true }, + { path: 'albums/:id', name: 'library.albums.detail', component: LibraryAlbum, props: true }, + { path: 'tracks/:id', name: 'library.tracks.detail', component: LibraryTrack, props: true }, { path: 'import/launch', name: 'library.import.launch',