дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
fix(python): address the review of the Django PRs #6542-#6545 (#6656)
Follow-up fixes to the Django support: - manage.py tasks: manage.py is looked up on each use and only a successful command list is cached; lines run while help loads go to manage.py; a failed help is reported; the active file's project picks the manage.py in a monorepo (shared via platform/django.ts); py/python3.x/Windows forms count as manage.py lines. - Django console: keeps the project root as working directory with manage.py's folder on sys.path, reads setdefault and os.environ[...] settings forms, and shows auto-imported names once reassigned. - URL names: re-reading names clears navigation's cache, names nest under include namespaces, and only path/re_path/url name= counts (small Python scanner). - Field lookups: models keyed per app, multi-table inheritance reverse names fixed, related_query_name/related_name/%(class)s rules, relation lookups and <fk>_id, completion in Q(...) and after F(...). Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
68abd00a7f
коміт
9d92f47f94
19 files changed
+1158
-262
No files matched your search
@@ -27,6 +27,8 @@ def _variables(namespace):
|
||||
for name, value in list(namespace.items()):
|
||||
if name.startswith("_") or name in _hidden or isinstance(value, types.ModuleType):
|
||||
continue
|
||||
if name in _auto and _auto[name] is value:
|
||||
continue
|
||||
try:
|
||||
text = _repr.repr(value)
|
||||
except Exception as error: # a broken __repr__ must not break the console
|
||||
@@ -82,10 +84,15 @@ except ImportError:
|
||||
|
||||
|
||||
ready = {"version": sys.version.split()[0], "ipython": flavour}
|
||||
# Names `manage.py shell` imports, hidden from the variables while they keep their value.
|
||||
_auto = {}
|
||||
# A Django project (PyCharm's Django Console): set Django up and import what `manage.py shell` does.
|
||||
if os.environ.get("OPENIDEA_DJANGO_SETTINGS"):
|
||||
if not os.environ.get("DJANGO_SETTINGS_MODULE"): # as manage.py: the environment's own wins
|
||||
os.environ["DJANGO_SETTINGS_MODULE"] = os.environ["OPENIDEA_DJANGO_SETTINGS"]
|
||||
if os.environ.get("OPENIDEA_DJANGO_DIR"):
|
||||
if os.environ["OPENIDEA_DJANGO_DIR"] not in sys.path:
|
||||
sys.path.insert(0, os.environ["OPENIDEA_DJANGO_DIR"]) # where manage.py imports the settings from
|
||||
if not os.environ.get("DJANGO_SETTINGS_MODULE") and os.environ.get("OPENIDEA_DJANGO_SETTINGS"):
|
||||
os.environ["DJANGO_SETTINGS_MODULE"] = os.environ["OPENIDEA_DJANGO_SETTINGS"] # as manage.py: the environment's wins
|
||||
if os.environ.get("OPENIDEA_DJANGO_DIR") and os.environ.get("DJANGO_SETTINGS_MODULE"):
|
||||
try:
|
||||
import django
|
||||
|
||||
@@ -94,11 +101,11 @@ if os.environ.get("OPENIDEA_DJANGO_SETTINGS"):
|
||||
try:
|
||||
from django.core.management.commands.shell import Command
|
||||
|
||||
imports = Command().get_namespace() # Django 5.2+: the models and common utilities
|
||||
# Django 5.2+: the models; 6.0+ also settings, timezone, models, functions…
|
||||
_auto = Command().get_namespace()
|
||||
except Exception:
|
||||
imports = {}
|
||||
namespace.update(imports)
|
||||
_hidden.update(imports)
|
||||
pass
|
||||
namespace.update(_auto)
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача