mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 17:52:21 +01:00
Merge branch 'fix/manage-page-shows-all-songs' into 'marietje-zuid'
Show only songs that match the user on manage page Closes #45 See merge request technicie/MarietjeDjango!66
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.generics import ListAPIView, RetrieveAPIView, CreateAPIView
|
||||
from rest_framework import filters
|
||||
from rest_framework.views import APIView
|
||||
@ -16,7 +17,8 @@ class SongsListAPIView(ListAPIView):
|
||||
queryset = Song.objects.all()
|
||||
permission_classes = [IsAuthenticatedOrTokenHasScopeForMethod]
|
||||
required_scopes_for_method = {"GET": ["read"]}
|
||||
filter_backends = (filters.SearchFilter, filters.OrderingFilter)
|
||||
filter_backends = (filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend)
|
||||
filterset_fields = ["user__username", "artist"]
|
||||
search_fields = ["artist", "title", "user__name", "user__username"]
|
||||
ordering_fields = [
|
||||
"artist",
|
||||
|
||||
@ -74,6 +74,7 @@
|
||||
typing_timer: null,
|
||||
page_size: 10,
|
||||
page_number: 1,
|
||||
user_data: null,
|
||||
},
|
||||
watch: {
|
||||
search_input: {
|
||||
@ -112,25 +113,18 @@
|
||||
}
|
||||
},
|
||||
created() {
|
||||
fetch(
|
||||
`/api/v1/songs/?ordering=artist,title&limit=${this.page_size}&offset=${this.page_size * (this.page_number - 1)}`
|
||||
).then(response => {
|
||||
fetch('/api/v1/users/me/').then(response => {
|
||||
if (response.status === 200) {
|
||||
return response.json();
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
}).then(data => {
|
||||
this.songs = data.results;
|
||||
this.total_songs = data.count;
|
||||
}).catch((e) => {
|
||||
if (e instanceof Response) {
|
||||
e.json().then(data => {
|
||||
tata.error("", data.errorMessage);
|
||||
});
|
||||
} else {
|
||||
tata.error("", "An unknown error occurred, please try again.")
|
||||
}
|
||||
this.user_data = data;
|
||||
}).then(() => {
|
||||
this.refresh();
|
||||
}).catch(() => {
|
||||
tata.error('', 'User details failed to fetch, please reload this page to try again.');
|
||||
});
|
||||
const stored_page_size = parseInt(getCookie("MANAGE_PAGE_SIZE"));
|
||||
if (stored_page_size !== Number.NaN && stored_page_size > 0) {
|
||||
@ -144,7 +138,7 @@
|
||||
},
|
||||
refresh() {
|
||||
fetch(
|
||||
`/api/v1/songs/?ordering=artist,title&limit=${this.page_size}&offset=${this.page_size * (this.page_number - 1)}&search=${this.search_input}`,
|
||||
`/api/v1/songs/?ordering=artist,title&user__username=${this.user_data.username}&limit=${this.page_size}&offset=${this.page_size * (this.page_number - 1)}&search=${this.search_input}`,
|
||||
{
|
||||
headers: {
|
||||
"X-CSRFToken": CSRF_TOKEN,
|
||||
|
||||
Reference in New Issue
Block a user