Browse Source

Automatické zpracování urls.py

upgrade_dokumentace
Jonas Havelka 1 year ago
parent
commit
79aef3557f
  1. 29
      docs/conf.py

29
docs/conf.py

@ -12,6 +12,8 @@
# #
import os import os
import sys import sys
import types
import django import django
sys.path.insert(0, os.path.abspath('..')) sys.path.insert(0, os.path.abspath('..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'mamweb.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'mamweb.settings'
@ -97,5 +99,32 @@ def ignorovat(app, what, name, obj, skip, options):
ignore = (what, name) in blacklist ignore = (what, name) in blacklist
return True if ignore else None return True if ignore else None
def see(app, what: str, name: str, obj, options, lines: list[str]):
from django.urls.resolvers import URLPattern
if what == "module" and name.endswith("urls") and hasattr(obj, "urlpatterns"):
for url_pattern in obj.urlpatterns:
text = f"- ``{url_pattern.pattern}`` "
if isinstance(url_pattern, URLPattern):
if url_pattern.name is not None:
text += f"({url_pattern.name}) "
if hasattr(url_pattern.callback, "view_class"):
text += f":class:`~{url_pattern.callback.view_class.__module__}.{url_pattern.callback.view_class.__name__}`"
else:
text += f":func:`~{url_pattern.callback.__module__}.{url_pattern.callback.__name__}`"
else:
if isinstance(url_pattern.urlconf_name, types.ModuleType):
text += f":mod:`~{url_pattern.urlconf_name.__name__}`"
else:
# FIXME nějak lépe ošetřit. Ale `admin/` je zatím jediný případ
pass
lines.append(text)
return lines
def setup(app): def setup(app):
app.connect('autodoc-skip-member', ignorovat) app.connect('autodoc-skip-member', ignorovat)
app.connect('autodoc-process-docstring', see)

Loading…
Cancel
Save