From 5b19b25aae5b4649ff43e5966e592c76cf90e807 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 13 Mar 2025 15:20:36 +0100 Subject: ✨ exhibitions: link documents (refs #6222) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_finds/urls.py | 5 +++++ archaeological_finds/views.py | 24 ++++++++++++++++++++++ ishtar_common/models.py | 11 ++++++++++ ishtar_common/templates/ishtar/sheet_document.html | 1 + 4 files changed, 41 insertions(+) diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index e8935511f..af6b5285a 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -612,6 +612,11 @@ urlpatterns = [ views.autocomplete_treatmentfile, name="autocomplete-treatmentfile", ), + url( + r"autocomplete-exhibition/$", + views.autocomplete_exhibition, + name="autocomplete-exhibition", + ), url( r"get-find-for-ope/own/(?P.+)?$", views.get_find_for_ope, diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index f0f1fe4e1..e370c0a87 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -200,6 +200,30 @@ def autocomplete_treatmentfile(request): return HttpResponse(data, content_type="text/plain") +def autocomplete_exhibition(request): + query = get_autocomplete_query(request, "archaeological_finds", "exhibition") + if query is None: + return HttpResponse(content_type="text/plain") + if not request.GET.get("term"): + return HttpResponse(content_type="text/plain") + q = request.GET.get("term") + for q1 in q.split(" "): + for q in q1.split(" "): + extra = ( + Q(reference__icontains=q) + | Q(name__icontains=q) + ) + try: + extra = extra | Q(year=int(q)) + except ValueError: + pass + query = query & extra + limit = 20 + items = models.Exhibition.objects.filter(query)[:limit] + data = json.dumps([{"id": item.pk, "value": str(item)} for item in items]) + return HttpResponse(data, content_type="text/plain") + + def show_basefind(request, pk, **dct): q = models.Find.objects.filter(base_finds__pk=pk, downstream_treatment__isnull=True) if not q.count(): diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 6a793e326..012bf920d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4623,6 +4623,7 @@ class Document( # order is important: put the image in the first match found # other will be symbolic links RELATED_MODELS = [ + "exhibitions", "treatment_files", "treatments", "finds", @@ -4646,6 +4647,7 @@ class Document( "administrativeacts", "warehouses", "containers", + "exhibitions", "treatments", "treatment_files", "towns", @@ -4664,6 +4666,8 @@ class Document( "context_records__pk"), (("archaeological_finds", "find"), "finds__pk"), + (("archaeological_finds", "exhibition"), + "exhibitions__pk"), (("archaeological_finds", "treatmentfile"), "treatment_files__pk"), (("archaeological_finds", "treatment"), @@ -4680,6 +4684,7 @@ class Document( "warehouses", "operations", "treatments", + "exhibitions", "files", "treatment_files", "administrativeacts", @@ -4726,6 +4731,7 @@ class Document( SearchVectorConfig("additional_information", "local"), ] BASE_SEARCH_VECTORS += [ + SearchVectorConfig("exhibitions__name"), SearchVectorConfig("treatment_files__name"), SearchVectorConfig("treatments__cached_label"), SearchVectorConfig("finds__cached_label"), @@ -4982,6 +4988,7 @@ class Document( ("warehouse", "warehouses__pk"), ("treatment", "treatments__pk"), ("treatmentfile", "treatment_files__pk"), + ("exhibition", "exhibitions__pk"), ("administrativeact", "administrativeacts__pk"), ] @@ -5009,6 +5016,10 @@ class Document( pgettext_lazy("key for text search", "treatment-file"), "cached_label", ), + "exhibition": ( + pgettext_lazy("key for text search", "exhibition"), + "cached_label", + ), } QA_EDIT = QuickAction( url="document-qa-bulk-update", diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html index ca382f137..d2fa2d2ef 100644 --- a/ishtar_common/templates/ishtar/sheet_document.html +++ b/ishtar_common/templates/ishtar/sheet_document.html @@ -126,6 +126,7 @@ {% field_flex_full _("Context records") item.context_records|add_links %} {% field_flex_full _("Finds") item.finds|add_links %} {% field_flex_full _("Treatments") item.treatments|add_links %} +{% field_flex_full _("Exhibitions") item.exhibitions|add_links %} {% field_flex_full _("Treatment files") item.treatment_files|add_links %} {% field_flex_full _("Warehouses") item.warehouses|add_links %} {% field_flex_full _("Containers") item.containers|add_links %} -- cgit v1.2.3