Extract 'id' fields from a list of dicts and return as comma-separated string. For dicts with a top-level 'elements' key (e.g. clash, relations output), extracts from that flat summary list rather than the nested structure.
(data)
| 65 | |
| 66 | |
| 67 | def _format_ids(data) -> str: |
| 68 | """Extract 'id' fields from a list of dicts and return as comma-separated string. |
| 69 | |
| 70 | For dicts with a top-level 'elements' key (e.g. clash, relations output), |
| 71 | extracts from that flat summary list rather than the nested structure. |
| 72 | """ |
| 73 | if isinstance(data, list): |
| 74 | ids = [str(item["id"]) for item in data if isinstance(item, dict) and "id" in item] |
| 75 | return ",".join(ids) |
| 76 | if isinstance(data, dict): |
| 77 | if "elements" in data and isinstance(data["elements"], list): |
| 78 | return _format_ids(data["elements"]) |
| 79 | if "id" in data: |
| 80 | return str(data["id"]) |
| 81 | return "" |
| 82 | |
| 83 | |
| 84 | def _format_text(data, indent: int = 0) -> str: |