From 85a91b340ab62834c87da4bc557a25a41792362f Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 24 Nov 2023 01:33:33 +0100 Subject: [PATCH] Add location templates --- vrobbler/apps/locations/admin.py | 3 + vrobbler/apps/locations/urls.py | 18 ++++ vrobbler/apps/locations/views.py | 23 ++++- vrobbler/apps/scrobbles/stats.py | 4 + .../locations/geolocation_detail.html | 80 ++++++++++++++++ .../templates/locations/geolocation_list.html | 94 +++++++++++++++++++ vrobbler/urls.py | 2 + 7 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 vrobbler/apps/locations/urls.py create mode 100644 vrobbler/templates/locations/geolocation_detail.html create mode 100644 vrobbler/templates/locations/geolocation_list.html diff --git a/vrobbler/apps/locations/admin.py b/vrobbler/apps/locations/admin.py index 28ef572..d8d80b7 100644 --- a/vrobbler/apps/locations/admin.py +++ b/vrobbler/apps/locations/admin.py @@ -18,6 +18,9 @@ class GeoLocationAdmin(admin.ModelAdmin): "lat", "lon", ) + inlines = [ + ScrobbleInline, + ] @admin.register(RawGeoLocation) diff --git a/vrobbler/apps/locations/urls.py b/vrobbler/apps/locations/urls.py new file mode 100644 index 0000000..4cf8258 --- /dev/null +++ b/vrobbler/apps/locations/urls.py @@ -0,0 +1,18 @@ +from django.urls import path +from locations import views + +app_name = "locations" + + +urlpatterns = [ + path( + "locations/", + views.GeoLocationListView.as_view(), + name="geo_locations_list", + ), + path( + "locations//", + views.GeoLocationDetailView.as_view(), + name="geo_location_detail", + ), +] diff --git a/vrobbler/apps/locations/views.py b/vrobbler/apps/locations/views.py index e5a0d9b..772bdc6 100644 --- a/vrobbler/apps/locations/views.py +++ b/vrobbler/apps/locations/views.py @@ -1 +1,22 @@ -#!/usr/bin/env python3 +from django.db.models import Count +from django.views import generic +from locations.models import GeoLocation +from scrobbles.stats import get_scrobble_count_qs + + +class GeoLocationListView(generic.ListView): + model = GeoLocation + paginate_by = 200 + + def get_queryset(self): + return super().get_queryset().order_by("-created") + + 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(generic.DetailView): + model = GeoLocation + slug_field = "uuid" diff --git a/vrobbler/apps/scrobbles/stats.py b/vrobbler/apps/scrobbles/stats.py index b731561..a95913d 100644 --- a/vrobbler/apps/scrobbles/stats.py +++ b/vrobbler/apps/scrobbles/stats.py @@ -47,6 +47,10 @@ def get_scrobble_count_qs( data_model = apps.get_model( app_label="sports", model_name="SportEvent" ) + if model_str == "GeoLocation": + data_model = apps.get_model( + app_label="locations", model_name="GeoLocation" + ) if model_str == "Artist": base_qs = data_model.objects.filter( diff --git a/vrobbler/templates/locations/geolocation_detail.html b/vrobbler/templates/locations/geolocation_detail.html new file mode 100644 index 0000000..6022b29 --- /dev/null +++ b/vrobbler/templates/locations/geolocation_detail.html @@ -0,0 +1,80 @@ +{% extends "base_list.html" %} +{% load mathfilters %} +{% load static %} +{% load naturalduration %} + +{% block title %}{{object.title}}{% endblock %} + +{% block head_extra %} + + + + + {% endblock %} + + {% block extra_js %} + + + +{% endblock %} + +{% block lists %} + +
+
+ +

+

+
+ {{object.lat}} + {% if object.summary %} +

{{object.summary|safe|linebreaks|truncatewords:160}}

+
+ {% endif %} +

+

+
+
+
+

{{object.scrobble_set.count}} scrobbles

+
+
+

Last scrobbles

+
+ + + + + + + + + + + {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + + + + + + + {% endfor %} + +
DateCompletedPages readAuthors
{{scrobble.timestamp}}{% if scrobble.long_play_complete == True %}Yes{% endif %}{% if scrobble.in_progress %}Now reading{% else %}{{scrobble.session_pages_read}}{% endif %}{% for author in scrobble.book.authors.all %}{{author}}{% if not forloop.last %}, {% endif %}{% endfor %}
+
+
+
+{% endblock %} diff --git a/vrobbler/templates/locations/geolocation_list.html b/vrobbler/templates/locations/geolocation_list.html new file mode 100644 index 0000000..295c034 --- /dev/null +++ b/vrobbler/templates/locations/geolocation_list.html @@ -0,0 +1,94 @@ +{% extends "base_list.html" %} +{% load urlreplace %} + +{% block title %}Locations{% endblock %} + +{% block head_extra %} + + + + + {% endblock %} + + {% block extra_js %} + + + +{% endblock %} + +{% block lists %} + +
+
+
+
+

+ + {% if page_obj.has_previous %} + prev + {% endif %} + + Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }} + + {% if page_obj.has_next %} + next + {% endif %} + +

+
+ +
+
+ + + + + + + + + {% for location in object_list %} + + + + + {% endfor %} + +
ScrobblesPoint
{{location.scrobbles.count}}{{location.lat}}x{{location.lon}}
+
+
+ + +
+{% endblock %} diff --git a/vrobbler/urls.py b/vrobbler/urls.py index cb853cd..3709b2c 100644 --- a/vrobbler/urls.py +++ b/vrobbler/urls.py @@ -10,6 +10,7 @@ from vrobbler.apps.sports import urls as sports_urls from vrobbler.apps.podcasts import urls as podcast_urls from vrobbler.apps.videogames import urls as videogame_urls from vrobbler.apps.boardgames import urls as boardgame_urls +from vrobbler.apps.locations import urls as locations_urls from vrobbler.apps.music.api.views import ( AlbumViewSet, ArtistViewSet, @@ -66,6 +67,7 @@ urlpatterns = [ path("", include(videogame_urls, namespace="videogames")), path("", include(boardgame_urls, namespace="boardgames")), path("", include(sports_urls, namespace="sports")), + path("", include(locations_urls, namespace="locations")), path("", include(podcast_urls, namespace="podcasts")), path("", include(scrobble_urls, namespace="scrobbles")), path(