Skip to content

Commit

Permalink
Merge pull request #13 from nationalarchives/release/v0.4.0
Browse files Browse the repository at this point in the history
Release/v0.4.0 - add accessors for all listable courts/tribunals
  • Loading branch information
timcowlishaw authored Oct 28, 2022
2 parents 6bc2f00 + c50d6a3 commit f8f6a00
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 13 deletions.
27 changes: 15 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog 1.0.0].

## [Release 0.4.0]
- Add accessors to return all visible courts or tribunals ungrouped.

## [Release 0.3.2]
- Fix bug in court names - parameter values for upper tribunals were incorrect.

## [Release 0.3.1]
- Add newly supported first-tier tribunals to the court list

## [Release 0.3.0]
- Add helper to access court metadata by parameter value.

## [Release 0.2.0]
- Add helpers for accessing metadata about courts

## [Release 0.1.6]
- Add King's Bench to NCN parser regex
- Add github action to lint code on push
Expand All @@ -14,16 +29,4 @@ The format is based on [Keep a Changelog 1.0.0].
## [Release 0.1.4]
- Initial tagged release

## [Release 0.2.0]
- Add helpers for accessing metadata about courts

## [Release 0.3.0]
- Add helper to access court metadata by parameter value.

## [Release 0.3.1]
- Add newly supported first-tier tribunals to the court list

## [Release 0.3.2]
- Fix bug in court names - parameter values for upper tribunals were incorrect.

[keep a changelog 1.0.0]: https://keepachangelog.com/en/1.0.0/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ courts.get_selectable() # returns a list of all courts that are whitelisted to
courts.get_listable_groups() # returns a grouped list of courts that are whitelisted to
# be listed publicly
courts.get_listable_courts() # returns a list of all *courts* (ie not tribunals)
# which are whitelisted to be listed publicly
courts.get_listable_tribunals() # return a list of all *tribunals* which are
# whitelisted to be listed publicly
```

The list of courts is defined in `src/ds_caselaw_utils/data/court_names.yml`. The format is as follows:

```
- name: high_court # Internal name of a group of courts to be displayed together
display_name: "High Court" # An optional public facing name for this group.
is_tribunal: false # Whether this group contains courts or tribunals
courts: # List of courts to be displayed under this group
-
# An internal code for this court:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ds_caselaw_utils"
version = "0.3.2"
version = "0.4.0"
description = "Utilities for the National Archives Caselaw project"
authors = ["David McKee <[email protected]>", "Tim Cowlishaw <[email protected]>"]
license = "MIT"
Expand Down
18 changes: 18 additions & 0 deletions src/ds_caselaw_utils/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def get_listable_groups(self):
groups.append(CourtGroup(category.get("display_name"), courts))
return groups

def get_listable_courts(self):
courts = []
for group in self._data:
if not group.get("is_tribunal"):
for court in group.get("courts", []):
if court.get("listable"):
courts.append(Court(court))
return courts

def get_listable_tribunals(self):
courts = []
for group in self._data:
if group.get("is_tribunal"):
for court in group.get("courts", []):
if court.get("listable"):
courts.append(Court(court))
return courts


yaml = YAML()
datafile = pathlib.Path(__file__).parent / "data/court_names.yaml"
Expand Down
7 changes: 7 additions & 0 deletions src/ds_caselaw_utils/data/court_names.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- name: supreme_court
display_name: ~
is_tribunal: false
courts:
-
code: UKSC
Expand All @@ -13,6 +14,7 @@
listable: true
- name: privy_council
display_name: ~
is_tribunal: false
courts:
-
code: UKPC
Expand All @@ -26,6 +28,7 @@
listable: true
- name: court_of_appeal
display_name: "Court of Appeal"
is_tribunal: false
courts:
-
code: EWCA-Civil
Expand All @@ -51,6 +54,7 @@
listable: true
- name: high_court
display_name: "High Court"
is_tribunal: false
courts:
-
code: EWHC-QBD-Admin
Expand Down Expand Up @@ -291,6 +295,7 @@
listable: false
- name: upper_tribunals
display_name: "Upper Tribunals"
is_tribunal: true
courts:
-
code: UKUT-IAC
Expand Down Expand Up @@ -339,6 +344,7 @@
end_year: ~
- name: employment_appeal_tribunal
display_name: ~
is_tribunal: true
courts:
-
code: EAT
Expand All @@ -352,6 +358,7 @@
end_year: ~
- name: first_tier_tribunals
display_name: "First-tier Tribunals"
is_tribunal: true
courts:
-
code: UKFTT-TC
Expand Down
54 changes: 54 additions & 0 deletions src/ds_caselaw_utils/test_courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,60 @@ def test_loads_court_by_param(self):
repo = CourtsRepository(data)
self.assertEqual("Court 2", repo.get_by_param("court2").name)

def test_returns_listable_courts(self):
data = [
{
"name": "court_group1",
"is_tribunal": False,
"courts": [
{"param": "court1", "listable": True, "name": "Court 1"},
{"param": "court2", "listable": False, "name": "Court 2"},
],
},
{
"name": "court_group2",
"is_tribunal": True,
"courts": [{"param": "court3", "listable": True, "name": "Court 3"}],
},
]
repo = CourtsRepository(data)
self.assertIn("court1", [c.canonical_param for c in repo.get_listable_courts()])
self.assertNotIn(
"court2", [c.canonical_param for c in repo.get_listable_courts()]
)
self.assertNotIn(
"court3", [c.canonical_param for c in repo.get_listable_courts()]
)

def test_returns_listable_tribunals(self):
data = [
{
"name": "court_group1",
"is_tribunal": False,
"courts": [
{"param": "court1", "listable": True, "name": "Court 1"},
],
},
{
"name": "court_group2",
"is_tribunal": True,
"courts": [
{"param": "court2", "listable": False, "name": "Court 2"},
{"param": "court3", "listable": True, "name": "Court 3"},
],
},
]
repo = CourtsRepository(data)
self.assertNotIn(
"court1", [c.canonical_param for c in repo.get_listable_tribunals()]
)
self.assertNotIn(
"court2", [c.canonical_param for c in repo.get_listable_tribunals()]
)
self.assertIn(
"court3", [c.canonical_param for c in repo.get_listable_tribunals()]
)


class TestCourt(unittest.TestCase):
def test_list_name_explicit(self):
Expand Down

0 comments on commit f8f6a00

Please sign in to comment.