Skip to content

Commit

Permalink
Show current Category in the title
Browse files Browse the repository at this point in the history
  • Loading branch information
pehala committed Jan 28, 2024
1 parent 45d7f24 commit 7008228
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/templates/songs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{% load static %}
{% load i18n %}

{% block title %}{{ title }}{% endblock %}

{% block extra_head %}
<script async src="{% static 'js/chords.js' %}"></script>
<script defer type="text/javascript" src="{% static "datatables/datatables.min.js" %}"></script>
Expand Down
9 changes: 9 additions & 0 deletions backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def get_queryset(self):
queryset = queryset.filter(archived=False)
return queryset

def get_title(self):
"""Return title of this song set"""
return self.request.tenant.display_name

def get_context_data(self, *, object_list=None, **kwargs):
context_data = super().get_context_data(object_list=object_list, **kwargs)

Expand All @@ -59,6 +63,7 @@ def get_context_data(self, *, object_list=None, **kwargs):
i += 1

context_data["songs"] = json.dumps(songs, cls=DjangoJSONEncoder)
context_data["title"] = self.get_title()
return context_data


Expand All @@ -68,6 +73,10 @@ class AllSongListView(BaseSongListView):
def get_queryset(self):
return super().get_queryset().filter(categories__tenant=self.request.tenant)

def get_title(self):
"""Return title of this song set"""
return f'{_("All Songs")} | {self.request.tenant.display_name}'


class IndexSongListView(RedirectView):
"""Shows first available category"""
Expand Down
10 changes: 9 additions & 1 deletion category/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ class CategorySongsListView(BaseSongListView, AnalyticsMixin):
def get_key(self):
return self.kwargs["slug"]

def category_queryset(self):
"""Returns queryset for this category"""
return Category.objects.filter(slug=self.kwargs["slug"], tenant=self.request.tenant)

def get_queryset(self):
slug = self.kwargs["slug"]
if not Category.objects.filter(slug=slug, tenant=self.request.tenant).exists():
if not self.category_queryset().exists():
raise Http404(_("Category with url /%(slug)s does not exist") % {"slug": slug})
return super().get_queryset().filter(categories__slug=slug)

def get_title(self):
"""Return title of this song set"""
return f"{self.category_queryset().get().name} | {self.request.tenant.display_name}"


class CategoryListView(LocalAdminRequired, ListView):
"""Lists all categories"""
Expand Down

0 comments on commit 7008228

Please sign in to comment.