Skip to content

Commit

Permalink
Merge pull request #1833 from laws-africa/case-history
Browse files Browse the repository at this point in the history
Case histories
  • Loading branch information
actlikewill authored Jun 3, 2024
2 parents 28bf8f5 + b2b2ff1 commit 304f7c0
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 2 deletions.
22 changes: 22 additions & 0 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Author,
Bench,
Book,
CaseHistory,
CaseNumber,
CitationLink,
CitationProcessing,
Expand Down Expand Up @@ -711,6 +712,26 @@ class CaseNumberAdmin(admin.StackedInline):
fields = ["matter_type", "number", "year", "string_override"]


class CaseHistoryInlineAdmin(admin.StackedInline):
model = CaseHistory
extra = 1
verbose_name = gettext_lazy("case history")
verbose_name_plural = gettext_lazy("case history")
fk_name = "judgment"

def get_formset(self, request, obj=None, **kwargs):
return super().get_formset(
request,
obj,
widgets={
"historical_judgment": autocomplete.ModelSelect2(
url="autocomplete-judgments"
)
},
**kwargs,
)


class BenchInline(admin.TabularInline):
# by using an inline, the ordering of the judges is preserved
model = Bench
Expand Down Expand Up @@ -776,6 +797,7 @@ class JudgmentAdmin(ImportExportMixin, DocumentAdmin):
BenchInline,
LowerBenchInline,
CaseNumberAdmin,
CaseHistoryInlineAdmin,
JudgmentRelationshipStackedInline,
] + DocumentAdmin.inlines
filter_horizontal = ("judges", "attorneys", "outcomes")
Expand Down
88 changes: 88 additions & 0 deletions peachjam/migrations/0136_casehistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Generated by Django 3.2.21 on 2024-05-30 13:13

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0135_backfill_citation_counts3"),
]

operations = [
migrations.CreateModel(
name="CaseHistory",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"case_number",
models.CharField(
blank=True,
max_length=1024,
null=True,
verbose_name="case number",
),
),
("date", models.DateField(blank=True, null=True, verbose_name="date")),
(
"court",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="peachjam.court",
verbose_name="court",
),
),
(
"historical_judgment",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="peachjam.judgment",
verbose_name="historical judgment",
),
),
(
"judges",
models.ManyToManyField(
blank=True, to="peachjam.Judge", verbose_name="judges"
),
),
(
"judgment",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="case_histories",
to="peachjam.judgment",
verbose_name="judgment",
),
),
(
"outcome",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="peachjam.outcome",
verbose_name="outcome",
),
),
],
options={
"verbose_name": "case history",
"verbose_name_plural": "case histories",
"ordering": ["date"],
},
),
]
39 changes: 39 additions & 0 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,42 @@ def get_case_number_string(self):
def save(self, *args, **kwargs):
self.string = self.get_case_number_string()
return super().save(*args, **kwargs)


class CaseHistory(models.Model):
judgment = models.ForeignKey(
Judgment,
related_name="case_histories",
on_delete=models.CASCADE,
verbose_name=_("judgment"),
)
case_number = models.CharField(
_("case number"), max_length=1024, null=True, blank=True
)
historical_judgment = models.ForeignKey(
Judgment,
on_delete=models.PROTECT,
null=True,
blank=True,
verbose_name=_("historical judgment"),
)
outcome = models.ForeignKey(
Outcome,
on_delete=models.PROTECT,
null=True,
blank=True,
verbose_name=_("outcome"),
)
judges = models.ManyToManyField(Judge, verbose_name=_("judges"), blank=True)
court = models.ForeignKey(
Court, on_delete=models.PROTECT, null=True, blank=True, verbose_name=_("court")
)
date = models.DateField(_("date"), null=True, blank=True)

class Meta:
ordering = ["-date"]
verbose_name = _("case history")
verbose_name_plural = _("case histories")

