refactor server.py for using Blueprint#3033
refactor server.py for using Blueprint#3033JanEisermann wants to merge 10 commits intoOpen-MSS:developfrom
Conversation
mslib/mswms/app/__init__.py
Outdated
| SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '/') | ||
|
|
||
| docs_bp = Blueprint( | ||
| "docs", |
There was a problem hiding this comment.
capital letters, see https://peps.python.org/pep-0008/#constants
mslib/mscolab/app/__init__.py
Outdated
| # This can be used to set a location by SCRIPT_NAME for testing. e.g. export SCRIPT_NAME=/demo/ | ||
| SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '/') | ||
|
|
||
| docs_bp = Blueprint( |
There was a problem hiding this comment.
capital letters, see https://peps.python.org/pep-0008/#constants
| @@ -57,21 +57,24 @@ def file_exists(filepath=None): | |||
| DOCS_STATIC_DIR = os.path.join(DOCS_SERVER_PATH, 'static') | |||
There was a problem hiding this comment.
move the section before the first function
mslib/mswms/app/__init__.py
Outdated
| logging.warning(message) | ||
|
|
||
|
|
||
| def file_exists(filepath=None): |
There was a problem hiding this comment.
may be when it is duplicated move it to mslib.utils and import it?
mslib/mswms/app/__init__.py
Outdated
| return False | ||
|
|
||
|
|
||
| DOCS_SERVER_PATH = os.path.dirname(os.path.abspath(mslib.__file__)) |
There was a problem hiding this comment.
move the constants to the beginning after the import block, see https://peps.python.org/pep-0008/#constants
mslib/mscolab/server.py
Outdated
| @@ -416,7 +416,7 @@ def user_register_handler(): | |||
| if APP.config['MAIL_ENABLED']: | |||
There was a problem hiding this comment.
have also a look if we have to use current_app instead of the imported APP
mslib/mscolab/app/__init__.py
Outdated
| # This can be used to set a location by SCRIPT_NAME for testing. e.g. export SCRIPT_NAME=/demo/ | ||
| SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '/') | ||
|
|
||
| DOCS_BP = Blueprint( |
There was a problem hiding this comment.
could that also be moved to a blueprints/docs?
| CHAT_BP = Blueprint('chat', __name__) | ||
|
|
||
|
|
||
| @CHAT_BP.route('/undo_changes', methods=["POST"]) |
There was a problem hiding this comment.
this belongs to operation
when the filemanager "fm" is involed this goes to operation
the chatmanager "cm" makes it to chat blueprint
|
|
||
|
|
||
| @CHAT_BP.route('/get_all_changes', methods=['GET']) | ||
| @verify_user |
There was a problem hiding this comment.
this belongs to operation
|
|
||
| @CHAT_BP.route('/get_change_content', methods=['GET']) | ||
| @verify_user | ||
| def get_change_content(): |
There was a problem hiding this comment.
this belongs to operation
|
|
||
| @CHAT_BP.route('/set_version_name', methods=['POST']) | ||
| @verify_user | ||
| def set_version_name(): |
There was a problem hiding this comment.
this belongs to operation
|
|
||
| @OPERATION_BP.route('/active_users', methods=["GET"]) | ||
| @verify_user | ||
| def active_users(): |
There was a problem hiding this comment.
this maybe can go with status to an info blueprint?
| from mslib.mscolab.app import APP | ||
| from mslib.utils import conditional_decorator | ||
|
|
||
|
|
There was a problem hiding this comment.
The not route related code should be on an other place
check_login, register_user ... verify_user these should be not in the blueprint file
Please look if they can be moved to mslib.utils.auth.py and imported where needed
| return wrapper | ||
|
|
||
|
|
||
| AUTH_BP = Blueprint('auth', __name__) |
There was a problem hiding this comment.
from here that is the part of the blueprint
mslib/mswms/app/__init__.py
Outdated
| # This can be used to set a location by SCRIPT_NAME for testing. e.g. export SCRIPT_NAME=/demo/ | ||
| SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '/') | ||
|
|
||
| DOCS_BP = Blueprint( |
There was a problem hiding this comment.
this should become also an own blueprints docs.py
mslib/utils/file_exists.py
Outdated
| mslib.utils.file_exists | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| function for app |
There was a problem hiding this comment.
verifies a given filepath is a file
ReimarBauer
left a comment
There was a problem hiding this comment.
That's good progress. We can already see it's becoming much more readable. You need to rearrange a few things.
The blueprints should contain as few additional functions as possible.
Especially not ones that need to be imported from other blueprints.
see comments
efd14d0 to
570f809
Compare
…luding templates)
| @@ -32,7 +32,7 @@ <h3>Reset Password</h3> | |||
| </div> | |||
| {% if uri is defined %} | |||
There was a problem hiding this comment.
maybe the name should be changed from status.html to status_password.html
status has too much meanings
|
|
||
| mslib.mscolab.blueprints.auth.auth | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
There was a problem hiding this comment.
mslib.mscolab.blueprints.auth
| """ | ||
|
|
||
| mslib.mscolab.blueprints.docs.docs | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
There was a problem hiding this comment.
mslib.mscolab.blueprints.docs
look also on the others
| return _app, sockio, cm, fm, mail | ||
|
|
||
|
|
||
| @APP.route('/') |
There was a problem hiding this comment.
this has to go to bp docs
|
|
||
|
|
||
| @APP.route('/uploads/<name>/<path:filename>', methods=["GET"]) | ||
| def uploads(name=None, filename=None): |
There was a problem hiding this comment.
this has to go to bp chat
| return render_template("docs/index.html") | ||
|
|
||
|
|
||
| @APP.route("/status") |
| @@ -17,13 +17,13 @@ | |||
| <div class="container-fluid"> | |||
| <div class="row" style="background-color:lavender;"> | |||
| {% if file_exists(imprint) %} | |||
There was a problem hiding this comment.
the file has to go to mscolab.blueprints.docs.templates and msmw.blueprints.docs.templates
one move one copy
| <meta name="author" content="authors of MSS"> | ||
| <link rel='shortcut icon' type='image/x-icon' href="{{ url_for('favicons') }}"> | ||
| <link rel='shortcut icon' type='image/x-icon' href="{{ url_for('docs.favicons') }}"> | ||
| <title>Mission Support System Collaboration Platform</title><!-- Bootstrap core CSS --> |
There was a problem hiding this comment.
the file has to go to mscolab.blueprints.docs.templates and msmw.blueprints.docs.templates
one move one copy
| @@ -28,13 +28,21 @@ | |||
| import logging | |||
ReimarBauer
left a comment
There was a problem hiding this comment.
see comments
have also a look into wms.py. There are some routes for the gallery and the "index" defined
| server = WMSServer() | ||
|
|
||
|
|
||
| @APP.route('/') |
There was a problem hiding this comment.
this should go to a docs bp
|
|
||
|
|
||
| @APP.route("/mss/plots") | ||
| def plots(): |
There was a problem hiding this comment.
this should go to a gallery bp
|
|
||
|
|
||
| @APP.route("/mss/code/<path:filename>") | ||
| def code(filename): |
There was a problem hiding this comment.
this should go to a gallery bp
Purpose of PR?:
Fixes #2081
Does this PR introduce a breaking change?
included Blueprint, fixed test_load_no_file
If the changes in this PR are manually verified, list down the scenarios covered::
tests succeed, not manually verified
Additional information for reviewer? :
Mention if this PR is part of any design or a continuation of previous PRs
Does this PR results in some Documentation changes?
If yes, include the list of Documentation changes
Checklist:
<type>: <subject>