mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-30 20:43:50 -06:00
19be3529f8
This will automatically find the correct version of a template for the server version, and allows us to remove templates that were previously duplicated for different server versions. Patch by George & Tira at Pivotal. Review by me and Murtuza from EDB. Discussion: https://www.postgresql.org/message-id/flat/CAHowoHaU9_pkCt%2B1g8dpY3hsXXZmsJZiJH-3-_Hd%2BC1MxiGhtA%40mail.gmail.com#CAHowoHaU9_pkCt+1g8dpY3hsXXZmsJZiJH-3-_Hd+C1MxiGhtA@mail.gmail.com
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from flask.templating import DispatchingJinjaLoader
|
|
from jinja2 import TemplateNotFound
|
|
|
|
|
|
class VersionedTemplateLoader(DispatchingJinjaLoader):
|
|
def get_source(self, environment, template):
|
|
template_path_parts = template.split("#", 2)
|
|
|
|
server_versions = (
|
|
{'name': "9.6_plus", 'number': 90600},
|
|
{'name': "9.5_plus", 'number': 90500},
|
|
{'name': "9.4_plus", 'number': 90400},
|
|
{'name': "9.3_plus", 'number': 90300},
|
|
{'name': "9.2_plus", 'number': 90200},
|
|
{'name': "9.1_plus", 'number': 90100}
|
|
)
|
|
|
|
if len(template_path_parts) == 1:
|
|
return super(VersionedTemplateLoader, self).get_source(environment, template)
|
|
else:
|
|
for server_version in server_versions:
|
|
path_start, specified_version_number, file_name = template_path_parts
|
|
|
|
if server_version['number'] > int(specified_version_number):
|
|
continue
|
|
|
|
template_path = path_start + '/' + server_version['name'] + '/' + file_name
|
|
try:
|
|
return super(VersionedTemplateLoader, self).get_source(environment, template_path)
|
|
except TemplateNotFound:
|
|
continue
|