Compare commits
1 commit
master
...
upgrade_do
Author | SHA1 | Date | |
---|---|---|---|
79aef3557f |
1 changed files with 29 additions and 0 deletions
29
docs/conf.py
29
docs/conf.py
|
@ -12,6 +12,8 @@
|
|||
#
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
|
||||
import django
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'mamweb.settings'
|
||||
|
@ -97,5 +99,32 @@ def ignorovat(app, what, name, obj, skip, options):
|
|||
ignore = (what, name) in blacklist
|
||||
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):
|
||||
app.connect('autodoc-skip-member', ignorovat)
|
||||
app.connect('autodoc-process-docstring', see)
|
||||
|
|
Loading…
Reference in a new issue