-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨(emails) use mjml to generate html and text emails
- Loading branch information
Showing
17 changed files
with
266 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,5 +58,6 @@ EMAIL_USE_TLS=False | |
[email protected] | ||
EMAIL_RATE_LIMIT=100/m | ||
EMAIL_MAX_RETRIES=3 | ||
EMAIL_SITE_NAME=FUN | ||
EMAIL_SITE_NAME="France Université Numérique" | ||
EMAIL_SITE_BASE_URL=https://fun-mooc.fr | ||
EMAIL_SITE_LOGIN_URL=https://lms.fun-mooc.fr/login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,11 +61,12 @@ class Settings(BaseSettings): | |
EMAIL_HOST_PASSWORD: str = "" | ||
EMAIL_PORT: int = 1025 | ||
EMAIL_USE_TLS: bool = False | ||
EMAIL_FROM: str = "[email protected]" | ||
EMAIL_FROM: str = "" | ||
EMAIL_RATE_LIMIT: str = "100/m" | ||
EMAIL_MAX_RETRIES: int = 3 | ||
EMAIL_SITE_NAME: str = "FUN" | ||
EMAIL_SITE_BASE_URL: str = "https://fun-mooc.fr" | ||
EMAIL_SITE_NAME: str = "" | ||
EMAIL_SITE_BASE_URL: str = "" | ||
EMAIL_SITE_LOGIN_URL: str = "" | ||
|
||
# Celery | ||
broker_url: str = Field("redis://redis:6379/0", alias="MORK_CELERY_BROKER_URL") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# noqa: D104 | ||
"""Template tags module.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
"""Tests for Mork extra Jinja tags.""" | ||
|
||
from mork.templatetags.extra_tags import Base64StaticTag | ||
from mork.templatetags.extra_tags import SVGStaticTag | ||
from mork.tests.conftest import TEST_STATIC_PATH | ||
|
||
|
||
def test_base64tag_render(monkeypatch): | ||
"""Test the Base64StaticTag `render` method returns file encoded in base64.""" | ||
static_filepath = TEST_STATIC_PATH / "images/red-square.webp" | ||
def test_svgstatictag_render(monkeypatch): | ||
"""Test the SVGStaticTag `render` method returns file encoded in base64.""" | ||
static_filepath = TEST_STATIC_PATH / "images/red-square.svg" | ||
|
||
red_square_base64 = ( | ||
"data:image/webp;base64, UklGRjAAAABXRUJQVlA4ICQAAABwAQCdASoBAAEACTD+J7ACdA" | ||
"FAAAD+0MkjDRr8XewjvuzAAAA=" | ||
) | ||
red_square_base64 = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxIDEiPgo8cGF0aCBkPSJNMCwwaDF2MUgwIiBmaWxsPSIjZjAwIi8+Cjwvc3ZnPg==" # noqa: E501 | ||
|
||
monkeypatch.setattr( | ||
"mork.templatetags.extra_tags.Base64StaticTag.__init__", lambda x: None | ||
"mork.templatetags.extra_tags.SVGStaticTag.__init__", lambda x: None | ||
) | ||
|
||
assert Base64StaticTag().render(static_filepath) == red_square_base64 | ||
assert SVGStaticTag().render(static_filepath) == red_square_base64 | ||
|
||
|
||
def test_base64tag_render_unknown_file(monkeypatch): | ||
"""Test that the Base64StaticTag `render` method should return an empty string.""" | ||
"""Test that the SVGStaticTag `render` method should return an empty string.""" | ||
static_filepath = "unknown-static-file.txt" | ||
|
||
monkeypatch.setattr( | ||
"mork.templatetags.extra_tags.Base64StaticTag.__init__", lambda x: None | ||
"mork.templatetags.extra_tags.SVGStaticTag.__init__", lambda x: None | ||
) | ||
|
||
assert Base64StaticTag().render(static_filepath) == "" | ||
assert SVGStaticTag().render(static_filepath) == "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
"""Tests for utilitary functions.""" | ||
"""Tests for utility functions.""" | ||
|
||
from mork.tests.conftest import TEST_STATIC_PATH | ||
from mork.utils import image_to_base64 | ||
from mork.utils import svg_to_datauri | ||
|
||
|
||
def test_utils_image_to_base64_path(): | ||
def test_utils_svg_to_datauri_path(): | ||
"""Image to base64 from path.""" | ||
|
||
red_square_base64 = ( | ||
"data:image/webp;base64, UklGRjAAAABXRUJQVlA4ICQAAABwAQCdASoBAAEACTD+J7ACdA" | ||
"FAAAD+0MkjDRr8XewjvuzAAAA=" | ||
) | ||
red_square_base64 = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxIDEiPgo8cGF0aCBkPSJNMCwwaDF2MUgwIiBmaWxsPSIjZjAwIi8+Cjwvc3ZnPg==" # noqa: E501 | ||
|
||
assert ( | ||
image_to_base64(TEST_STATIC_PATH / "images/red-square.webp") | ||
== red_square_base64 | ||
svg_to_datauri(TEST_STATIC_PATH / "images/red-square.svg") == red_square_base64 | ||
) | ||
|
||
assert image_to_base64("not_found.png") == "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,10 @@ | ||
"""Utilitary functions.""" | ||
"""Utility functions.""" | ||
|
||
import base64 | ||
from pathlib import Path | ||
|
||
from PIL import ImageFile as PillowImageFile | ||
from datauri import DataURI | ||
|
||
|
||
def image_to_base64(path: Path | str): | ||
"""Return the src string of the base64 encoding of an image. | ||
Strongly inspired by Joanie's `image_to_base64`. | ||
""" | ||
pil_parser = PillowImageFile.Parser() | ||
try: | ||
file = open(path, "rb") | ||
except OSError: | ||
return "" | ||
|
||
try: | ||
image_data = file.read() | ||
if not image_data: | ||
return "" | ||
pil_parser.feed(image_data) | ||
if pil_parser.image: | ||
mime_type = pil_parser.image.get_format_mimetype() | ||
encoded_string = base64.b64encode(image_data) | ||
return f"data:{mime_type:s};base64, {encoded_string.decode('utf-8'):s}" | ||
return "" | ||
finally: | ||
file.close() | ||
def svg_to_datauri(path: Path | str): | ||
"""Return the data URI string of an SVG image.""" | ||
return str(DataURI.from_file(path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
{ | ||
"name": "mail_mjml", | ||
"version": "2.5.1", | ||
"description": "An util to generate html and text jinja templates from mjml templates", | ||
"type": "module", | ||
"dependencies": { | ||
"@html-to/text-cli": "0.5.4", | ||
"mjml": "4.15.3" | ||
}, | ||
"private": true, | ||
"scripts": { | ||
"build-mjml-to-html": "./bin/mjml-to-html", | ||
"build-html-to-plain-text": "./bin/html-to-plain-text", | ||
"build": "yarn build-mjml-to-html; yarn build-html-to-plain-text;" | ||
}, | ||
"volta": { | ||
"node": "16.15.1" | ||
}, | ||
"repository": "https://github.com/openfun/mork", | ||
"author": "France Université Numérique", | ||
"license": "MIT" | ||
} | ||
|
||
"name": "mail_mjml", | ||
"version": "2.5.1", | ||
"description": "An util to generate html and text jinja templates from mjml templates", | ||
"type": "module", | ||
"dependencies": { | ||
"@html-to/text-cli": "0.5.4", | ||
"mjml": "4.15.3" | ||
}, | ||
"private": true, | ||
"scripts": { | ||
"build-mjml-to-html": "./bin/mjml-to-html", | ||
"build-html-to-plain-text": "./bin/html-to-plain-text", | ||
"build": "yarn build-mjml-to-html; yarn build-html-to-plain-text;" | ||
}, | ||
"volta": { | ||
"node": "16.15.1" | ||
}, | ||
"repository": "https://github.com/openfun/mork", | ||
"author": "France Université Numérique", | ||
"license": "MIT" | ||
} |