Files
vrobbler/vrobbler/apps/trails/views.py
Colin Powell d036dbe4fd
All checks were successful
build & deploy / test (push) Successful in 1m57s
build & deploy / build-and-deploy (push) Successful in 31s
[trails] Use latest scrobble for trail map
2026-05-22 11:40:10 -04:00

27 lines
747 B
Python

from django.apps import apps
from trails.models import Trail
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
class TrailListView(ScrobbleableListView):
model = Trail
class TrailDetailView(ScrobbleableDetailView):
model = Trail
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Scrobble = apps.get_model("scrobbles", "Scrobble")
context["trail_gpx_url"] = None
latest = (
Scrobble.objects.filter(trail=self.object, gpx_file__isnull=False)
.order_by("-timestamp")
.first()
)
if latest and latest.gpx_file:
context["trail_gpx_url"] = latest.gpx_file.url
return context