Skip to content

Commit

Permalink
Add facet counts to InstrumentListView context
Browse files Browse the repository at this point in the history
  • Loading branch information
dchiller committed Oct 18, 2023
1 parent b500dc9 commit 093301a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions web-app/django/VIM/apps/instruments/views/instrument_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.views.generic import ListView
from VIM.apps.instruments.models import Instrument, Language
import requests


class InstrumentList(ListView):
Expand Down Expand Up @@ -33,6 +34,23 @@ def get_context_data(self, **kwargs):
if active_language_en
else Language.objects.get(en_label="english") # default in English
)
hbs_facets = requests.get(
"http://solr:8983/solr/virtual-instrument-museum/select?facet.pivot=hbs_prim_cat_label_s,hbs_sec_cat_label_s&facet=true&indent=true&q=*:*&rows=0"
).json()["facet_counts"]["facet_pivot"][
"hbs_prim_cat_label_s,hbs_sec_cat_label_s"
]
hbs_facet_list = []
for hbs_prim_cat in hbs_facets:
hbs_facet_list.append(
{
hbs_prim_cat["value"]: hbs_prim_cat["count"],
"children": {
hbs_sec_cat["value"]: hbs_sec_cat["count"]
for hbs_sec_cat in hbs_prim_cat["pivot"]
},
}
)
context["hbs_facets"] = hbs_facet_list
return context

def get(self, request, *args, **kwargs):
Expand Down

0 comments on commit 093301a

Please sign in to comment.