Files
vrobbler/vrobbler/apps/locations/views.py
Colin Powell 2b88f89794
All checks were successful
build & deploy / test (push) Successful in 1m42s
build & deploy / build-and-deploy (push) Successful in 27s
[locations] Update view to show all locations
2026-05-20 13:29:09 -04:00

43 lines
1.2 KiB
Python

from django.db.models import Count
from django.urls import reverse_lazy
from django.views import generic
from locations.models import GeoLocation
from scrobbles.stats import get_scrobble_count_qs
from scrobbles.views import ChartContextMixin
class GeoLocationListView(generic.ListView):
model = GeoLocation
paginate_by = 100
def get_queryset(self):
return (
super()
.get_queryset()
.filter(scrobble__user_id=self.request.user.id)
.order_by("-scrobble__timestamp")
)
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
context_data["latest"] = self.get_queryset().first()
return context_data
class GeoLocationDetailView(ChartContextMixin, generic.DetailView):
model = GeoLocation
slug_field = "uuid"
class GeoLocationUpdateView(generic.UpdateView):
model = GeoLocation
fields = ["title", "base_run_time_seconds"]
slug_field = "uuid"
template_name = "locations/geolocation_form.html"
success_url = reverse_lazy("locations:geolocation_list")
def get_success_url(self):
return reverse_lazy(
"locations:geolocation_detail", kwargs={"slug": self.object.uuid}
)