Skip to content

Commit

Permalink
adds case history model
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed May 30, 2024
1 parent 28bf8f5 commit 49d5e51
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 1 deletion.
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}"
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

0 comments on commit 49d5e51

Please sign in to comment.