[views] Clean up base scrobblable views
This commit is contained in:
@ -1,15 +1,15 @@
|
|||||||
from django.views import generic
|
from django.views import generic
|
||||||
from books.models import Book, Author
|
from books.models import Book, Author
|
||||||
|
|
||||||
|
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
|
||||||
|
|
||||||
class BookListView(generic.ListView):
|
|
||||||
|
class BookListView(ScrobbleableListView):
|
||||||
model = Book
|
model = Book
|
||||||
paginate_by = 20
|
|
||||||
|
|
||||||
|
|
||||||
class BookDetailView(generic.DetailView):
|
class BookDetailView(ScrobbleableDetailView):
|
||||||
model = Book
|
model = Book
|
||||||
slug_field = "uuid"
|
|
||||||
|
|
||||||
|
|
||||||
class AuthorDetailView(generic.DetailView):
|
class AuthorDetailView(generic.DetailView):
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
from django.db.models import Count
|
|
||||||
from django.views import generic
|
|
||||||
from moods.models import Mood
|
from moods.models import Mood
|
||||||
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
|
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
|
||||||
|
|
||||||
|
|||||||
@ -4,20 +4,15 @@ from music.models import Album, Artist, Track
|
|||||||
from scrobbles.models import ChartRecord
|
from scrobbles.models import ChartRecord
|
||||||
from scrobbles.stats import get_scrobble_count_qs
|
from scrobbles.stats import get_scrobble_count_qs
|
||||||
|
|
||||||
|
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
|
||||||
|
|
||||||
class TrackListView(generic.ListView):
|
|
||||||
|
class TrackListView(ScrobbleableListView):
|
||||||
model = Track
|
model = Track
|
||||||
paginate_by = 200
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return get_scrobble_count_qs(user=self.request.user).order_by(
|
|
||||||
"-scrobble_count"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TrackDetailView(generic.DetailView):
|
class TrackDetailView(ScrobbleableDetailView):
|
||||||
model = Track
|
model = Track
|
||||||
slug_field = "uuid"
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context_data = super().get_context_data(**kwargs)
|
context_data = super().get_context_data(**kwargs)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from videos.models import Series, Video
|
from videos.models import Series, Video
|
||||||
|
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
|
||||||
|
|
||||||
|
|
||||||
class MovieListView(LoginRequiredMixin, generic.ListView):
|
class MovieListView(LoginRequiredMixin, generic.ListView):
|
||||||
@ -33,6 +34,9 @@ class SeriesDetailView(LoginRequiredMixin, generic.DetailView):
|
|||||||
return context_data
|
return context_data
|
||||||
|
|
||||||
|
|
||||||
class VideoDetailView(LoginRequiredMixin, generic.DetailView):
|
class VideoListView(ScrobbleableListView):
|
||||||
|
model = Video
|
||||||
|
|
||||||
|
|
||||||
|
class VideoDetailView(ScrobbleableDetailView):
|
||||||
model = Video
|
model = Video
|
||||||
slug_field = "uuid"
|
|
||||||
|
|||||||
@ -7,29 +7,15 @@ from django.views import generic
|
|||||||
from webpages.forms import WebPageReadForm
|
from webpages.forms import WebPageReadForm
|
||||||
from webpages.models import WebPage
|
from webpages.models import WebPage
|
||||||
|
|
||||||
|
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
|
||||||
|
|
||||||
class WebPageListView(LoginRequiredMixin, generic.ListView):
|
|
||||||
|
class WebPageListView(ScrobbleableListView):
|
||||||
model = WebPage
|
model = WebPage
|
||||||
paginate_by = 20
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return (
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.annotate(scrobble_count=Count("scrobble"))
|
|
||||||
.order_by("-scrobble_count")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WebPageDetailView(LoginRequiredMixin, generic.DetailView):
|
class WebPageDetailView(ScrobbleableDetailView):
|
||||||
model = WebPage
|
model = WebPage
|
||||||
slug_field = "uuid"
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
user = self.request.user
|
|
||||||
context_data = super().get_context_data(**kwargs)
|
|
||||||
context_data["scrobbles"] = self.object.scrobbles(user)
|
|
||||||
return context_data
|
|
||||||
|
|
||||||
|
|
||||||
class WebPageReadView(
|
class WebPageReadView(
|
||||||
|
|||||||
Reference in New Issue
Block a user