| 11 | |
| 12 | |
| 13 | class VersionedTemplateLoader(DispatchingJinjaLoader): |
| 14 | def get_source(self, environment, template): |
| 15 | specified_version_number, exists = parse_version(template) |
| 16 | if not exists: |
| 17 | return super().get_source( |
| 18 | environment, template |
| 19 | ) |
| 20 | |
| 21 | template_dir, file_name = parse_template(template) |
| 22 | |
| 23 | for version_mapping in get_version_mapping(template): |
| 24 | if version_mapping['number'] > specified_version_number: |
| 25 | continue |
| 26 | |
| 27 | template_path = '/'.join([ |
| 28 | template_dir, |
| 29 | version_mapping['name'], |
| 30 | file_name |
| 31 | ]) |
| 32 | |
| 33 | try: |
| 34 | return super().get_source( |
| 35 | environment, template_path |
| 36 | ) |
| 37 | except TemplateNotFound: |
| 38 | continue |
| 39 | raise TemplateNotFound(template) |
| 40 | |
| 41 | |
| 42 | def parse_version(template): |