Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model label for court registry #1800

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: [],
Expand All @@ -302,7 +306,7 @@ export default {
options: []
},
{
title: this.$t('Court registry'),
title: getTitle('registry'),
name: 'registry',
type: 'checkboxes',
value: [],
Expand Down
6 changes: 5 additions & 1 deletion peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion peachjam/templates/peachjam/_registries.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}
{% if registries %}
<h4>{% trans 'Registries' %}</h4>
<h4>{{ registry_label_plural }}</h4>
<div class="row mb-4">
{% for group in registry_groups %}
<div class="col-sm">
Expand Down
2 changes: 1 addition & 1 deletion peachjam/templates/peachjam/judgment_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{% endif %}
{% if document.registry %}
<dt>
{% trans 'Court Registry' %}
{{ document.registry.model_label }}
</dt>
<dd class="text-muted">
<a href="{% url 'court_registry' document.court.code document.registry.code %}">{{ document.registry.name }}</a>
Expand Down
8 changes: 4 additions & 4 deletions peachjam/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_add_judgment_docx_swap_pdf(self):
judgment_add_url = reverse("admin:peachjam_judgment_add")
judgment_list_url = reverse("admin:peachjam_judgment_changelist")

form = self.app.get(judgment_add_url).form
form = self.app.get(judgment_add_url).forms["judgment_form"]

form["jurisdiction"] = "ZA"
form["court"] = "1"
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_add_judgment_docx_swap_pdf(self):
judgment_change_url = reverse(
"admin:peachjam_judgment_change", kwargs={"object_id": judgment.pk}
)
form2 = self.app.get(judgment_change_url).form
form2 = self.app.get(judgment_change_url).forms["judgment_form"]

with open(
os.path.abspath("peachjam/fixtures/source_files/gauteng_judgment.pdf"), "rb"
Expand All @@ -86,7 +86,7 @@ def test_add_judgment_pdf_swap_docx(self):
judgment_add_url = reverse("admin:peachjam_judgment_add")
judgment_list_url = reverse("admin:peachjam_judgment_changelist")

form = self.app.get(judgment_add_url).form
form = self.app.get(judgment_add_url).forms["judgment_form"]

form["jurisdiction"] = "ZA"
form["court"] = "1"
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_add_judgment_pdf_swap_docx(self):
) as docx_file:
docx_file_content = docx_file.read()

form2 = self.app.get(judgment_change_url).form
form2 = self.app.get(judgment_change_url).forms["judgment_form"]
form2["source_file-0-file"] = Upload(
"file.docx",
docx_file_content,
Expand Down
1 change: 1 addition & 0 deletions peachjam/views/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion peachjam_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down
Loading