Skip to content

Commit

Permalink
adds model label for court registry
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed Apr 19, 2024
1 parent 04d2b90 commit abfa712
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
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
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

0 comments on commit abfa712

Please sign in to comment.