Skip to content

Commit

Permalink
Merge pull request #179 from acdh-oeaw/ms/142-add-Akademiepreise-to-f…
Browse files Browse the repository at this point in the history
…ilter-for-Preise

fix: changes search for Preise to autocomplete
  • Loading branch information
sennierer authored Nov 10, 2023
2 parents 29b99d8 + bca5224 commit ac402a6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
21 changes: 21 additions & 0 deletions paas_theme/autocompletes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ def get_queryset(self):
return SearchQuerySet().filter(query_object)


class PaasPreiseAutocomplete(autocomplete.Select2QuerySetView):
f = {"django_ct": "apis_entities.institution", "kind": "Preis"}

def get_result_value(self, result):
return f"{result.pk}|{result.name}"

def get_result_label(self, item):
lbl = item.name
date = get_date_label(item)
if date:
lbl += f" {date}"
return lbl

def get_queryset(self):
query_object = SQ(**self.f)
if self.q:
query_object &= SQ(name__contains=self.q)
return SearchQuerySet().filter(query_object)



class PaasInstitutionAutocomplete(autocomplete.Select2QuerySetView):
f = {"django_ct": "apis_entities.institution", "academy": False}

Expand Down
27 changes: 18 additions & 9 deletions paas_theme/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(self, *args, **kwargs):
AccordionGroup(
"Wissenschaftler/innen/austausch", "wiss_austausch"
),
AccordionGroup("Auszeichnungen", "nobelpreis", "ewk"),
AccordionGroup("Auszeichnungen", "preise"),
),
css_class="col-md-6 pt-30 pr-0 pl-0 pl-md-custom",
),
Expand Down Expand Up @@ -316,7 +316,14 @@ class PersonFacetedSearchFormNew(FacetedSearchForm):
attrs={"data-theme": "bootstrap4"},
),
)
nobelpreis = forms.BooleanField(required=False, label="Nobelpreis")
preise = MultiSolrField(
required=False,
label="",
widget=autocomplete.Select2Multiple(
url="paas_theme:paas_preise_autocomplete",
attrs={"data-theme": "bootstrap4"},
),
)
beruf_position = MultiSolrChildsField(
model_class=PersonInstitutionRelation,
required=False,
Expand Down Expand Up @@ -361,9 +368,6 @@ class PersonFacetedSearchFormNew(FacetedSearchForm):
("phil.-hist. Klasse", "Philosophisch-Historische Klasse"),
],
)
ewk = forms.BooleanField(
required=False, label="Österreichisches Ehrenzeichen für Wissenschaft und Kunst"
)
wiss_austausch = MultiSolrField(
required=False,
label="Land",
Expand Down Expand Up @@ -485,10 +489,15 @@ def search(self):
end_exclusive=self.cleaned_data.get("end_date_form_exclusive"),
).get_person_ids()
sqs = sqs.filter(django_id__in=ids_person)
if self.cleaned_data["ewk"]:
sqs = sqs.filter(ewk=self.cleaned_data["ewk"])
if self.cleaned_data["nobelpreis"]:
sqs = sqs.filter(nobelpreis=self.cleaned_data["nobelpreis"])
# if self.cleaned_data["ewk"]:
# sqs = sqs.filter(ewk=self.cleaned_data["ewk"])
# if self.cleaned_data["nobelpreis"]:
# sqs = sqs.filter(nobelpreis=self.cleaned_data["nobelpreis"])
if self.cleaned_data["preise"]:
preise_dict = SQ()
for preis in self.cleaned_data["preise"]:
preise_dict.add(SQ(akademiepreise=preis[1]), SQ.OR)
sqs = sqs.filter(preise_dict)
if self.cleaned_data["wahl_person"]:
dict_wahl = {"django_ct": "apis_relations.personperson",
"elected_by_id__in": [x[0] for x in self.cleaned_data["wahl_person"]]
Expand Down
14 changes: 7 additions & 7 deletions paas_theme/provide_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,23 +675,23 @@ def enrich_person_context(person_object, context):
context["image"] = False
preise = []
for nobel in person_object.personinstitution_set.filter(
relation_type_id=138,
relation_type_id__in=[138, 3501],
related_institution_id__in=getattr(id_mapping, "NOBEL_PREISE"),
):
preise.append(
f"{nobel.related_institution.name}, {get_date_range(nobel, classes['time_ranges_ids'])[1:-1]}"
f"{nobel.related_institution.name}{' (abgelehnt)' if nobel.relation_type_id == 3501 else ''}, {get_date_range(nobel, classes['time_ranges_ids'])[1:-1]}"
)
for ewk in person_object.personinstitution_set.filter(
relation_type_id=138, related_institution_id=29953
relation_type_id__in=[138, 3501], related_institution_id=29953
):
preise.append(
f"{ewk.related_institution.name}{', '+get_date_range(ewk, classes['time_ranges_ids'])[1:-1] if len(get_date_range(ewk, classes['time_ranges_ids'])) > 0 else ''}"
f"{ewk.related_institution.name}{' (abgelehnt)' if ewk.relation_type_id == 3501 else ''}{', '+get_date_range(ewk, classes['time_ranges_ids'])[1:-1] if len(get_date_range(ewk, classes['time_ranges_ids'])) > 0 else ''}"
)
akad_preise = ""
for akadp in person_object.personinstitution_set.filter(
related_institution_id__in=classes["akademiepreise"], relation_type_id=138
).exclude(relation_type_id=3501):
akad_preise += f"<li><a href='/institution/{akadp.related_institution_id}'>{akadp.related_institution}</a>{' '+get_date_range(akadp, classes['time_ranges_ids'])[1:-1] if len(get_date_range(akadp, classes['time_ranges_ids'])) > 0 else ''}</li>"
related_institution_id__in=classes["akademiepreise"], relation_type_id__in=[138, 3501]
):
akad_preise += f"<li><a href='/institution/{akadp.related_institution_id}'>{akadp.related_institution}</a>{' (abgelehnt)' if akadp.relation_type_id == 3501 else ''}{' '+get_date_range(akadp, classes['time_ranges_ids'])[1:-1] if len(get_date_range(akadp, classes['time_ranges_ids'])) > 0 else ''}</li>"
if len(akad_preise) > 0:
akad_preise = (
"Ausgezeichnet mit folgenden Akademiepreisen:<ul>" + akad_preise + "</ul>"
Expand Down
8 changes: 6 additions & 2 deletions paas_theme/search_indexes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from haystack import indexes
from django.conf import settings
from django.db.models import Q

from apis_core.apis_metainfo.models import Collection, Text
from apis_core.apis_vocabularies.models import (
Expand Down Expand Up @@ -191,7 +192,7 @@ def prepare_text(self, object):

# TODO: MAYBE remove GEMEINSAM KOMMISSION etc. (not id__in=[1,2,3])
def index_queryset(self, using=None):
qs = self.get_model().objects.filter(kind__parent_class__id=81)
qs = self.get_model().objects.filter(Q(kind__parent_class__id=81)|Q(kind_id=137))
return qs


Expand Down Expand Up @@ -502,10 +503,13 @@ def prepare_akademiepreise(self, object):
pi.related_institution.name
for pi in PersonInstitution.objects.filter(
related_person=object,
related_institution_id__in=classes["akademiepreise"],
related_institution_id__in=classes["akademiepreise"]+[29953],
relation_type_id=138,
)
]
nb = object.nobelprizes()
if nb is not None:
res.extend([x[1] for x in nb])
return res

def prepare_preisaufgaben(self, object):
Expand Down
5 changes: 5 additions & 0 deletions paas_theme/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
autocompletes.PaasPersonAutocomplete.as_view(),
name="paas_person_autocomplete",
),
path(
"paas/autocompletes/preise/",
autocompletes.PaasPreiseAutocomplete.as_view(),
name="paas_preise_autocomplete",
),
path(
r"paas/autocompletes/institution/",
autocompletes.PaasInstitutionAutocomplete.as_view(),
Expand Down

0 comments on commit ac402a6

Please sign in to comment.