Skip to content

refactor server.py for using Blueprint#3033

Open
JanEisermann wants to merge 10 commits intoOpen-MSS:developfrom
JanEisermann:inkludingBP
Open

refactor server.py for using Blueprint#3033
JanEisermann wants to merge 10 commits intoOpen-MSS:developfrom
JanEisermann:inkludingBP

Conversation

@JanEisermann
Copy link
Contributor

@JanEisermann JanEisermann commented Mar 13, 2026

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:

  • Bug fix. Fixes #
  • New feature (Non-API breaking changes that adds functionality)
  • PR Title follows the convention of <type>: <subject>
  • Commit has unit tests

@JanEisermann JanEisermann changed the title Inkluding bp Inkcuding bp Mar 13, 2026
@JanEisermann JanEisermann changed the title Inkcuding bp Including bp Mar 13, 2026
@JanEisermann JanEisermann changed the title Including bp refactor server.py for using Blueprint Mar 13, 2026
SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '/')

docs_bp = Blueprint(
"docs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -57,21 +57,24 @@ def file_exists(filepath=None):
DOCS_STATIC_DIR = os.path.join(DOCS_SERVER_PATH, 'static')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the section before the first function

logging.warning(message)


def file_exists(filepath=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be when it is duplicated move it to mslib.utils and import it?

return False


DOCS_SERVER_PATH = os.path.dirname(os.path.abspath(mslib.__file__))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the constants to the beginning after the import block, see https://peps.python.org/pep-0008/#constants

@@ -416,7 +416,7 @@ def user_register_handler():
if APP.config['MAIL_ENABLED']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have also a look if we have to use current_app instead of the imported APP

# 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(
Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could that also be moved to a blueprints/docs?

CHAT_BP = Blueprint('chat', __name__)


@CHAT_BP.route('/undo_changes', methods=["POST"])
Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs to operation


@CHAT_BP.route('/get_change_content', methods=['GET'])
@verify_user
def get_change_content():
Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs to operation


@CHAT_BP.route('/set_version_name', methods=['POST'])
@verify_user
def set_version_name():
Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs to operation


@OPERATION_BP.route('/active_users', methods=["GET"])
@verify_user
def active_users():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this maybe can go with status to an info blueprint?

from mslib.mscolab.app import APP
from mslib.utils import conditional_decorator


Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from here that is the part of the blueprint

# 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(
Copy link
Member

@ReimarBauer ReimarBauer Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should become also an own blueprints docs.py

mslib.utils.file_exists
~~~~~~~~~~~~~~~~~

function for app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verifies a given filepath is a file

Copy link
Member

@ReimarBauer ReimarBauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -32,7 +32,7 @@ <h3>Reset Password</h3>
</div>
{% if uri is defined %}
Copy link
Member

@ReimarBauer ReimarBauer Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the name should be changed from status.html to status_password.html

status has too much meanings


mslib.mscolab.blueprints.auth.auth
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mslib.mscolab.blueprints.auth

"""

mslib.mscolab.blueprints.docs.docs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Member

@ReimarBauer ReimarBauer Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mslib.mscolab.blueprints.docs

look also on the others

return _app, sockio, cm, fm, mail


@APP.route('/')
Copy link
Member

@ReimarBauer ReimarBauer Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to go to bp docs



@APP.route('/uploads/<name>/<path:filename>', methods=["GET"])
def uploads(name=None, filename=None):
Copy link
Member

@ReimarBauer ReimarBauer Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to go to bp chat

return render_template("docs/index.html")


@APP.route("/status")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this goes to bp auth

@@ -17,13 +17,13 @@
<div class="container-fluid">
<div class="row" style="background-color:lavender;">
{% if file_exists(imprint) %}
Copy link
Member

@ReimarBauer ReimarBauer Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -->
Copy link
Member

@ReimarBauer ReimarBauer Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc string

Copy link
Member

@ReimarBauer ReimarBauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

have also a look into wms.py. There are some routes for the gallery and the "index" defined

server = WMSServer()


@APP.route('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go to a docs bp



@APP.route("/mss/plots")
def plots():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go to a gallery bp



@APP.route("/mss/code/<path:filename>")
def code(filename):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go to a gallery bp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor server.py for using Blueprint

2 participants