Skip to content

Commit

Permalink
Bugfixes 2024101702 (#997)
Browse files Browse the repository at this point in the history
* fixed syntax error for send_from_directory and refactored how the version information is returned.

* ensure there's a default value for DEBUG

* Image.ANTIALIAS is now Image.LANCZOS
  • Loading branch information
takinbo authored Oct 17, 2024
1 parent 8d4b77a commit 8284f47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 44 deletions.
2 changes: 1 addition & 1 deletion apollo/odk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def generate_config_qr_code(participant=None):
img = qr_code.make_image(fill_color="black", back_color="white")

thumb_size = (256, 256)
img.thumbnail(thumb_size, Image.ANTIALIAS)
img.thumbnail(thumb_size, Image.LANCZOS)

img.save(img_buffer, format="PNG")
img_buffer.seek(0)
Expand Down
63 changes: 20 additions & 43 deletions apollo/pwa/views_pwa.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,44 @@
# -*- coding: utf-8 -*-
from configparser import ConfigParser, Error
from pathlib import Path

from flask import (
Blueprint, jsonify, make_response, render_template, send_from_directory)
from flask import Blueprint, current_app, jsonify, make_response, render_template, send_from_directory
from flask_babel import gettext as _

from apollo import settings
from apollo.frontend import route

blueprint = Blueprint("pwa", __name__, static_folder="static", template_folder="templates", url_prefix="/pwa")

blueprint = Blueprint('pwa', __name__, static_folder='static',
template_folder='templates', url_prefix='/pwa')


@route(blueprint, '/')
@route(blueprint, "/")
def index():
version_file_path = Path(settings.PROJECT_ROOT).joinpath('version.ini')
if version_file_path.exists():
parser = ConfigParser()
parser.read([version_file_path])

try:
commit = parser.get('settings', 'commit')
except Error:
commit = 'unknown'
else:
commit = 'unknown'
"""Index view for the PWA."""
commit = current_app.config["COMMIT"] or current_app.config["VERSION"]

trace_errors = settings.DEBUG
sentry_dsn = settings.SENTRY_DSN or ''
trace_errors = current_app.config["DEBUG"]
sentry_dsn = current_app.config["SENTRY_DSN"] or ""

context = {'commit': commit, 'trace_errors': trace_errors}
context = {"commit": commit, "trace_errors": trace_errors}
if trace_errors:
context.update(dsn=sentry_dsn)
page_title = _('Apollo')
template_name = 'pwa/index.html'
page_title = _("Apollo")
template_name = "pwa/index.html"

context['page_title'] = page_title
context["page_title"] = page_title

return render_template(template_name, **context)


@route(blueprint, '/serviceworker.js')
@route(blueprint, "/serviceworker.js")
def service_worker():
response = make_response(send_from_directory(
blueprint.static_folder, filename='js/serviceworker.js'))
response.headers['Content-Type'] = 'application/javascript'
"""Serve the service worker."""
response = make_response(send_from_directory(blueprint.static_folder, path="js/serviceworker.js"))
response.headers["Content-Type"] = "application/javascript"
return response


@route(blueprint, '/versioncheck')
@route(blueprint, "/versioncheck")
def version_check():
version_file_path = Path(settings.PROJECT_ROOT).joinpath('version.ini')
if version_file_path.exists():
parser = ConfigParser()
parser.read([version_file_path])

try:
version_info = dict(parser['settings'])

return jsonify(version_info)
except (KeyError, TypeError):
pass
"""Version check endpoint for the PWA."""
version = current_app.config["VERSION"]
commit = current_app.config["COMMIT"] or version

return jsonify({'version': 'unknown', 'commit': 'unknown'})
return jsonify({"version": version, "commit": commit})
1 change: 1 addition & 0 deletions apollo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

# WTF_CSRF_CHECK_DEFAULT = False

DEBUG = False
DEBUG_TB_ENABLED = False

_environment = os.environ.get("FLASK_ENV", "").lower()
Expand Down

0 comments on commit 8284f47

Please sign in to comment.