13 lines
572 B
Python
13 lines
572 B
Python
# common/private_files/registry.py
|
|
from typing import Callable, Tuple, Dict
|
|
|
|
Guard = Callable[[object, "django.contrib.auth.models.User"], bool]
|
|
|
|
_REGISTRY: Dict[Tuple[str, str, str], Guard] = {} # (app_label, model_name, field_name) -> guard
|
|
|
|
def register(app_label: str, model_name: str, field_name: str, guard: Guard):
|
|
key = (app_label.lower(), model_name.lower(), field_name)
|
|
_REGISTRY[key] = guard
|
|
|
|
def get_guard(app_label: str, model_name: str, field_name: str) -> Guard | None:
|
|
return _REGISTRY.get((app_label.lower(), model_name.lower(), field_name))
|