Skip to content

Commit

Permalink
Merge pull request #1073 from ImageMarkup/collection-filter-by-doi
Browse files Browse the repository at this point in the history
Allow filtering collections by DOI presence
  • Loading branch information
danlamanna authored Feb 5, 2025
2 parents c53a6cd + fab0f55 commit d4542a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions isic/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class Meta:
model = Collection
fields = [
"pinned",
"doi",
"shared_with_me",
"mine",
]

pinned = BooleanFilter(method="filter_pinned")
doi = BooleanFilter(method="filter_doi")
shared_with_me = BooleanFilter(method="filter_shared_with_me")
mine = BooleanFilter(method="filter_mine")

Expand All @@ -25,6 +27,9 @@ def __init__(self, *args, **kwargs):
def filter_pinned(self, qs: QuerySet, name, value):
return qs.filter(pinned=value)

def filter_doi(self, qs: QuerySet, name, value):
return qs.filter(doi__isnull=not value)

def filter_shared_with_me(self, qs: QuerySet, name, value):
if value is True and self.user.is_authenticated:
qs = qs.filter(shares=self.user)
Expand Down
12 changes: 9 additions & 3 deletions isic/core/templates/core/collection_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@
</div>
<div class="my-4">
{% url 'core/collection-list' as base %}
<a class="text-white" href="{% querystring pinned="true" shared_with_me=None mine=None %}">
<a class="text-white" href="{% querystring pinned="true" doi=None shared_with_me=None mine=None %}">
<button class="btn btn-secondary primary gap-2">
Pinned
<div class="badge badge-accent">{{ counts.pinned }}</div>
</button>
</a>
<a class="text-white" href="{% querystring pinned=None doi="true" shared_with_me=None mine=None %}">
<button class="btn btn-secondary primary gap-2">
DOI
<div class="badge badge-accent">{{ counts.doi }}</div>
</button>
</a>
{% if request.user.is_authenticated %}
<a class="text-white" href="{% querystring pinned=None shared_with_me="true" mine=None %}">
<a class="text-white" href="{% querystring pinned=None doi=None shared_with_me="true" mine=None %}">
<button class="btn btn-secondary primary gap-2">
Shared with Me
<div class="badge badge-accent">{{ counts.shared_with_me }}</div>
</button>
</a>
<a class="text-white" href="{% querystring pinned=None shared_with_me=None mine="true" %}">
<a class="text-white" href="{% querystring pinned=None doi=None shared_with_me=None mine="true" %}">
<button class="btn btn-secondary primary gap-2">
Mine
<div class="badge badge-accent">{{ counts.mine }}</div>
Expand Down
2 changes: 2 additions & 0 deletions isic/core/views/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def collection_list(request):
if request.user.is_authenticated:
counts = collections.aggregate(
pinned=Count("pk", filter=Q(pinned=True)),
doi=Count("pk", filter=Q(doi__isnull=False)),
shared_with_me=Count("pk", filter=Q(shares=request.user)),
mine=Count("pk", filter=Q(creator=request.user)),
all_=Count("pk"),
)
else:
counts = collections.aggregate(
pinned=Count("pk", filter=Q(pinned=True)),
doi=Count("pk", filter=Q(doi__isnull=False)),
all_=Count("pk"),
)

Expand Down

0 comments on commit d4542a9

Please sign in to comment.