mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Use Flask blueprints for modularisation, per Khushboo Vashi.
This commit is contained in:
@@ -10,9 +10,7 @@
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os, sys
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from time import time, ctime
|
|
||||||
|
|
||||||
# Configuration settings
|
# Configuration settings
|
||||||
import config
|
import config
|
||||||
@@ -59,6 +57,11 @@ def create_app(app_name=config.APP_NAME):
|
|||||||
|
|
||||||
# Register all the modules
|
# Register all the modules
|
||||||
for m in config.MODULES:
|
for m in config.MODULES:
|
||||||
app.register_module(__import__('%s.views' % m).module)
|
app.logger.debug('Loading module %s' % m)
|
||||||
|
module = __import__(m, globals(), locals(), ['views'], -1)
|
||||||
|
app.register_blueprint(module.views.blueprint)
|
||||||
|
|
||||||
|
app.logger.debug('URL map: %s' % app.url_map)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
@@ -9,6 +9,3 @@
|
|||||||
#
|
#
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
from flask import Module
|
|
||||||
|
|
||||||
module = Module(__name__, 'utils')
|
|
||||||
|
@@ -10,14 +10,17 @@
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from utils import module
|
from flask import Blueprint
|
||||||
from time import time, ctime
|
from time import time, ctime
|
||||||
|
|
||||||
|
# Initialise the module
|
||||||
|
blueprint = Blueprint('utils', __name__)
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# A test page
|
# A test page
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@module.route("/test")
|
@blueprint.route("/test")
|
||||||
def index():
|
def test():
|
||||||
|
|
||||||
output = """
|
output = """
|
||||||
Today is <b>%s</b>
|
Today is <b>%s</b>
|
||||||
@@ -31,6 +34,6 @@ Today is <b>%s</b>
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
# A special URL used to "ping" the server
|
# A special URL used to "ping" the server
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@module.route("/ping")
|
@blueprint.route("/ping")
|
||||||
def ping():
|
def ping():
|
||||||
return "PING"
|
return "PING"
|
||||||
|
Reference in New Issue
Block a user