| 76 | |
| 77 | |
| 78 | class PgAdmin(Flask): |
| 79 | def __init__(self, *args, **kwargs): |
| 80 | # Set the template loader to a postgres-version-aware loader |
| 81 | self.jinja_options = ImmutableDict( |
| 82 | autoescape=select_autoescape(enabled_extensions=('html', 'xml')), |
| 83 | loader=VersionedTemplateLoader(self) |
| 84 | ) |
| 85 | self.logout_hooks = [] |
| 86 | self.before_app_start = [] |
| 87 | |
| 88 | super().__init__(*args, **kwargs) |
| 89 | |
| 90 | def find_submodules(self, basemodule): |
| 91 | try: |
| 92 | for module_name in find_modules(basemodule, True): |
| 93 | if module_name in self.config['MODULE_BLACKLIST']: |
| 94 | self.logger.info( |
| 95 | 'Skipping blacklisted module: %s' % module_name |
| 96 | ) |
| 97 | continue |
| 98 | self.logger.info( |
| 99 | 'Examining potential module: %s' % module_name) |
| 100 | module = import_module(module_name) |
| 101 | for key in list(module.__dict__.keys()): |
| 102 | if isinstance(module.__dict__[key], PgAdminModule): |
| 103 | yield module.__dict__[key] |
| 104 | except Exception: |
| 105 | return [] |
| 106 | |
| 107 | @property |
| 108 | def submodules(self): |
| 109 | for blueprint in self.blueprints.values(): |
| 110 | if isinstance(blueprint, PgAdminModule): |
| 111 | yield blueprint |
| 112 | |
| 113 | @property |
| 114 | def messages(self): |
| 115 | messages = dict() |
| 116 | for module in self.submodules: |
| 117 | messages.update(getattr(module, "messages", dict())) |
| 118 | return messages |
| 119 | |
| 120 | @property |
| 121 | def exposed_endpoint_url_map(self): |
| 122 | ############################################################# |
| 123 | # To handle WSGI paths |
| 124 | # If user has setup application under WSGI alias |
| 125 | # like 'localhost/pgadmin4' then we have to append '/pgadmin4' |
| 126 | # into endpoints |
| 127 | ############################################################# |
| 128 | wsgi_root_path = '' |
| 129 | if url_for(_INDEX_PATH) != '/browser/': |
| 130 | wsgi_root_path = url_for(_INDEX_PATH).replace( |
| 131 | '/browser/', '' |
| 132 | ) |
| 133 | |
| 134 | def get_full_url_path(url): |
| 135 | """ |