Skip to content

Commit

Permalink
Catch errors in docs build
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklinke committed Dec 21, 2024
1 parent eef4921 commit 4c1b20b
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,41 @@ def project_django_models(app, what, name, obj, options, lines): # pylint: disa
# Only look at objects that inherit from Django's base model class
if inspect.isclass(obj) and issubclass(obj, models.Model):
# Grab the field list from the meta class
fields = obj._meta.get_fields() # pylint: disable=W0212

for field in fields:
# If it's a reverse relation, skip it
if isinstance(
field,
(
models.fields.related.ManyToOneRel,
models.fields.related.ManyToManyRel,
models.fields.related.OneToOneRel,
),
):
continue

# Decode and strip any html out of the field's help text
help_text = strip_tags(field.help_text) if hasattr(field, "help_text") else None

# Decode and capitalize the verbose name, for use if there isn't
# any help text
verbose_name = field.verbose_name if hasattr(field, "verbose_name") else ""

if help_text:
# Add the model field to the end of the docstring as a param
# using the help text as the description
lines.append(f":param {field.attname}: {help_text}")
else:
# Add the model field to the end of the docstring as a param
# using the verbose name as the description
lines.append(f":param {field.attname}: {verbose_name}")

# Add the field's type to the docstring
lines.append(f":type {field.attname}: {field.__class__.__name__}")
try:
fields = obj._meta.get_fields() # pylint: disable=W0212

for field in fields:
# If it's a reverse relation, skip it
if isinstance(
field,
(
models.fields.related.ManyToOneRel,
models.fields.related.ManyToManyRel,
models.fields.related.OneToOneRel,
),
):
continue

# Decode and strip any html out of the field's help text
help_text = strip_tags(field.help_text) if hasattr(field, "help_text") else None

# Decode and capitalize the verbose name, for use if there isn't
# any help text
verbose_name = field.verbose_name if hasattr(field, "verbose_name") else ""

if help_text:
# Add the model field to the end of the docstring as a param
# using the help text as the description
lines.append(f":param {field.attname}: {help_text}")
else:
# Add the model field to the end of the docstring as a param
# using the verbose name as the description
lines.append(f":param {field.attname}: {verbose_name}")

# Add the field's type to the docstring
lines.append(f":type {field.attname}: {field.__class__.__name__}")
except Exception:
pass

# Return the extended docstring
return lines
Expand Down

0 comments on commit 4c1b20b

Please sign in to comment.