Use nested template metadata in route readers
This commit is contained in:
+32
-3
@@ -16,13 +16,29 @@ except ImportError: # Allows local smoke tests from the repository root.
|
||||
def row_action_family(row: Any, default: str = "") -> str:
|
||||
if not isinstance(row, dict):
|
||||
return default
|
||||
return normalize_hardcore_action_family(row.get("action_family"), default)
|
||||
family = normalize_hardcore_action_family(row.get("action_family"), "")
|
||||
if family:
|
||||
return family
|
||||
metadata = row.get("item_template_metadata")
|
||||
if isinstance(metadata, dict):
|
||||
family = template_metadata_policy.template_action_family(metadata)
|
||||
if family:
|
||||
return family
|
||||
return default
|
||||
|
||||
|
||||
def row_position_family(row: Any, default: str = "") -> str:
|
||||
if not isinstance(row, dict):
|
||||
return default
|
||||
return normalize_hardcore_position_family(str(row.get("position_family") or "").strip().lower(), default)
|
||||
family = normalize_hardcore_position_family(str(row.get("position_family") or "").strip().lower(), "")
|
||||
if family:
|
||||
return family
|
||||
metadata = row.get("item_template_metadata")
|
||||
if isinstance(metadata, dict):
|
||||
family = template_metadata_policy.template_position_family(metadata)
|
||||
if family:
|
||||
return family
|
||||
return default
|
||||
|
||||
|
||||
def _raw_position_key_values(row: dict[str, Any]) -> list[Any]:
|
||||
@@ -49,6 +65,11 @@ def row_position_keys(row: Any, *, include_unknown: bool = False) -> list[str]:
|
||||
return []
|
||||
values = _raw_position_key_values(row)
|
||||
selected = normalize_hardcore_position_values(values)
|
||||
metadata = row.get("item_template_metadata")
|
||||
if isinstance(metadata, dict):
|
||||
for key in template_metadata_policy.template_position_keys(metadata):
|
||||
if key and key not in selected:
|
||||
selected.append(key)
|
||||
if not include_unknown:
|
||||
return selected
|
||||
for value in values:
|
||||
@@ -59,4 +80,12 @@ def row_position_keys(row: Any, *, include_unknown: bool = False) -> list[str]:
|
||||
|
||||
|
||||
def row_formatter_hints(row: Any, route: str) -> list[str]:
|
||||
return template_metadata_policy.formatter_hints_for_route(row, route)
|
||||
hints: list[str] = []
|
||||
for hint in template_metadata_policy.formatter_hints_for_route(row, route):
|
||||
if hint not in hints:
|
||||
hints.append(hint)
|
||||
if isinstance(row, dict) and isinstance(row.get("item_template_metadata"), dict):
|
||||
for hint in template_metadata_policy.formatter_hints_for_route(row["item_template_metadata"], route):
|
||||
if hint not in hints:
|
||||
hints.append(hint)
|
||||
return hints
|
||||
|
||||
Reference in New Issue
Block a user