Skip to content

Django updates for local testing #30

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hacktheback/messenger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
mjml_app_id = settings.MJML_APPLICATION_ID
mjml_secret = settings.MJML_SECRET_KEY

import logging

logger = logging.getLogger(__name__)

def _render_template_with_context(html, context):
template = Template(html)
Expand All @@ -19,6 +22,8 @@ def render_mjml(mjml, context=None):
Provided MJML, render it to HTML. Render with context if context is
provided.
"""
if mjml_app_id is None:
return None
req = requests.post(
mjml_api_url,
auth=(mjml_app_id, mjml_secret),
Expand All @@ -37,6 +42,11 @@ def send_emails(subject, recipients, plaintext, html):
Send individual e-mails to each user in the list of recipients with the
subject as `subject`, and the body as `plaintext` and `html`.
"""
if mjml_app_id is None:
logger.info(subject)
logger.info(recipients)
logger.info(plaintext)
return
conn = mail.get_connection()
conn.open()
emails = []
Expand Down
2 changes: 1 addition & 1 deletion hacktheback/rest/forms/admin_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

router.register("food", FoodViewSet, basename="all-foods")

router.register("foodtracker", FoodTrackingViewSet, basename="all-foods")
router.register("foodtracker", FoodTrackingViewSet, basename="foodtracker")

forms_router = routers.NestedSimpleRouter(router, "forms", lookup="form")
forms_router.register(
Expand Down
4 changes: 2 additions & 2 deletions hacktheback/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,5 @@ def media_upload_to_path(instance, filename, sub_dir=None):
)

MJML_API_URL = env.str("MJML_API_URL", default="https://api.mjml.io/v1/render")
MJML_APPLICATION_ID = env.str("MJML_APPLICATION_ID")
MJML_SECRET_KEY = env.str("MJML_SECRET_KEY")
MJML_APPLICATION_ID = env.str("MJML_APPLICATION_ID", default=None)
MJML_SECRET_KEY = env.str("MJML_SECRET_KEY", default=None)
Loading