8
8
from ruamel .yaml import YAML
9
9
10
10
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
+
11
18
class Court :
12
19
def __init__ (self , data ):
13
20
self .code = data .get ("code" )
@@ -19,11 +26,71 @@ def __init__(self, data):
19
26
self .param_aliases = [data .get ("param" )] + (data .get ("extra_params" ) or [])
20
27
self .start_year = data .get ("start_year" )
21
28
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
+ ]
22
42
23
43
def __repr__ (self ):
24
44
return self .name
25
45
26
46
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
+
27
94
class CourtGroup :
28
95
def __init__ (self , name , courts ):
29
96
self .name = name
@@ -55,16 +122,37 @@ def get_by_param(self, param):
55
122
except KeyError :
56
123
raise CourtNotFoundException ()
57
124
58
- def get_by_code (self , code ):
125
+ def get_court_by_code (self , code ):
59
126
try :
60
127
return self ._byCode [code ]
61
128
except KeyError :
62
129
raise CourtNotFoundException ()
63
130
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 = [
66
150
Court (court ) for category in self ._data for court in category .get ("courts" )
67
151
]
152
+ if with_jurisdictions :
153
+ return [c for court in courts for c in court .expand_jurisdictions ()]
154
+ else :
155
+ return courts
68
156
69
157
def get_selectable (self ):
70
158
courts = []
0 commit comments