Add webpage pages and redirect
This commit is contained in:
@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -28,6 +28,8 @@ class UserProfile(TimeStampedModel):
|
|||||||
retroarch_path = models.CharField(max_length=255, **BNULL)
|
retroarch_path = models.CharField(max_length=255, **BNULL)
|
||||||
retroarch_auto_import = models.BooleanField(default=False)
|
retroarch_auto_import = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
redirect_to_webpage = models.BooleanField(default=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"User profile for {self.user}"
|
return f"User profile for {self.user}"
|
||||||
|
|
||||||
|
|||||||
@ -100,29 +100,29 @@ class RecentScrobbleList(ListView):
|
|||||||
|
|
||||||
limit = 14
|
limit = 14
|
||||||
artist = {"user": user, "media_type": "Artist", "limit": limit}
|
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"] = {
|
data["chart_keys"] = {
|
||||||
"today": "Today",
|
"today": "Today",
|
||||||
"last7": "Last 7 days",
|
"last7": "Last 7 days",
|
||||||
"last30": "Last 30 days",
|
"last30": "Last 30 days",
|
||||||
"year": "This year",
|
"year": "This year",
|
||||||
"all": "All time",
|
"all": "All time",
|
||||||
}
|
}
|
||||||
data["current_artist_charts"] = {
|
data["current_artist_charts"] = {
|
||||||
"today": list(live_charts(**artist, chart_period="today")),
|
"today": list(live_charts(**artist, chart_period="today")),
|
||||||
"last7": list(live_charts(**artist, chart_period="last7")),
|
"last7": list(live_charts(**artist, chart_period="last7")),
|
||||||
"last30": list(live_charts(**artist, chart_period="last30")),
|
"last30": list(live_charts(**artist, chart_period="last30")),
|
||||||
"year": list(live_charts(**artist, chart_period="year")),
|
"year": list(live_charts(**artist, chart_period="year")),
|
||||||
"all": list(live_charts(**artist)),
|
"all": list(live_charts(**artist)),
|
||||||
}
|
}
|
||||||
|
|
||||||
track = {"user": user, "media_type": "Track", "limit": limit}
|
track = {"user": user, "media_type": "Track", "limit": limit}
|
||||||
data["current_track_charts"] = {
|
data["current_track_charts"] = {
|
||||||
"today": list(live_charts(**track, chart_period="today")),
|
"today": list(live_charts(**track, chart_period="today")),
|
||||||
"last7": list(live_charts(**track, chart_period="last7")),
|
"last7": list(live_charts(**track, chart_period="last7")),
|
||||||
"last30": list(live_charts(**track, chart_period="last30")),
|
"last30": list(live_charts(**track, chart_period="last30")),
|
||||||
"year": list(live_charts(**track, chart_period="year")),
|
"year": list(live_charts(**track, chart_period="year")),
|
||||||
"all": list(live_charts(**track)),
|
"all": list(live_charts(**track)),
|
||||||
}
|
}
|
||||||
data["counts"] = scrobble_counts(user)
|
data["counts"] = scrobble_counts(user)
|
||||||
else:
|
else:
|
||||||
@ -222,7 +222,11 @@ class ManualScrobbleView(FormView):
|
|||||||
|
|
||||||
key, item_id = item_str[:2], item_str[3:]
|
key, item_id = item_str[:2], item_str[3:]
|
||||||
scrobble_fn = MANUAL_SCROBBLE_FNS[key]
|
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"))
|
return HttpResponseRedirect(self.request.META.get("HTTP_REFERER"))
|
||||||
|
|
||||||
@ -445,6 +449,13 @@ def scrobble_start(request, uuid):
|
|||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.ERROR, f"Media with uuid {uuid} not found."
|
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)
|
return HttpResponseRedirect(success_url)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -54,6 +54,10 @@ class WebPage(ScrobblableMixin):
|
|||||||
words = len(self.extract.split(" "))
|
words = len(self.extract.split(" "))
|
||||||
return int(words / words_per_minute) * 60
|
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
|
@property
|
||||||
def subtitle(self):
|
def subtitle(self):
|
||||||
return self.domain
|
return self.domain
|
||||||
|
|||||||
@ -7,15 +7,16 @@
|
|||||||
<style>
|
<style>
|
||||||
.webpage-body {float:left: width:500px; margin-right:10px; font-size:larger;}
|
.webpage-body {float:left: width:500px; margin-right:10px; font-size:larger;}
|
||||||
.webpage-body br { margin-bottom: 1em; }
|
.webpage-body br { margin-bottom: 1em; }
|
||||||
.webpage-source {float:left; width:600px; margin-left:10px;}
|
.webpage-metadata {float:left; width:600px; padding:20px 0px 0px 20px; margin-bottom:10px; border: 1px solid #aaa;}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block lists %}
|
{% block lists %}
|
||||||
<div class="row webpage">
|
<div class="row webpage">
|
||||||
|
|
||||||
<div class="webpage-source">
|
<div class="webpage-metadata">
|
||||||
<p>Source: <a href="{{object.url}}">{{object.url}}</a></p>
|
<p>Source: <a href="{{object.url}}">{{object.url}}</a></p>
|
||||||
|
<p>Time to read: {{object.estimated_time_to_read_in_minutes}} minutes</p>
|
||||||
</div>
|
</div>
|
||||||
{% if object.extract %}
|
{% if object.extract %}
|
||||||
<div class="webpage-body">
|
<div class="webpage-body">
|
||||||
|
|||||||
Reference in New Issue
Block a user