Extensions list: sort_by parameter #159

Merged
Márton Lente merged 36 commits from filter-sort into main 2024-06-03 12:57:45 +02:00
2 changed files with 29 additions and 10 deletions
Showing only changes of commit 631f9ec0d7 - Show all commits

View File

@ -27,15 +27,13 @@
<button class="align-items-center d-flex dropdown-toggle js-dropdown-toggle" data-toggle-menu-id="js-dropdown-menu-filter"> <button class="align-items-center d-flex dropdown-toggle js-dropdown-toggle" data-toggle-menu-id="js-dropdown-menu-filter">
{% if tag %} {% if tag %}
{{ tag.name }} {{ tag.name }}
{# TODO: @back-end add tags count dynamic #}
<div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4"> <div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4">
1 {{ current_tag_count }}
</div> </div>
{% else %} {% else %}
All All
{# TODO: @back-end add tags count dynamic #}
<div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4"> <div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4">
1 {{ total_count }}
</div> </div>
{% endif %} {% endif %}
@ -48,7 +46,7 @@
<a class="dropdown-item {% if not tag.name %}is-active{% endif %}" href="/{{ tag.get_type_display|slugify }}s/"> <a class="dropdown-item {% if not tag.name %}is-active{% endif %}" href="/{{ tag.get_type_display|slugify }}s/">
All All
<div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4"> <div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4">
1 {{ total_count }}
</div> </div>
</a> </a>
</li> </li>
@ -57,9 +55,8 @@
<li> <li>
<a class="dropdown-item {% if tag.name == list_tag.name %}is-active{% endif %}" href="{% url "extensions:by-tag" tag_slug=list_tag.slug %}" title="{{ list_tag.name }}"> <a class="dropdown-item {% if tag.name == list_tag.name %}is-active{% endif %}" href="{% url "extensions:by-tag" tag_slug=list_tag.slug %}" title="{{ list_tag.name }}">
{{ list_tag.name }} {{ list_tag.name }}
<div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4"> <div class="align-items-center bg-tertiary d-flex h-4 fs-xs justify-content-center ms-2 rounded-circle w-4">
1 {{list_tag.count}}
</div> </div>
</a> </a>
</li> </li>

View File

@ -1,7 +1,7 @@
import logging import logging
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db.models import Q from django.db.models import Count, Q
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.views.generic.list import ListView from django.views.generic.list import ListView
@ -122,11 +122,33 @@ class SearchView(ListedExtensionsView):
context['team'] = get_object_or_404(teams.models.Team, slug=self.kwargs['team_slug']) context['team'] = get_object_or_404(teams.models.Team, slug=self.kwargs['team_slug'])
# Determine which tags to list depending on the context. # Determine which tags to list depending on the context.
tag_type_id = None
if context.get('type'): if context.get('type'):
tag_type_id = self._get_type_id_by_slug() tag_type_id = self._get_type_id_by_slug()
context['tags'] = Tag.objects.filter(type=tag_type_id).exclude(versions=None)
elif context.get('tag'): elif context.get('tag'):
tag_type_id = context['tag'].type tag_type_id = context['tag'].type
context['tags'] = Tag.objects.filter(type=tag_type_id).exclude(versions=None) if tag_type_id:
tags = [
{
'count': t['count'],
'name': t['latest_version__tags__name'],
'slug': t['latest_version__tags__slug'],
}
for t in Extension.objects.listed.select_related('latest_version__tags')
.filter(latest_version__tags__type=tag_type_id)
.values('latest_version__tags__name', 'latest_version__tags__slug')
.annotate(count=Count('id'))
.order_by('latest_version__tags__name')
]
context['tags'] = tags
if 'tag' in context:
# this is silly, but the list is short
tag_slug = context['tag'].slug
for t in tags:
if t['slug'] == tag_slug:
context['current_tag_count'] = t['count']
break
context['total_count'] = super().get_queryset().filter(type=tag_type_id).count()
return context return context