mirror of
https://github.com/django-components/django-components.git
synced 2025-08-08 16:27:59 +00:00
fix: implement safe retrieval of component classes from registry (#934)
This commit is contained in:
parent
bafa9f7cc5
commit
f01ee1fe8a
3 changed files with 24 additions and 30 deletions
|
@ -1,8 +1,12 @@
|
|||
import re
|
||||
from typing import Any, Callable, List, Optional, Type, TypeVar
|
||||
from hashlib import md5
|
||||
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Type, TypeVar
|
||||
|
||||
from django_components.util.nanoid import generate
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django_components.component import Component
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
|
@ -71,3 +75,9 @@ def get_last_index(lst: List, key: Callable[[Any], bool]) -> Optional[int]:
|
|||
|
||||
def is_nonempty_str(txt: Optional[str]) -> bool:
|
||||
return txt is not None and bool(txt.strip())
|
||||
|
||||
|
||||
def hash_comp_cls(comp_cls: Type["Component"]) -> str:
|
||||
full_name = get_import_path(comp_cls)
|
||||
comp_cls_hash = md5(full_name.encode()).hexdigest()[0:6]
|
||||
return comp_cls.__name__ + "_" + comp_cls_hash
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue