| 184 | |
| 185 | |
| 186 | def create_app(app_name=None): |
| 187 | # Configuration settings |
| 188 | import config |
| 189 | if not app_name: |
| 190 | app_name = config.APP_NAME |
| 191 | |
| 192 | # Check if app is created for CLI operations or Web |
| 193 | cli_mode = False |
| 194 | if app_name.endswith('-cli'): |
| 195 | cli_mode = True |
| 196 | |
| 197 | # Only enable password related functionality in server mode. |
| 198 | if config.SERVER_MODE is True: |
| 199 | # Some times we need to access these config params where application |
| 200 | # context is not available (we can't use current_app.config in those |
| 201 | # cases even with current_app.app_context()) |
| 202 | # So update these params in config itself. |
| 203 | # And also these updated config values will picked up by application |
| 204 | # since we are updating config before the application instance is |
| 205 | # created. |
| 206 | |
| 207 | config.SECURITY_RECOVERABLE = True |
| 208 | config.SECURITY_CHANGEABLE = True |
| 209 | # Now we'll open change password page in dialog |
| 210 | # we don't want it to redirect to main page after password |
| 211 | # change operation so we will open the same password change page again. |
| 212 | config.SECURITY_POST_CHANGE_VIEW = 'browser.change_password' |
| 213 | |
| 214 | """Create the Flask application, startup logging and dynamically load |
| 215 | additional modules (blueprints) that are found in this directory.""" |
| 216 | app = PgAdmin(__name__, static_url_path='/static') |
| 217 | # Removes unwanted whitespace from render_template function |
| 218 | app.jinja_env.trim_blocks = True |
| 219 | app.config.from_object(config) |
| 220 | app.config.update(dict(PROPAGATE_EXCEPTIONS=True)) |
| 221 | |
| 222 | config.SETTINGS_SCHEMA_VERSION = CURRENT_SCHEMA_VERSION |
| 223 | ########################################################################## |
| 224 | # Setup logging and log the application startup |
| 225 | ########################################################################## |
| 226 | |
| 227 | # We won't care about errors in the logging system, we are more |
| 228 | # interested in application errors. |
| 229 | logging.raiseExceptions = False |
| 230 | |
| 231 | # Add SQL level logging, and set the base logging level |
| 232 | logging.addLevelName(25, 'SQL') |
| 233 | app.logger.setLevel(logging.DEBUG) |
| 234 | app.logger.handlers = [] |
| 235 | |
| 236 | # We also need to update the handler on the webserver in order to see |
| 237 | # request. Setting the level prevents werkzeug from setting up it's own |
| 238 | # stream handler thus ensuring all the logging goes through the pgAdmin |
| 239 | # logger. |
| 240 | logger = logging.getLogger('werkzeug') |
| 241 | logger.setLevel(config.CONSOLE_LOG_LEVEL) |
| 242 | |
| 243 | # Set SQLITE_PATH to TEST_SQLITE_PATH while running test cases |