Opened 3 years ago

Last modified 12 months ago

#24128 new Bug

Admindocs doesn't account for template loaders

Reported by: Aymeric Augustin Owned by: nobody
Component: contrib.admindocs Version: master
Severity: Normal Keywords:
Cc: Kris Avi Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

TemplateDetailView only considers dirs and assumes that the filesystem loader is enabled. It doesn't account for other loaders such as app_directories.

The code changed a bit during the multiple-template-engines refactor but this bug existed before and still exists.

Change History (5)

comment:1 Changed 3 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:2 Changed 14 months ago by Kris Avi

Cc: Kris Avi added

It seems it is quite fixable with something like that:

That is probably not the most elegant solution. Tried to get loaders from all the engines and combine their location directories into one to send to enumerator.

            ...
            pass
        else:
            # This doesn't account for template loaders (#24128).

            # Fix for #24128
            from django.template import engines
            directories = set(default_engine.dirs)                    # making set with default engine dirs parameter as initial set
            for engine in engines.all():                              # going through all the engines
                for loader in engine.engine.template_loaders:         # getting each template loader from engine
                    directories.update(loader.get_dirs())             # updating set with new directories from loaders

            for index, directory in enumerate(directories):           # new enumerator with all dirs from default and loaders
            # for index, directory in enumerate(default_engine.dirs): # commented out original enumerator
            # End of fix for #24128
                template_file = os.path.join(directory, template)
                templates.append({
                ...

instead of

            ...
            pass
        else:
            # This doesn't account for template loaders (#24128).
            for index, directory in enumerate(default_engine.dirs):
                template_file = os.path.join(directory, template)
                templates.append({
                ...

comment:3 Changed 14 months ago by Tim Graham

Has patch: set
Needs tests: set

PR without tests.

comment:4 Changed 12 months ago by Tim Graham

Needs tests: unset

comment:5 Changed 12 months ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top