Skip to content

Commit

Permalink
Merge pull request #1816 from laws-africa/outcome
Browse files Browse the repository at this point in the history
Split order and outcome fields
  • Loading branch information
actlikewill authored May 21, 2024
2 parents c385922 + f2b7b99 commit 2df2fd4
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 66 deletions.
11 changes: 6 additions & 5 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
Locality,
LowerBench,
MatterType,
OrderOutcome,
Outcome,
PeachJamSettings,
Predicate,
Relationship,
Expand Down Expand Up @@ -275,6 +275,7 @@ class DocumentForm(forms.ModelForm):
)
flynote = forms.CharField(widget=CKEditorWidget(), required=False)
case_summary = forms.CharField(widget=CKEditorWidget(), required=False)
order = forms.CharField(widget=CKEditorWidget(), required=False)
date = forms.DateField(widget=DateSelectorWidget())

def __init__(self, data=None, *args, **kwargs):
Expand Down Expand Up @@ -750,22 +751,22 @@ class JudgmentAdmin(ImportExportMixin, DocumentAdmin):
CaseNumberAdmin,
JudgmentRelationshipStackedInline,
] + DocumentAdmin.inlines
filter_horizontal = ("judges", "attorneys", "order_outcomes")
filter_horizontal = ("judges", "attorneys", "outcomes")
list_filter = (*DocumentAdmin.list_filter, "court")
fieldsets = copy.deepcopy(DocumentAdmin.fieldsets)

fieldsets[0][1]["fields"].insert(3, "court")
fieldsets[0][1]["fields"].insert(4, "registry")
fieldsets[0][1]["fields"].insert(5, "case_name")
fieldsets[0][1]["fields"].insert(6, "order_outcomes")
fieldsets[0][1]["fields"].insert(6, "outcomes")
fieldsets[0][1]["fields"].insert(7, "mnc")
fieldsets[0][1]["fields"].insert(8, "serial_number_override")
fieldsets[0][1]["fields"].insert(9, "serial_number")
fieldsets[0][1]["fields"].append("hearing_date")
fieldsets[1][1]["fields"].insert(0, "attorneys")

