Skip to content

Commit

Permalink
Merge pull request #159 from stuartmaxwell:wsgi-testing
Browse files Browse the repository at this point in the history
Wsgi-testing
  • Loading branch information
stuartmaxwell authored Nov 27, 2024
2 parents e56ea99 + 448244e commit c1a967e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 5 deletions.
24 changes: 22 additions & 2 deletions contact_form/tasks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
"""Contact Form Tasks."""

import logging

import httpx
from django.conf import settings

logger = logging.getLogger(__name__)

SUCESS_STATUS_CODE = 200


async def send_email_async(message: str, name: str = "", email: str = "") -> None:
"""Asynchronously send an email using Resend's API."""
"""Asynchronously send an email using Resend's API.
Args:
message (str): The message to send.
name (str): The name of the sender.
email (str): The email of the sender.
Returns:
None: The function does not return anything.
"""
url = "https://api.resend.com/emails"

headers = {
"Authorization": f"Bearer {settings.RESEND_API_KEY}",
"Content-Type": "application/json",
Expand All @@ -22,4 +38,8 @@ async def send_email_async(message: str, name: str = "", email: str = "") -> Non
}

async with httpx.AsyncClient() as client:
await client.post(url, headers=headers, json=payload)
response = await client.post(url, headers=headers, json=payload)
if response.status_code != SUCESS_STATUS_CODE:
logger.error(f"Failed to send email: {response.status_code}. Payload: {payload}")
else:
logger.debug(f"Email sent successfully: {response.status_code}. Payload: {payload}")
24 changes: 24 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,27 @@ article {
.highlight pre {
background-color: #2e3440;
}

/* Message Alert Styles */
.message {
border-radius: 0.5em;
color: #2e3440;
margin-bottom: var(--pico-spacing);
padding: 0.5rem;
}

.alert-info {
background-color: #5e81ac;
}

.alert-success {
background-color: #a3be8c;
}

.alert-warning {
background-color: #ebcb8b;
}

.alert-danger {
background-color: #bf616a;
}
1 change: 0 additions & 1 deletion static/js/htmx_2.0.0.min.js

This file was deleted.

1 change: 1 addition & 0 deletions static/js/htmx_203.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
{% block header %}{% endblock %}

<main class="{% block main_classes %}{% endblock %}">
{% include "snippets/messages.html" %}
{% block content %}{% endblock %}
</main>

Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{% block head %}
{% rss_link %}
<script src="https://unpkg.com/[email protected]" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script>
<script src="{% static "js/htmx_203.min.js" %}"></script>
{% endblock head %}

{% block header %}
Expand Down
9 changes: 9 additions & 0 deletions templates/snippets/messages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% if messages %}

{% for message in messages %}
<div class="container-fluid message {{ message.tags }}">
{{ message }}
</div>
{% endfor %}

{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block title %}Timezone Converter{% endblock %}

{% block head %}
<script src="{% static "js/htmx_2.0.0.min.js" %}"></script>
<script src="{% static "js/htmx_203.min.js" %}"></script>
{% endblock head %}

{% block content %}
Expand Down

0 comments on commit c1a967e

Please sign in to comment.