Skip to content

Commit

Permalink
Merge pull request #1888 from laws-africa/registry-order
Browse files Browse the repository at this point in the history
Order court stations by name
  • Loading branch information
actlikewill authored Jul 5, 2024
2 parents ac58ed7 + 6bccb3c commit 70a98c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
21 changes: 21 additions & 0 deletions peachjam/migrations/0145_alter_courtregistry_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.25 on 2024-07-04 14:37

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0144_gazette_special"),
]

operations = [
migrations.AlterModelOptions(
name="courtregistry",
options={
"ordering": ("name",),
"verbose_name": "court registry",
"verbose_name_plural": "court registries",
},
),
]
1 change: 1 addition & 0 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class CourtRegistry(models.Model):
code = models.SlugField(_("code"), max_length=255, null=False, unique=True)

class Meta:
ordering = ("name",)
verbose_name = _("court registry")
verbose_name_plural = _("court registries")
unique_together = ("court", "name")
Expand Down
11 changes: 9 additions & 2 deletions peachjam/views/courts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import cached_property
from itertools import groupby
from math import ceil

from django.http import Http404
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -118,10 +119,16 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["court"] = self.court
context["registry_label_plural"] = CourtRegistry.model_label_plural
context["registries"] = self.court.registries.exclude(
context["registries"] = registries = self.court.registries.exclude(
judgments__isnull=True
) # display registries with judgments only
context["registry_groups"] = list(chunks(context["registries"], 2))
# split the list in the middle to have two columns and preserve ordering
split_index = ceil(registries.count() / 2)
context["registry_groups"] = [
registries[:split_index],
registries[split_index:],
]

context["all_years_url"] = self.court.get_absolute_url()
return context

Expand Down

0 comments on commit 70a98c5

Please sign in to comment.