fieldsets[2][1]["classes"] = ["collapse"]
fieldsets[3][1]["fields"].extend(["case_summary", "flynote"])
fieldsets[3][1]["fields"].extend(["case_summary", "flynote", "order"])
readonly_fields = [
"mnc",
"serial_number",
Expand Down Expand Up @@ -1058,7 +1059,7 @@ class CourtRegistryAdmin(BaseAdmin):
list_display = ("name", "code")


@admin.register(OrderOutcome)
@admin.register(Outcome)
class OutcomeAdmin(admin.ModelAdmin):
list_display = ("name",)

Expand Down
10 changes: 4 additions & 6 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class BaseDocumentFilterForm(forms.Form):
localities = forms.CharField(required=False)
registries = forms.CharField(required=False)
attorneys = forms.CharField(required=False)
order_outcomes = forms.CharField(required=False)
outcomes = forms.CharField(required=False)

def __init__(self, data, *args, **kwargs):
self.params = QueryDict(mutable=True)
Expand All @@ -103,7 +103,7 @@ def filter_queryset(self, queryset, exclude=None):
localities = self.params.getlist("localities")
registries = self.params.getlist("registries")
attorneys = self.params.getlist("attorneys")
order_outcomes = self.params.getlist("order_outcomes")
outcomes = self.params.getlist("outcomes")

queryset = self.order_queryset(queryset, exclude)

Expand Down Expand Up @@ -137,10 +137,8 @@ def filter_queryset(self, queryset, exclude=None):
if attorneys and exclude != "attorneys":
queryset = queryset.filter(attorneys__name__in=attorneys)

if order_outcomes and exclude != "order_outcomes":
queryset = queryset.filter(
order_outcomes__name__in=order_outcomes
).distinct()
if outcomes and exclude != "outcomes":
queryset = queryset.filter(outcomes__name__in=outcomes).distinct()

return queryset

Expand Down
6 changes: 3 additions & 3 deletions peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
{{ $t('Court registry') }}
{{ $t('Judges') }}
{{ $t('Attorneys') }}
{{ $t('Order') }}
{{ $t('Outcome') }}
{{ $t('Jurisdiction') }}
{{ $t('Locality') }}
{{ $t('Matter type') }}
Expand Down Expand Up @@ -329,8 +329,8 @@ export default {
options: []
},
{
title: this.$t('Order'),
name: 'order_outcome',
title: this.$t('Outcome'),
name: 'outcome',
type: 'checkboxes',
value: [],
options: []
Expand Down
6 changes: 3 additions & 3 deletions peachjam/js/components/ListFacets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default {
type: Array,
default: () => []
},
order_outcomes: {
outcomes: {
type: Array,
default: () => []
}
Expand Down Expand Up @@ -141,9 +141,9 @@ export default {
title: this.$t('Judges')
},
{
name: 'order_outcomes',
name: 'outcomes',
type: 'checkboxes',
title: this.$t('Order')
title: this.$t('Outcome')
},
{
name: 'jurisdictions',
Expand Down
76 changes: 76 additions & 0 deletions peachjam/migrations/0131_rename_order_outcome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by Django 3.2.21 on 2024-05-15 13:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0130_backfill_citation_counts"),
]

operations = [
migrations.CreateModel(
name="Outcome",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"name",
models.CharField(max_length=1024, unique=True, verbose_name="name"),
),
(
"name_en",
models.CharField(
max_length=1024, null=True, unique=True, verbose_name="name"
),
),
(
"name_fr",
models.CharField(
max_length=1024, null=True, unique=True, verbose_name="name"
),
),
(
"name_pt",
models.CharField(
max_length=1024, null=True, unique=True, verbose_name="name"
),
),
(
"name_sw",
models.CharField(
max_length=1024, null=True, unique=True, verbose_name="name"
),
),
(
"description",
models.TextField(blank=True, verbose_name="description"),
),
],
options={
"verbose_name": "outcome",
"verbose_name_plural": "outcomes",
"ordering": ["name"],
},
),
migrations.AddField(
model_name="judgment",
name="order",
field=models.TextField(blank=True, null=True, verbose_name="order"),
),
migrations.AddField(
model_name="judgment",
name="outcomes",
field=models.ManyToManyField(
blank=True, related_name="judgments", to="peachjam.Outcome"
),
),
]
38 changes: 38 additions & 0 deletions peachjam/migrations/0132_outcome_es_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 3.2.21 on 2024-05-15 13:59

import os

from django.db import migrations


def forwards(apps, schema_editor):
from django.conf import settings
from django_elasticsearch_dsl.registries import registry

if not settings.DEBUG and os.environ.get("ELASTICSEARCH_HOST"):
for ix in registry.get_indices():
if not ix._mapping:
continue
print(f"Adding outcome mapping for {ix._name}")
ix.connection.indices.put_mapping(
index=ix._name,
body={
"properties": {
"outcome": ix._mapping["outcome"].to_dict(),
"outcome_en": ix._mapping["outcome_en"].to_dict(),
"outcome_sw": ix._mapping["outcome_sw"].to_dict(),
"outcome_fr": ix._mapping["outcome_fr"].to_dict(),
"outcome_pt": ix._mapping["outcome_pt"].to_dict(),
"order": ix._mapping["order"].to_dict(),
}
},
)


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0131_rename_order_outcome"),
]

operations = [migrations.RunPython(forwards, migrations.RunPython.noop)]
45 changes: 45 additions & 0 deletions peachjam/migrations/0133_backfill_outcomes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 3.2.21 on 2024-05-17 09:54


from django.db import migrations


def forwards(apps, schema_editor):
Outcome = apps.get_model("peachjam", "Outcome")
OrderOutCome = apps.get_model("peachjam", "OrderOutCome")
Judgment = apps.get_model("peachjam", "Judgment")

