From abfa712c2c4d109b224e0635a83adc731ca5d26e Mon Sep 17 00:00:00 2001 From: Wilson Gaturu Date: Fri, 19 Apr 2024 12:46:27 +0300 Subject: [PATCH] adds model label for court registry --- peachjam/js/components/FindDocuments/index.vue | 8 ++++++-- peachjam/models/judgment.py | 6 +++++- peachjam/templates/peachjam/_registries.html | 2 +- peachjam/templates/peachjam/judgment_detail.html | 2 +- peachjam/views/courts.py | 1 + peachjam_search/views.py | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/peachjam/js/components/FindDocuments/index.vue b/peachjam/js/components/FindDocuments/index.vue index cbb06e5a3..54f6b2746 100644 --- a/peachjam/js/components/FindDocuments/index.vue +++ b/peachjam/js/components/FindDocuments/index.vue @@ -244,6 +244,10 @@ export default { return labelOptions; }; + const getTitle = (title) => { + return JSON.parse(document.querySelector('#data-labels').textContent)[title]; + }; + const data = { searchPlaceholder: JSON.parse(document.querySelector('#data-labels').textContent).searchPlaceholder, documentLabels: JSON.parse(document.querySelector('#data-labels').textContent).documentLabels, @@ -288,7 +292,7 @@ export default { optionLabels: getLabelOptionLabels(data.documentLabels) }, { - title: JSON.parse(document.querySelector('#data-labels').textContent).author, + title: getTitle('author'), name: 'authors', type: 'checkboxes', value: [], @@ -302,7 +306,7 @@ export default { options: [] }, { - title: this.$t('Court registry'), + title: getTitle('registry'), name: 'registry', type: 'checkboxes', value: [], diff --git a/peachjam/models/judgment.py b/peachjam/models/judgment.py index de192140e..f0948ce74 100644 --- a/peachjam/models/judgment.py +++ b/peachjam/models/judgment.py @@ -135,6 +135,9 @@ def get_queryset(self): class CourtRegistry(models.Model): + model_label = _("Court registry") + model_label_plural = _("Court registries") + objects = CourtRegistryManager() court = models.ForeignKey( Court, @@ -158,7 +161,8 @@ def get_absolute_url(self): return reverse("court_registry", args=[self.court.code, self.code]) def save(self, *args, **kwargs): - self.code = f"{self.court.code}-{slugify(self.name)}" + if not self.code: + self.code = f"{self.court.code}-{slugify(self.name)}" return super().save(*args, **kwargs) diff --git a/peachjam/templates/peachjam/_registries.html b/peachjam/templates/peachjam/_registries.html index cf433b198..1277913a0 100644 --- a/peachjam/templates/peachjam/_registries.html +++ b/peachjam/templates/peachjam/_registries.html @@ -1,6 +1,6 @@ {% load i18n %} {% if registries %} -

{% trans 'Registries' %}

+

{{ registry_label_plural }}

{% for group in registry_groups %}
diff --git a/peachjam/templates/peachjam/judgment_detail.html b/peachjam/templates/peachjam/judgment_detail.html index 6e26aafe9..85211f778 100644 --- a/peachjam/templates/peachjam/judgment_detail.html +++ b/peachjam/templates/peachjam/judgment_detail.html @@ -36,7 +36,7 @@ {% endif %} {% if document.registry %}
- {% trans 'Court Registry' %} + {{ document.registry.model_label }}
{{ document.registry.name }} diff --git a/peachjam/views/courts.py b/peachjam/views/courts.py index 546dafb99..48d881f4c 100644 --- a/peachjam/views/courts.py +++ b/peachjam/views/courts.py @@ -40,6 +40,7 @@ def get_context_data(self, **kwargs): context["doc_type"] = "Judgment" context["court"] = self.court context["formatted_court_name"] = self.formatted_court_name() + context["registry_label_plural"] = CourtRegistry.model_label_plural context["registries"] = self.court.registries.exclude( judgments__isnull=True ) # display registries with judgments only diff --git a/peachjam_search/views.py b/peachjam_search/views.py index c756bf852..12ee4cb2e 100644 --- a/peachjam_search/views.py +++ b/peachjam_search/views.py @@ -27,7 +27,7 @@ from rest_framework.exceptions import PermissionDenied from rest_framework.permissions import AllowAny -from peachjam.models import Author, Label, pj_settings +from peachjam.models import Author, CourtRegistry, Label, pj_settings from peachjam_api.serializers import LabelSerializer from peachjam_search.documents import SearchableDocument, get_search_indexes from peachjam_search.serializers import SearchableDocumentSerializer @@ -170,6 +170,7 @@ def get_context_data(self, **kwargs): } context["labels"] = { "author": Author.model_label, + "registry": CourtRegistry.model_label, "searchPlaceholder": search_placeholder_text, "documentLabels": LabelSerializer(Label.objects.all(), many=True).data, }