def __str__(self):
return f"{self.case_number}" or f"{self.judgment} - {self.date}"
35 changes: 35 additions & 0 deletions peachjam/templates/peachjam/_case_histories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans 'Date' %}</th>
<th>{% trans 'Case' %}</th>
<th>{% trans 'Court' %}</th>
<th>{% trans 'Judges' %}</th>
<th>{% trans 'Outcome' %}</th>
</tr>
</thead>
<tbody>
{% for history in case_histories %}
<tr>
<td>{{ history.date }}</td>
<td>
{% if history.historical_judgment %}
<a target="_blank"
href="{{ history.historical_judgment.expression_frbr_uri }}">{{ history.historical_judgment }}</a>
{% else %}
{{ history.case_number }}
{% endif %}
</td>
<td>{{ history.court }}</td>
<td>
{% for judge in history.judges.all %}
{{ judge }}
{% if not forloop.last %},{% endif %}
{% endfor %}
</td>
<td>{{ history.outcome }}</td>
</tr>
{% endfor %}
</tbody>
</table>
22 changes: 22 additions & 0 deletions peachjam/templates/peachjam/layouts/document_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ <h1>{{ document.title }}</h1>
</button>
</li>
{% endif %}
{% if case_histories %}
<li class="nav-item" role="presentation">
<button class="nav-link"
data-bs-toggle="tab"
data-bs-target="#case-history-tab"
type="button"
role="tab"
aria-controls="case-history-tab"
aria-selected="false">
<i class="bi bi-pj pj-case-history"></i>
{% trans 'Case history' %}
</button>
</li>
{% endif %}
{% if document.work.ratification.countries.all|length %}
<li class="nav-item" role="presentation">
<button class="nav-link"
Expand Down Expand Up @@ -421,6 +435,14 @@ <h5>
<div class="container">{% include 'peachjam/_citations.html' %}</div>
</div>
{% endif %}
{% if case_histories %}
<div class="tab-pane fade"
id="case-history-tab"
role="tabpanel"
aria-labelledby="case-history-tab">
<div class="container">{% include 'peachjam/_case_histories.html' %}</div>
</div>
{% endif %}
{% if document.work.ratification.countries.all|length %}
<div class="tab-pane fade"
id="ratifications-tab"
Expand Down
6 changes: 6 additions & 0 deletions peachjam/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
GazetteYearView,
HomePageView,
JournalListView,
JudgmentAutocomplete,
JudgmentListView,
LegalInstrumentListView,
LegislationListView,
Expand Down Expand Up @@ -227,6 +228,11 @@
WorkAutocomplete.as_view(),
name="autocomplete-works",
),
path(
"admin/autocomplete/judgments",
JudgmentAutocomplete.as_view(),
name="autocomplete-judgments",
),
path("admin/", admin.site.urls),
path("accounts/", include("allauth.urls")),
path("api/", include("peachjam_api.urls")),
Expand Down
14 changes: 13 additions & 1 deletion peachjam/views/autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dal import autocomplete

from peachjam.models import Work
from peachjam.models import Judgment, Work


class WorkAutocomplete(autocomplete.Select2QuerySetView):
Expand All @@ -14,3 +14,15 @@ def get_queryset(self):
qs = qs.filter(title__istartswith=self.q)

return qs


class JudgmentAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
if not self.request.user.is_staff:
return Judgment.objects.none()

qs = Judgment.objects.all()
if self.q:
qs = qs.filter(title__istartswith=self.q)

return qs
5 changes: 4 additions & 1 deletion peachjam/views/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def get_context_data(self, **kwargs):
{
"judges": self.get_object()
.bench.prefetch_related("judge")
.values_list("judge__name", flat=True)
.values_list("judge__name", flat=True),
"case_histories": self.get_object()
.case_histories.select_related("court", "historical_judgment")
.prefetch_related("judges"),
}
)
return context

0 comments on commit 304f7c0

Please sign in to comment.