for outcome in OrderOutCome.objects.all():
o = Outcome()
o.name = outcome.name
o.description = outcome.description
if hasattr(outcome, "name_en"):
o.name_en = outcome.name_en
if hasattr(outcome, "name_fr"):
o.name_fr = outcome.name_fr
if hasattr(outcome, "name_pt"):
o.name_pt = outcome.name_pt
if hasattr(outcome, "name_sw"):
o.name_sw = outcome.name_sw
o.save()

for judgment in (
Judgment.objects.filter(order_outcomes__isnull=False)
.order_by("pk")
.iterator(chunk_size=100)
):
j_outcomes = judgment.order_outcomes.all().values_list("name", flat=True)
outcomes = Outcome.objects.filter(name__in=j_outcomes)
if outcomes:
judgment.outcomes.set(outcomes)


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0132_outcome_es_index"),
]

operations = [
migrations.RunPython(forwards, migrations.RunPython.noop),
]
21 changes: 21 additions & 0 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ def __str__(self):
return self.name


class Outcome(models.Model):
name = models.CharField(
_("name"), max_length=1024, null=False, blank=False, unique=True
)
description = models.TextField(_("description"), blank=True)

class Meta:
ordering = ["name"]
verbose_name = _("outcome")
verbose_name_plural = _("outcomes")

def __str__(self):
return self.name


class MatterType(models.Model):
name = models.CharField(
_("name"), max_length=1024, null=False, blank=False, unique=True
Expand Down Expand Up @@ -246,8 +261,14 @@ class Judgment(CoreDocument):
blank=True,
related_name="judgments",
)
outcomes = models.ManyToManyField(
Outcome,
blank=True,
related_name="judgments",
)
case_summary = models.TextField(_("case summary"), null=True, blank=True)
flynote = models.TextField(_("flynote"), null=True, blank=True)
order = models.TextField(_("order"), null=True, blank=True)
case_name = models.CharField(
_("case name"),
max_length=4096,
Expand Down
10 changes: 5 additions & 5 deletions peachjam/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Judgment,
Locality,
MatterType,
OrderOutcome,
Outcome,
SourceFile,
Taxonomy,
citations_processor,
Expand Down Expand Up @@ -490,10 +490,10 @@ class JudgmentResource(BaseDocumentResource):
)
matter_type = fields.Field(column_name="matter_type", widget=CharWidget)

order_outcome = fields.Field(
column_name="order_outcome",
attribute="order_outcome",
widget=ForeignKeyWidget(OrderOutcome, field="name"),
outcome = fields.Field(
column_name="outcome",
attribute="outcome",
widget=ForeignKeyWidget(Outcome, field="name"),
)

class Meta(BaseDocumentResource.Meta):
Expand Down
20 changes: 15 additions & 5 deletions peachjam/templates/peachjam/judgment_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<a href="{% url 'court_registry' document.court.code document.registry.code %}">{{ document.registry.name }}</a>
</dd>
{% endif %}
{% with document.order_outcomes.all as order_outcomes %}
{% if order_outcomes %}
{% with document.outcomes.all as outcomes %}
{% if outcomes %}
<dt>
{% trans 'Order' %}
{% trans 'Outcome' %}
</dt>
<dd class="text-muted">
{% for order_outcome in order_outcomes %}
{{ order_outcome.name }}
{% for outcome in outcomes %}
{{ outcome.name }}
{% if not forloop.last %},{% endif %}
{% endfor %}
</dd>
Expand Down Expand Up @@ -92,6 +92,16 @@
</dd>
</dl>
{% endif %}
{% if document.order %}
<dl>
<dt>
{% trans 'Order' %}
</dt>
<dd>
{{ document.order|safe }}
</dd>
</dl>
{% endif %}
{% if document.case_summary %}
<dl>
<dt>
Expand Down
Loading

0 comments on commit 2df2fd4

Please sign in to comment.