Nav apraksta

apps.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. from django.apps import AppConfig
  2. class OrgsConfig(AppConfig):
  3. default_auto_field = "django.db.models.BigAutoField"
  4. name = "orgs"
  5. verbose_name = "Organizations & Tenancy"
  6. def ready(self) -> None: # pragma: no cover
  7. # Import signal handlers robustly to avoid attribute import issues
  8. import importlib
  9. try:
  10. importlib.import_module("orgs.signals")
  11. except Exception:
  12. # Avoid startup hard-fail if migrations/apps not ready; re-raise only in debug if needed
  13. raise
  14. # Monkey-patch User.__str__ to show "<username>, <fullname>"
  15. # This affects labels in forms and general stringification.
  16. try:
  17. from django.contrib.auth import get_user_model
  18. User = get_user_model()
  19. def _user_str(self): # type: ignore[override]
  20. full = self.get_full_name().strip()
  21. return f"{self.username}, {full}" if full else f"{self.username}"
  22. # Assign only if not already customized
  23. if getattr(User.__str__, "__name__", None) != "_user_str": # type: ignore[attr-defined]
  24. User.__str__ = _user_str # type: ignore[assignment]
  25. except Exception:
  26. # Do not block app startup if something goes wrong
  27. pass
  28. return super().ready()