Skip to content

Commit 09cb5bb

Browse files
authored
Merge pull request #116 from nationalarchives/feature/grc-subdivisions
Add Jurisdiction info to Courts
2 parents 9191f15 + c43bcb9 commit 09cb5bb

File tree

5 files changed

+332
-4
lines changed

5 files changed

+332
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

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

7+
## [Unreleased]
8+
9+
- Add jurisdiction metadata to courts to support GRC subdivisions
10+
711
## [Release 1.3.5]
812

913
- Fix an issue with EWFC B's name taking priority for the 'ewfc' param

src/ds_caselaw_utils/courts.py

+91-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
from ruamel.yaml import YAML
99

1010

11+
class Jurisdiction:
12+
def __init__(self, data):
13+
self.code = data.get("code")
14+
self.name = data.get("name")
15+
self.prefix = data.get("prefix")
16+
17+
1118
class Court:
1219
def __init__(self, data):
1320
self.code = data.get("code")
@@ -19,11 +26,71 @@ def __init__(self, data):
1926
self.param_aliases = [data.get("param")] + (data.get("extra_params") or [])
2027
self.start_year = data.get("start_year")
2128
self.end_year = data.get("end_year") or date.today().year
29+
self.jurisdictions = [
30+
Jurisdiction(jurisdiction_data)
31+
for jurisdiction_data in data.get("jurisdictions", [])
32+
]
33+
34+
def get_jurisdiction(self, code):
35+
return [j for j in self.jurisdictions if j.code == code][0]
36+
37+
def expand_jurisdictions(self):
38+
return [self] + [
39+
CourtWithJurisdiction(self, jurisdiction)
40+
for jurisdiction in self.jurisdictions
41+
]
2242

2343
def __repr__(self):
2444
return self.name
2545

2646

47+
class CourtWithJurisdiction(Court):
48+
def __init__(self, court, jurisdiction):
49+
self.court = court
50+
self.jurisdiction = jurisdiction
51+
self.jurisdictions = []
52+
53+
@property
54+
def code(self):
55+
return "/".join((self.court.code, self.jurisdiction.code))
56+
57+
@property
58+
def name(self):
59+
return "%s – %s" % (self.court.name, self.jurisdiction.name)
60+
61+
@property
62+
def grouped_name(self):
63+
return self.court.grouped_name
64+
65+
@property
66+
def link(self):
67+
return self.court.link
68+
69+
@property
70+
def ncn(self):
71+
return self.court.ncn
72+
73+
@property
74+
def canonical_param(self):
75+
return self.court.canonical_param
76+
77+
@property
78+
def param_aliases(self):
79+
return self.court.param_aliases
80+
81+
@property
82+
def start_year(self):
83+
return self.court.start_year
84+
85+
@property
86+
def end_year(self):
87+
return self.court.end_year
88+
89+
@property
90+
def jurisdiction_prefix(self):
91+
return self.jurisdiction.prefix
92+
93+
2794
class CourtGroup:
2895
def __init__(self, name, courts):
2996
self.name = name
@@ -55,16 +122,37 @@ def get_by_param(self, param):
55122
except KeyError:
56123
raise CourtNotFoundException()
57124

58-
def get_by_code(self, code):
125+
def get_court_by_code(self, code):
59126
try:
60127
return self._byCode[code]
61128
except KeyError:
62129
raise CourtNotFoundException()
63130

64-
def get_all(self):
65-
return [
131+
def get_court_with_jurisdiction_by_code(self, court_code, jursidiction_code):
132+
court = self.get_court_by_code(court_code)
133+
jurisdiction = court.get_jurisdiction(jursidiction_code)
134+
if jurisdiction is not None:
135+
return CourtWithJurisdiction(court, jurisdiction)
136+
else:
137+
raise CourtNotFoundException()
138+
139+
def get_by_code(self, code):
140+
if "/" in code:
141+
(court_code, jurisdiction_code) = code.split("/")
142+
return self.get_court_with_jurisdiction_by_code(
143+
court_code, jurisdiction_code
144+
)
145+
else:
146+
return self.get_court_by_code(code)
147+
148+
def get_all(self, with_jurisdictions=False):
149+
courts = [
66150
Court(court) for category in self._data for court in category.get("courts")
67151
]
152+
if with_jurisdictions:
153+
return [c for court in courts for c in court.expand_jurisdictions()]
154+
else:
155+
return courts
68156

69157
def get_selectable(self):
70158
courts = []

src/ds_caselaw_utils/data/court_names.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,52 @@
447447
end_year: 2022
448448
selectable: true
449449
listable: true
450+
jurisdictions:
451+
- code: Charity
452+
prefix: CA
453+
name: Charity
454+
- code: CommunityRightToBid
455+
prefix: CR
456+
name: Community Right to Bid
457+
- code: NetworkInformationSystems
458+
prefix: NIS
459+
name: Electronic Communications, Postal Services, and Network Information Systems
460+
- code: Environment
461+
prefix: NV
462+
name: Environment
463+
- code: EstateAgents
464+
prefix: EEA
465+
name: Estate Agents
466+
- code: ExamBoards
467+
prefix: EB
468+
name: Exam Boards
469+
- code: FoodSafety
470+
prefix: FD
471+
name: Food Safety
472+
- code: Gambling
473+
prefix: GA
474+
name: Gambling
475+
- code: ImmigrationServices
476+
prefix: IMS
477+
name: Immigration Services
478+
- code: IndividualElectoralRegulation
479+
prefix: IR
480+
name: Individual Electoral Regulation
481+
- code: InformationRights
482+
prefix: EA
483+
name: Information Rights
484+
- code: Pensions
485+
prefix: PEN
486+
name: Pensions
487+
- code: StandardsAndLicensing
488+
prefix: PR
489+
name: Standards & Licensing
490+
- code: Transport
491+
prefix: D
492+
name: Transport
493+
- code: WelfareOfAnimals
494+
prefix: WA
495+
name: Welfare of Animals
450496
- code: UKFTT-TC
451497
grouped_name: Tax Chamber
452498
name: First-tier Tribunal (Tax Chamber)

src/ds_caselaw_utils/data/schema/courts.schema.json

+17
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@
6161
},
6262
"selectable": {
6363
"type": "boolean"
64+
},
65+
"jurisdictions": {
66+
"type": "array",
67+
"items": {
68+
"type": "object",
69+
"properties": {
70+
"prefix": {
71+
"type": "string"
72+
},
73+
"name": {
74+
"type": "string"
75+
},
76+
"code": {
77+
"type": "string"
78+
}
79+
}
80+
}
6481
}
6582
},
6683
"required": ["code", "name", "link", "listable", "selectable"],

0 commit comments

Comments
 (0)