2017-03-16 09:27:55 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
2017-01-30 05:25:02 -06:00
|
|
|
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 = (
|
2017-04-24 07:55:29 -05:00
|
|
|
{'name': "10.0_plus", 'number': 100000},
|
2017-01-30 05:25:02 -06:00
|
|
|
{'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},
|
2017-01-30 11:02:55 -06:00
|
|
|
{'name': "9.1_plus", 'number': 90100},
|
|
|
|
{'name': "9.0_plus", 'number': 90000},
|
2017-02-01 03:57:45 -06:00
|
|
|
{'name': "default", 'number': 0}
|
2017-01-30 05:25:02 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2017-01-30 11:02:55 -06:00
|
|
|
raise TemplateNotFound(template)
|