From a72e0b0fb94a090a8dd3f290044c45bf28794510 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sat, 13 Apr 2024 15:25:13 -0400 Subject: [PATCH] [scrobbles] Add a status page --- vrobbler/apps/locations/models.py | 6 ++ vrobbler/apps/scrobbles/urls.py | 1 + vrobbler/apps/scrobbles/views.py | 31 ++++++ vrobbler/apps/webpages/models.py | 2 +- vrobbler/apps/webpages/urls.py | 4 +- vrobbler/templates/base.html | 2 - vrobbler/templates/scrobbles/status.html | 114 +++++++++++++++++++++++ 7 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 vrobbler/templates/scrobbles/status.html diff --git a/vrobbler/apps/locations/models.py b/vrobbler/apps/locations/models.py index 6d08c27..82ad44d 100644 --- a/vrobbler/apps/locations/models.py +++ b/vrobbler/apps/locations/models.py @@ -85,6 +85,12 @@ class GeoLocation(ScrobblableMixin): ) return location + @property + def subtitle(self) -> str: + if self.title: + return f"{self.lat} x {self.lon}" + return "" + def loc_diff(self, old_lat_lon: tuple) -> tuple: return ( abs(Decimal(old_lat_lon[0]) - Decimal(self.lat)), diff --git a/vrobbler/apps/scrobbles/urls.py b/vrobbler/apps/scrobbles/urls.py index 36f671c..164defa 100644 --- a/vrobbler/apps/scrobbles/urls.py +++ b/vrobbler/apps/scrobbles/urls.py @@ -4,6 +4,7 @@ from scrobbles import views app_name = "scrobbles" urlpatterns = [ + path("status/", views.ScrobbleStatusView.as_view(), name="status"), path( "manual/lookup/", views.ManualScrobbleView.as_view(), diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 772a51c..0717033 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -725,3 +725,34 @@ class ChartRecordView(TemplateView): context_data["name"] = " ".join(["Top", media_type, "for", name]) context_data["in_progress"] = in_progress return context_data + + +class ScrobbleStatusView(LoginRequiredMixin, TemplateView): + model = Scrobble + template_name = "scrobbles/status.html" + + def get_context_data(self, **kwargs): + data = super().get_context_data(**kwargs) + user_scrobble_qs = Scrobble.objects.filter().order_by("-timestamp") + progress_plays = user_scrobble_qs.filter( + in_progress=True, is_paused=False + ) + + data["listening"] = progress_plays.filter(track__isnull=False).first() + data["watching"] = progress_plays.filter(video__isnull=False).first() + data["going"] = progress_plays.filter( + geo_location__isnull=False + ).first() + data["playing"] = progress_plays.filter( + board_game__isnull=False + ).first() + + long_plays = user_scrobble_qs.filter( + long_play_complete=False, played_to_completion=True + ) + data["reading"] = long_plays.filter(book__isnull=False).first() + data["sessioning"] = long_plays.filter( + video_game__isnull=False + ).first() + + return data diff --git a/vrobbler/apps/webpages/models.py b/vrobbler/apps/webpages/models.py index ec163c8..1e67918 100644 --- a/vrobbler/apps/webpages/models.py +++ b/vrobbler/apps/webpages/models.py @@ -67,7 +67,7 @@ class WebPage(ScrobblableMixin): self.save(update_fields=["extract"]) def get_absolute_url(self): - return reverse("webpages:webpage_detail", kwargs={"slug": self.uuid}) + return reverse("webpages:webpage-detail", kwargs={"slug": self.uuid}) @property def estimated_time_to_read_in_seconds(self): diff --git a/vrobbler/apps/webpages/urls.py b/vrobbler/apps/webpages/urls.py index 1d79cb2..3892c85 100644 --- a/vrobbler/apps/webpages/urls.py +++ b/vrobbler/apps/webpages/urls.py @@ -5,10 +5,10 @@ app_name = "webpages" urlpatterns = [ - path("webpage/", views.WebPageListView.as_view(), name="webpage_list"), + path("webpage/", views.WebPageListView.as_view(), name="webpage-list"), path( "webpage//", views.WebPageDetailView.as_view(), - name="webpage_detail", + name="webpage-detail", ), ] diff --git a/vrobbler/templates/base.html b/vrobbler/templates/base.html index 5cbdbb3..b3b785a 100644 --- a/vrobbler/templates/base.html +++ b/vrobbler/templates/base.html @@ -258,10 +258,8 @@ {% for scrobble in now_playing_list %}
{% if scrobble.media_obj.primary_image_url %}
{% endif %} -

{{scrobble.media_obj.title}}

{% if scrobble.media_obj.subtitle %}

{{scrobble.media_obj.subtitle}}

{% endif %} -

{{scrobble.timestamp|naturaltime}} from {{scrobble.source}}

diff --git a/vrobbler/templates/scrobbles/status.html b/vrobbler/templates/scrobbles/status.html new file mode 100644 index 0000000..278e668 --- /dev/null +++ b/vrobbler/templates/scrobbles/status.html @@ -0,0 +1,114 @@ +{% load static %} +{% load humanize %} + + + + + + Now Playing + + + + + + + + +
+

Listening

+
+ {% if listening %} +

{{listening.media_type}}

+

{{listening.media_obj.title}}

+ {% if listening.media_obj.subtitle %}

{{listening.media_obj.subtitle}}

{% endif %} +
+

{{listening.timestamp|naturaltime}} from {{listening.source}}

+

{{listening.percent_played}}% played

+ {% else %} +
+

Nothing

+
+ {% endif %} +
+
+
+

Watching

+
+ {% if watching %} +

{{watching.media_type}}

+

{{watching.media_obj.title}}

+ {% if watching.media_obj.subtitle %}

{{watching.media_obj.subtitle}}

{% endif %} +

{{watching.timestamp|naturaltime}} from {{watching.source}}

+
+ {% else %} +
+

Nothing

+
+ {% endif %} +
+
+
+

Going

+
+ {% if going %} +

{{going.media_type}}

+

{{going.media_obj}}

+ {% if going.media_obj.subtitle %}

{{going.media_obj.subtitle}}

{% endif %} +

{{going.timestamp|naturaltime}} from {{going.source}}

+
+ {% else %} +
+

Nowhere

+
+ {% endif %} +
+
+
+

Playing

+
+ {% if playing %} +

{{playing.media_type}}

+

{{playing.media_obj}}

+ {% if playing.media_obj.subtitle %}

{{playing.media_obj.subtitle}}

{% endif %} +

{{playing.timestamp|naturaltime}} from {{playing.source}}

+
+ {% else %} +
+

Nothing

+
+ {% endif %} +
+
+
+

Reading

+
+ {% if reading %} +

{{reading.media_type}}

+

{{reading.media_obj}}

+ {% if reading.media_obj.subtitle %}

{{reading.media_obj.subtitle}}

{% endif %} +

{{reading.timestamp|naturaltime}} from {{reading.source}}

+
+ {% else %} +
+

Nothing

+
+ {% endif %} +
+
+
+

Sessioning

+
+ {% if sessioning %} +

{{sessioning.media_type}}

+

{{sessioning.media_obj}}

+ {% if sessioning.media_obj.subtitle %}

{{sessioning.media_obj.subtitle}}

{% endif %} +

{{sessioning.timestamp|naturaltime}} from {{sessioning.source}}

+
+ {% else %} +
+

Nothing

+
+ {% endif %} +
+ +