27 lines
747 B
Python
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
|