Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ece2fb

Browse files
committed
[pages] use flask_config dict for remaining fields
1 parent 18ac1f8 commit 3ece2fb

4 files changed

Lines changed: 18 additions & 19 deletions

File tree

inginious/frontend/app.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ def _put_configuration_defaults(config):
4141
:param config: the basic configuration as a dict
4242
:return: the same dict, but with defaults for some unfilled parameters
4343
"""
44-
if 'allowed_file_extensions' not in config:
45-
config['allowed_file_extensions'] = [".c", ".cpp", ".java", ".oz", ".zip", ".tar.gz", ".tar.bz2", ".txt"]
46-
if 'max_file_size' not in config:
47-
config['max_file_size'] = 1024 * 1024
44+
config["ALLOWED_FILE_EXTENSIONS"] = config.get(
45+
'allowed_file_extensions',
46+
[".c", ".cpp", ".java", ".oz", ".zip", ".tar.gz", ".tar.bz2", ".txt"]
47+
)
48+
49+
config["MAX_FILE_SIZE"] = config.get('max_file_size', 1024 * 1024)
4850

4951
if 'session_parameters' not in config or 'secret_key' not in config['session_parameters']:
5052
print("Please define a secret_key in the session_parameters part of the configuration.", file=sys.stderr)
@@ -61,6 +63,7 @@ def _put_configuration_defaults(config):
6163

6264
if 'session_parameters' not in config:
6365
config['session_parameters'] = {}
66+
6467
default_session_parameters = {
6568
"cookie_name": "inginious_session_id",
6669
"cookie_domain": None,
@@ -93,6 +96,7 @@ def _put_configuration_defaults(config):
9396
config["MAIL_PASSWORD"] = smtp_conf.get("password", None)
9497
config["MAIL_DEFAULT_SENDER"] = smtp_conf.get("sendername", "[email protected]")
9598

99+
config["STATIC_DIRECTORY"] = config.get("static_directory", "./static")
96100
config["SUPERADMINS"] = config.get("superadmins", [])
97101
config["ALLOW_DELETION"] = config.get("allow_deletion", True)
98102
config["ALLOW_REGISTRATION"] = config.get("allow_registration", True)
@@ -195,7 +199,6 @@ def get_app(config):
195199
flask_app.jinja_env.globals["get_homepath"] = get_homepath
196200
flask_app.jinja_env.globals["get_path"] = get_path
197201
flask_app.jinja_env.globals["pkg_version"] = __version__
198-
flask_app.jinja_env.globals["sentry_io_url"] = config.get("SENTRY_IO_URL")
199202
flask_app.jinja_env.globals["user_manager"] = user_manager
200203
flask_app.jinja_env.globals["is_tos_defined"] = flask_app.is_tos_defined
201204

@@ -229,8 +232,6 @@ def flask_internalerror(e):
229232
flask_app.client = client
230233
flask_app.available_languages = available_languages
231234
flask_app.available_indentation_types = available_indentation_types
232-
flask_app.welcome_page = config.get("WELCOME_PAGE", None)
233-
flask_app.static_directory = config.get("STATIC_DIRECTORY", "./static")
234235

235236
# Init the mapping of the app
236237
if config.get("MAINTENANCE", False):

inginious/frontend/pages/index.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# more information about the licensing of this file.
55

66
""" Index page """
7-
from flask import redirect, url_for
7+
from flask import current_app, redirect, url_for
88
from inginious.frontend.pages.utils import INGIniousStaticPage
99

1010

@@ -13,12 +13,11 @@ class IndexPage(INGIniousStaticPage):
1313

1414
def GET(self): # pylint: disable=arguments-differ
1515
""" Display main course list page """
16-
if not self.app.welcome_page:
17-
return redirect(self.app.get_path("courselist"))
18-
return self.show_page(self.app.welcome_page)
16+
if "WELCOME_PAGE" in current_app.config:
17+
return self.show_page(current_app.config["WELCOME_PAGE"])
18+
return redirect(self.app.get_path("courselist"))
19+
1920

2021
def POST(self): # pylint: disable=arguments-differ
2122
""" Display main course list page """
22-
if not self.app.welcome_page:
23-
return redirect(self.app.get_path("courselist"))
24-
return self.show_page(self.app.welcome_page)
23+
return self.GET()

inginious/frontend/pages/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
from typing import List, Dict
1010

1111
import flask
12-
from flask import redirect, render_template, session
12+
from flask import current_app, redirect, render_template, session
1313
from flask.views import MethodView
1414
from werkzeug.exceptions import NotFound, NotAcceptable, MethodNotAllowed
1515

16-
from inginious.common.filesystems import FileSystemProvider
1716
from inginious.client.client import Client
1817
from inginious.common import custom_yaml
1918
from inginious.frontend.environment_types import get_all_env_types
@@ -233,7 +232,7 @@ def POST(self, pageid):
233232
return self.show_page(pageid)
234233

235234
def show_page(self, page):
236-
static_directory = self.app.static_directory
235+
static_directory = current_app.config["STATIC_DIRECTORY"]
237236
language = session.language
238237

239238
# Check for the file

inginious/frontend/templates/layout.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
<meta name="msapplication-TileImage" content="{{get_homepath()}}/static/icons/mstile-144x144.png">
6262
<meta name="msapplication-config" content="{{get_homepath()}}/static/icons/browserconfig.xml">
6363

64-
{% if sentry_io_url %}
64+
{% if config.SENTRY_IO_URL %}
6565
<script src="{{get_homepath()}}/static/js/libs/sentry-io-bundle.min.js?version=5.4.3" type="text/javascript" charset="utf-8"></script>
6666
<script>
67-
Sentry.init({ dsn: "{{sentry_io_url}}" });
67+
Sentry.init({ dsn: "{{config.SENTRY_IO_URL}}" });
6868
{% if user_manager is defined and session.loggedin %}
6969
Sentry.configureScope(function(scope) {
7070
scope.setUser({

0 commit comments

Comments
 (0)