summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-03-13 15:20:36 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-03-13 15:48:10 +0100
commit5b19b25aae5b4649ff43e5966e592c76cf90e807 (patch)
tree41620c7c59dbd964cf801a35ed02a15591d63f8d
parentce71f7f286819ee1399fef5f1819f9cc812149a6 (diff)
downloadIshtar-5b19b25aae5b4649ff43e5966e592c76cf90e807.tar.bz2
Ishtar-5b19b25aae5b4649ff43e5966e592c76cf90e807.zip
✨ exhibitions: link documents (refs #6222)
-rw-r--r--archaeological_finds/urls.py5
-rw-r--r--archaeological_finds/views.py24
-rw-r--r--ishtar_common/models.py11
-rw-r--r--ishtar_common/templates/ishtar/sheet_document.html1
4 files changed, 41 insertions, 0 deletions
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
@@ -613,6 +613,11 @@ urlpatterns = [
name="autocomplete-treatmentfile",
),
url(
+ r"autocomplete-exhibition/$",
+ views.autocomplete_exhibition,
+ name="autocomplete-exhibition",
+ ),
+ url(
r"get-find-for-ope/own/(?P<type>.+)?$",
views.get_find_for_ope,
name="get-own-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 %}