Skip to content

Commit e2e3eae

Browse files
Make one config handler for Jurisdictionso
YAML parsing of the jurisdiction configs was originally handled in multiple places, with duplicate configs all around. This PR puts all of the config info for each jurisdiction in its YAML file, and reads it everywhere that jurisdiction configs are used. No more multiple parsing functions[^1]. [^1]: Okay, one parsing function: left in `get_case_type_config`, since it's unclear to me if case_types in jurisdictions should contain all of the base case types or just the ones they've defined / overriden. Need more understanding to make that choice, so I left the code as is there.
1 parent 75a535c commit e2e3eae

12 files changed

Lines changed: 277 additions & 631 deletions

‎efile_app/efile/api/case_form_views.py‎

Lines changed: 0 additions & 272 deletions
This file was deleted.

‎efile_app/efile/api/case_type_config.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.http import JsonResponse
22

3-
from .case_form_views import CaseFormAPIViews
3+
from ..utils.config_loader import JurisdictionConfigLoader, config_loader
44

55

66
def get_case_type_config(request):
@@ -11,11 +11,13 @@ def get_case_type_config(request):
1111
jurisdiction = request.GET.get("jurisdiction") or request.session.get("jurisdiction", "illinois")
1212

1313
# Use the new jurisdiction-aware configuration loader
14-
config_data = CaseFormAPIViews._load_jurisdiction_configuration(jurisdiction)
14+
config_data = config_loader.load_jurisdiction_config(jurisdiction)
1515

1616
# Process case types to ensure proper inheritance from base_case_types
1717
processed_case_types = {}
1818

19+
# TODO(brycew): decide if jurisdictions get all from base_case_types, or
20+
# just the listed ones. Remove this if it's the latter.
1921
# First, add all base case types
2022
if "base_case_types" in config_data:
2123
for key, value in config_data["base_case_types"].items():
@@ -30,7 +32,7 @@ def get_case_type_config(request):
3032
jurisdiction_config = value.copy()
3133

3234
# Deep merge the configurations
33-
merged_config = CaseFormAPIViews._deep_merge_configs(base_config, jurisdiction_config)
35+
merged_config = JurisdictionConfigLoader._deep_merge(base_config, jurisdiction_config)
3436
processed_case_types[key] = merged_config
3537
else:
3638
# New case type not in base

‎efile_app/efile/api/config_views.py‎

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,14 @@
77

88
from django.views.decorators.http import require_http_methods
99

10+
from ..utils.config_loader import config_loader
1011
from .base import APIResponseMixin
11-
from .case_form_views import CaseFormAPIViews
1212

1313
logger = logging.getLogger(__name__)
1414

1515

1616
class ConfigAPIViews(APIResponseMixin):
17-
"""API views for form configuration - delegates to CaseFormAPIViews for jurisdiction-aware configs"""
18-
19-
@staticmethod
20-
def _find_config_key_for_case_type(case_type_id, jurisdiction="illinois"):
21-
"""Find the config key (like 'name_change') that corresponds to a case type ID (like '78346')"""
22-
try:
23-
config = CaseFormAPIViews._load_jurisdiction_configuration(jurisdiction)
24-
case_types_sources = [config.get("case_types", {}), config.get("base_case_types", {})]
25-
26-
case_type_id_lower = case_type_id.lower()
27-
28-
for case_types in case_types_sources:
29-
for case_type_key, case_type_config in case_types.items():
30-
if "keywords" in case_type_config:
31-
for keyword in case_type_config["keywords"]:
32-
keyword_lower = keyword.lower()
33-
if (
34-
keyword_lower in case_type_id_lower
35-
or case_type_id_lower in keyword_lower
36-
or keyword_lower == case_type_id_lower
37-
):
38-
return case_type_key
39-
return None
40-
except Exception:
41-
return None
17+
"""API views for form configuration - delegates to config_loader for jurisdiction-aware configs"""
4218

4319
@staticmethod
4420
@require_http_methods(["GET"])
@@ -62,7 +38,7 @@ def get_form_config(request):
6238
return ConfigAPIViews.error_response("Missing required parameter: case_type")
6339

6440
# Use the new jurisdiction-aware configuration system
65-
case_config = CaseFormAPIViews._find_case_type_config(case_type_id, jurisdiction)
41+
case_config = config_loader.get_case_type_config(jurisdiction, case_type_id, court=court_code)
6642

6743
# If no specific configuration found, return minimal structure
6844
if not case_config:
@@ -76,15 +52,7 @@ def get_form_config(request):
7652
}
7753
)
7854

79-
# Apply court-specific customizations if they exist
8055
sections = case_config.get("sections", {})
81-
if court_code:
82-
# For court-specific modifications, we need to use the config key (like "name_change")
83-
# not the case type ID (like "78346"). Find the config key by reverse lookup.
84-
case_config_key = ConfigAPIViews._find_config_key_for_case_type(case_type_id, jurisdiction)
85-
sections = CaseFormAPIViews._apply_court_specific_config(
86-
sections, court_code, case_config_key or case_type_id, jurisdiction
87-
)
8856

8957
# Structure the response in the expected format
9058
config = {

0 commit comments

Comments
 (0)