Skip to content
Snippets Groups Projects
Verified Commit 5c18e15c authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Implement icon_choices

parent dfc3b4e3
No related branches found
No related tags found
1 merge request!6Resolve "Export django model choices for icons"
"""Utility code used by other parts of django-iconify."""
import os
import re
from .conf import COLLECTIONS_ALLOWED, COLLECTIONS_DISALLOWED
from .conf import COLLECTIONS_ALLOWED, COLLECTIONS_DISALLOWED, JSON_ROOT
def split_css_unit(string: str):
......@@ -33,3 +34,15 @@ def collection_allowed(collection: str) -> bool:
return False
return True
def icon_choices(collection: str) -> list[tuple[str, str]]:
"""Get Django model/form choices for icons in one collection."""
from .types import IconifyJSON
# Load icon set through Iconify types
collection_file = os.path.join(JSON_ROOT, "json", f"{collection}.json")
icon_set = IconifyJSON.from_file(collection_file)
return [(name, name) for name in icon_set.icons.keys()]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment