From 5bcc13c63857adf3ccf15bbcc4899de3e1704c0e Mon Sep 17 00:00:00 2001 From: Daniel Grams Date: Sun, 26 Mar 2023 22:46:58 +0200 Subject: [PATCH] Add admin email test page #388 --- project/base_tasks.py | 4 +++- project/celery.py | 14 ++++++++++++++ project/static/widget-loader.js | 6 ++++++ .../translations/de/LC_MESSAGES/messages.mo | Bin 35509 -> 35508 bytes .../translations/de/LC_MESSAGES/messages.po | 2 +- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/project/base_tasks.py b/project/base_tasks.py index f29caf7..0280a39 100644 --- a/project/base_tasks.py +++ b/project/base_tasks.py @@ -1,4 +1,5 @@ from project import app, celery +from project.celery import force_locale from project.views.utils import send_mail @@ -7,4 +8,5 @@ from project.views.utils import send_mail priority=0, ) def send_mail_task(recipient, subject, template): - send_mail(recipient, subject, template) + with force_locale(): + send_mail(recipient, subject, template) diff --git a/project/celery.py b/project/celery.py index e4b6a4a..9069cc7 100644 --- a/project/celery.py +++ b/project/celery.py @@ -1,6 +1,8 @@ +from contextlib import contextmanager from smtplib import SMTPException from urllib.error import URLError +from babel import Locale from celery import Celery from celery import Task as BaseTask from celery.signals import after_setup_logger, after_setup_task_logger, task_postrun @@ -77,3 +79,15 @@ def close_session(*args, **kwargs): # won't propagate across tasks) with app.app_context(): sqlalchemydb.session.remove() + + +@contextmanager +def force_locale(locale=None): + from project import app + + if not locale: + locale = Locale.parse("de") + + with app.test_request_context() as ctx: + ctx.babel_locale = locale + yield diff --git a/project/static/widget-loader.js b/project/static/widget-loader.js index 2a43e23..6ee1330 100644 --- a/project/static/widget-loader.js +++ b/project/static/widget-loader.js @@ -19,6 +19,12 @@ for (var i = 0; i < elements.length; i++) { initIframeWidget(elements.item(i), i); } + + // Legacy + elements = d.getElementsByClassName("oveda-widget"); + for (var i = 0; i < elements.length; i++) { + initIframeWidget(elements.item(i), i); + } } function initIframeWidget(element, index) { diff --git a/project/translations/de/LC_MESSAGES/messages.mo b/project/translations/de/LC_MESSAGES/messages.mo index 53cabf652821c752223d85b8ee697f434bbe0c09..0f63114b2bdde6e381ea3668fc22f2e2e4e27e59 100644 GIT binary patch delta 545 zcmXZZIZFdU6u|LE0v-_rQDfo}FNi3KARZ}1T(C%~f{hjt#oC~SMU-qb+4UfHE?5Ww z8?lkVu0=}iA|hBQHu?p$7Gk6Saku)tH^aPxxwU+bmqTi;V=&6L>6!n zqj-r1R&f&N_eI9hz!X++8bb#n8ZO}#TG)>>d68LM#W5^l5})&;|33&9LPC~mPf)fikf~40K>q0XiMsAD`mxGjV;zJHkxHDxdYr`}TthEj zVhuiE6TYEt{DZonWJH?5i+ZpT4B`a(a2Z>16MHa=`u&q4&;?$RCFR?>NbVIjUB?p6 z4J^eY96%F2XrqPi7{TLxk#2lO-6)U4*l|!8d;xVGh5D<@GXzBhH@UlD?^5wfG7-;x HDck)AA=F!C diff --git a/project/translations/de/LC_MESSAGES/messages.po b/project/translations/de/LC_MESSAGES/messages.po index 045c90c..a94fbfa 100644 --- a/project/translations/de/LC_MESSAGES/messages.po +++ b/project/translations/de/LC_MESSAGES/messages.po @@ -2107,7 +2107,7 @@ msgstr "Einstellungen erfolgreich aktualisiert" #: project/views/admin.py:108 #, python-format msgid "Test mail from %(site_name)s" -msgstr "Test-Mail from %(site_name)s" +msgstr "Test-Mail von %(site_name)s" #: project/views/admin.py:152 msgid "User successfully updated"