sphinx-doc / sphinxcontrib-django

This is a sphinx extension which improves the documentation of Django apps.
https://pypi.org/project/sphinxcontrib-django/
Apache License 2.0
43 stars 25 forks source link

verbose_name is capitalized and goes against user expectations #30

Closed afparsons closed 1 year ago

afparsons commented 3 years ago

In the following block in docstrings.py, .capitalize() is applied to the verbose_name.

    for field in obj._meta.get_fields():
        try:
            help_text = strip_tags(force_text(field.help_text))
            verbose_name = force_text(field.verbose_name).capitalize()
        except AttributeError:
            # e.g. ManyToOneRel
            continue

This is not behavior I expect as a user.

For example, I have a model and field:

class Configuration(models.Model):

    api_secret_key = models.CharField(
        max_length=32,
        blank=False,
        null=False,
        verbose_name='API Secret Key',
    )

I have explicitly set my preferred case (notably, all uppercase letters for the "API" abbreviation), but because .capitalize() is applied to verbose_name, this is turned into:

Api secret key


Solution proposals:

timobrembeck commented 3 years ago

This bothered me as well, I solved it in the following way: field_verbose_name[:1].upper() + field_verbose_name[1:] Since this project is not maintained anymore, I packaged my own fork: https://pypi.org/project/sphinxcontrib-django2/ If you have any ideas for improvements, feel free to submit them to the forked repo: sphinxcontrib-django2

afparsons commented 3 years ago

Thanks, @timoludwig. I saw your "Maintained Fork" issue. While it is unfortunate that @vdboor has seemingly abandoned maintence, I'm glad you've stepped up and are willing to maintain a fork. Hopefully your fork gets more traction.

timobrembeck commented 1 year ago

I now merged the changes of my fork back into this repo, including commit 714230958150f0c9bbd75a55cdea6204c6bd3a31 which fixes this issue.