Extensions list: sort_by parameter #159
@ -27,15 +27,13 @@
|
||||
<button class="align-items-center d-flex dropdown-toggle js-dropdown-toggle" data-toggle-menu-id="js-dropdown-menu-filter">
|
||||
{% if tag %}
|
||||
{{ 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">
|
||||
1
|
||||
{{ current_tag_count }}
|
||||
</div>
|
||||
{% else %}
|
||||
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">
|
||||
1
|
||||
{{ total_count }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@ -48,7 +46,7 @@
|
||||
<a class="dropdown-item {% if not tag.name %}is-active{% endif %}" href="/{{ tag.get_type_display|slugify }}s/">
|
||||
All
|
||||
<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>
|
||||
</a>
|
||||
</li>
|
||||
@ -57,9 +55,8 @@
|
||||
<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 }}">
|
||||
{{ 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">
|
||||
1
|
||||
{{list_tag.count}}
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
|
||||
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.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'])
|
||||
|
||||
# Determine which tags to list depending on the context.
|
||||
tag_type_id = None
|
||||
if context.get('type'):
|
||||
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'):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user