Skip to content

Commit

Permalink
Merge pull request #267 from ya-pekatoros/multi-choice-labels-feature
Browse files Browse the repository at this point in the history
Add multi filter for repositories labels
  • Loading branch information
fey committed Apr 8, 2023
2 parents 4902e0d + 9e816fc commit 3417435
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions contributors/admin/label.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.contrib import admin
from django.db import models
from django.db.models.functions import Lower

from contributors.admin.custom import site
from contributors.admin.repository import RepoLabelInline
Expand All @@ -11,4 +13,6 @@ class LabelAdmin(admin.ModelAdmin):
inlines = (RepoLabelInline,)


models.CharField.register_lookup(Lower)

site.register(Label, LabelAdmin)
8 changes: 4 additions & 4 deletions contributors/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def get_queryset(self): # noqa: WPS615
"""Get a dataset."""
labels_param = self.request.GET.get('labels')
if labels_param:
for label in labels_param.split('.'):
self.queryset = self.queryset.filter(
labels__name__iexact=label,
)
labels_param = labels_param.split('.')
self.queryset = self.queryset.filter(
labels__name__lower__in=labels_param,
)
return super().get_queryset()


Expand Down
2 changes: 2 additions & 0 deletions contributors/views/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class ListView(

def get_context_data(self, **kwargs):
"""Add context."""
all_labels = Label.objects.all()
labels = Label.objects.filter(
repository__id__in=self.get_queryset(),
).distinct()

context = super().get_context_data(**kwargs)
context['all_labels'] = all_labels
context['labels'] = labels
return context
4 changes: 2 additions & 2 deletions templates/components/repo_tags_list.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% load i18n contrib_extras %}

<div class="my-3">
{% for label in labels %}
{% for label in all_labels %}
<a href="{% url 'contributors:repositories_list' %}{% get_label_query_string label|lower %}"
class="text-decoration-none">
<span class="badge bg-primary">{{ label }}</span>
<span class="badge bg-primary {% if label not in labels %} bg-secondary {% endif %}">{{ label }}</span>
</a>
{% endfor %}
</div>
Expand Down

0 comments on commit 3417435

Please sign in to comment.