diff --git a/vrobbler/apps/profiles/migrations/0010_userprofile_redirect_to_webpage.py b/vrobbler/apps/profiles/migrations/0010_userprofile_redirect_to_webpage.py new file mode 100644 index 0000000..1140fd2 --- /dev/null +++ b/vrobbler/apps/profiles/migrations/0010_userprofile_redirect_to_webpage.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-12-11 19:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("profiles", "0009_userprofile_retroarch_auto_import_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="userprofile", + name="redirect_to_webpage", + field=models.BooleanField(default=True), + ), + ] diff --git a/vrobbler/apps/profiles/models.py b/vrobbler/apps/profiles/models.py index c68b47b..c623c3a 100644 --- a/vrobbler/apps/profiles/models.py +++ b/vrobbler/apps/profiles/models.py @@ -28,6 +28,8 @@ class UserProfile(TimeStampedModel): retroarch_path = models.CharField(max_length=255, **BNULL) retroarch_auto_import = models.BooleanField(default=False) + redirect_to_webpage = models.BooleanField(default=True) + def __str__(self): return f"User profile for {self.user}" diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 0753946..911c9f4 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -100,29 +100,29 @@ class RecentScrobbleList(ListView): limit = 14 artist = {"user": user, "media_type": "Artist", "limit": limit} - #This is weird. They don't display properly as QuerySets, so we cast to lists + # This is weird. They don't display properly as QuerySets, so we cast to lists data["chart_keys"] = { - "today": "Today", - "last7": "Last 7 days", - "last30": "Last 30 days", - "year": "This year", - "all": "All time", + "today": "Today", + "last7": "Last 7 days", + "last30": "Last 30 days", + "year": "This year", + "all": "All time", } data["current_artist_charts"] = { - "today": list(live_charts(**artist, chart_period="today")), - "last7": list(live_charts(**artist, chart_period="last7")), - "last30": list(live_charts(**artist, chart_period="last30")), - "year": list(live_charts(**artist, chart_period="year")), - "all": list(live_charts(**artist)), + "today": list(live_charts(**artist, chart_period="today")), + "last7": list(live_charts(**artist, chart_period="last7")), + "last30": list(live_charts(**artist, chart_period="last30")), + "year": list(live_charts(**artist, chart_period="year")), + "all": list(live_charts(**artist)), } track = {"user": user, "media_type": "Track", "limit": limit} data["current_track_charts"] = { - "today": list(live_charts(**track, chart_period="today")), - "last7": list(live_charts(**track, chart_period="last7")), - "last30": list(live_charts(**track, chart_period="last30")), - "year": list(live_charts(**track, chart_period="year")), - "all": list(live_charts(**track)), + "today": list(live_charts(**track, chart_period="today")), + "last7": list(live_charts(**track, chart_period="last7")), + "last30": list(live_charts(**track, chart_period="last30")), + "year": list(live_charts(**track, chart_period="year")), + "all": list(live_charts(**track)), } data["counts"] = scrobble_counts(user) else: @@ -222,7 +222,11 @@ class ManualScrobbleView(FormView): key, item_id = item_str[:2], item_str[3:] scrobble_fn = MANUAL_SCROBBLE_FNS[key] - eval(scrobble_fn)(item_id, self.request.user.id) + scrobble = eval(scrobble_fn)(item_id, self.request.user.id) + + if self.request.user.profile.redirect_to_webpage and key == "-w": + logger.info(f"Redirecting to {scrobble.media_obj} detail page") + return HttpResponseRedirect(scrobble.media_obj.get_absolute_url()) return HttpResponseRedirect(self.request.META.get("HTTP_REFERER")) @@ -445,6 +449,13 @@ def scrobble_start(request, uuid): messages.add_message( request, messages.ERROR, f"Media with uuid {uuid} not found." ) + + if ( + user.profile.redirect_on_webpage + and media_obj.__class__.__name__ == Scrobble.MediaType.WEBPAGE + ): + logger.info(f"Redirecting to {media_obj} detail apge") + return HttpResponseRedirect(media_obj.get_absolute_url()) return HttpResponseRedirect(success_url) diff --git a/vrobbler/apps/webpages/models.py b/vrobbler/apps/webpages/models.py index dcff57e..ba30b4c 100644 --- a/vrobbler/apps/webpages/models.py +++ b/vrobbler/apps/webpages/models.py @@ -54,6 +54,10 @@ class WebPage(ScrobblableMixin): words = len(self.extract.split(" ")) return int(words / words_per_minute) * 60 + @property + def estimated_time_to_read_in_minutes(self): + return int(self.estimated_time_to_read_in_seconds / 60) + @property def subtitle(self): return self.domain diff --git a/vrobbler/templates/webpages/webpage_detail.html b/vrobbler/templates/webpages/webpage_detail.html index cd42ff1..af8fb19 100644 --- a/vrobbler/templates/webpages/webpage_detail.html +++ b/vrobbler/templates/webpages/webpage_detail.html @@ -7,15 +7,16 @@ {% endblock %} {% block lists %}