[scrobbles] Fix filtering by tags
This commit is contained in:
@ -121,6 +121,7 @@ urlpatterns = [
|
|||||||
views.ScrobbleLongPlaysView.as_view(),
|
views.ScrobbleLongPlaysView.as_view(),
|
||||||
name="long-plays",
|
name="long-plays",
|
||||||
),
|
),
|
||||||
|
path("scrobbles/", views.ScrobbleListView.as_view(), name="scrobble-list"),
|
||||||
path(
|
path(
|
||||||
"scrobbles/<slug:uuid>/",
|
"scrobbles/<slug:uuid>/",
|
||||||
views.ScrobbleDetailView.as_view(),
|
views.ScrobbleDetailView.as_view(),
|
||||||
@ -129,5 +130,4 @@ urlpatterns = [
|
|||||||
path("scrobbles/<slug:uuid>/start/", views.scrobble_start, name="start"),
|
path("scrobbles/<slug:uuid>/start/", views.scrobble_start, name="start"),
|
||||||
path("scrobbles/<slug:uuid>/finish/", views.scrobble_finish, name="finish"),
|
path("scrobbles/<slug:uuid>/finish/", views.scrobble_finish, name="finish"),
|
||||||
path("scrobbles/<slug:uuid>/cancel/", views.scrobble_cancel, name="cancel"),
|
path("scrobbles/<slug:uuid>/cancel/", views.scrobble_cancel, name="cancel"),
|
||||||
path("scrobbles/", views.ScrobbleListView.as_view(), name="scrobble-list"),
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -192,26 +192,6 @@ class ScrobbleableDetailView(ChartContextMixin, DetailView):
|
|||||||
class RecentScrobbleList(ListView):
|
class RecentScrobbleList(ListView):
|
||||||
model = Scrobble
|
model = Scrobble
|
||||||
|
|
||||||
|
|
||||||
class ScrobbleListView(LoginRequiredMixin, ListView):
|
|
||||||
model = Scrobble
|
|
||||||
paginate_by = 100
|
|
||||||
template_name = "scrobbles/scrobble_all_list.html"
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
qs = Scrobble.objects.filter(user=self.request.user).order_by("-timestamp")
|
|
||||||
tags_param = self.request.GET.get("tags", "")
|
|
||||||
if tags_param:
|
|
||||||
tag_list = [t.strip() for t in tags_param.split(",") if t.strip()]
|
|
||||||
if tag_list:
|
|
||||||
qs = qs.filter(tags__name__in=tag_list).distinct()
|
|
||||||
return qs
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
ctx = super().get_context_data(**kwargs)
|
|
||||||
ctx["tags_param"] = self.request.GET.get("tags", "")
|
|
||||||
return ctx
|
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
if user.is_authenticated:
|
if user.is_authenticated:
|
||||||
@ -324,6 +304,26 @@ class ScrobbleListView(LoginRequiredMixin, ListView):
|
|||||||
return Scrobble.objects.all().order_by("-timestamp")
|
return Scrobble.objects.all().order_by("-timestamp")
|
||||||
|
|
||||||
|
|
||||||
|
class ScrobbleListView(LoginRequiredMixin, ListView):
|
||||||
|
model = Scrobble
|
||||||
|
paginate_by = 100
|
||||||
|
template_name = "scrobbles/scrobble_all_list.html"
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = Scrobble.objects.filter(user=self.request.user).order_by("-timestamp")
|
||||||
|
tags_param = self.request.GET.get("tags", "")
|
||||||
|
if tags_param:
|
||||||
|
tag_list = [t.strip() for t in tags_param.split(",") if t.strip()]
|
||||||
|
if tag_list:
|
||||||
|
qs = qs.filter(tags__name__in=tag_list).distinct()
|
||||||
|
return qs
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
ctx["tags_param"] = self.request.GET.get("tags", "")
|
||||||
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
class ScrobbleLongPlaysView(TemplateView):
|
class ScrobbleLongPlaysView(TemplateView):
|
||||||
template_name = "scrobbles/long_plays_in_progress.html"
|
template_name = "scrobbles/long_plays_in_progress.html"
|
||||||
|
|
||||||
|
|||||||
@ -21,14 +21,16 @@
|
|||||||
<p>{{ object.logdata.description }}</p>
|
<p>{{ object.logdata.description }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
Tags: {{object.tags}}
|
|
||||||
{% if object.tags.all %}
|
|
||||||
<p>
|
<p>
|
||||||
{% for tag in object.tags.all %}
|
Tags:
|
||||||
<a href="{% url 'scrobbles:scrobble-list' %}?tag={{ tag.name }}" class="badge bg-secondary">{{ tag.name }}</a>
|
{% if object.tags.all %}
|
||||||
{% endfor %}
|
{% for tag in object.tags.all %}
|
||||||
|
<a href="{% url 'scrobbles:scrobble-list' %}?tag={{ tag.name }}" class="badge bg-secondary">{{ tag.name }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
untagged
|
||||||
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% with notes_html=object.logdata.notes_as_html %}
|
{% with notes_html=object.logdata.notes_as_html %}
|
||||||
{% if notes_html %}
|
{% if notes_html %}
|
||||||
|
|||||||
Reference in New Issue
Block a user