Skip to content

Commit

Permalink
Merge pull request #151 from stuartmaxwell:uvicorn
Browse files Browse the repository at this point in the history
Uvicorn
  • Loading branch information
stuartmaxwell authored Nov 25, 2024
2 parents 921e01e + d08139d commit 02d3eac
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 259 deletions.
1 change: 0 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
CSRF_TRUSTED_ORIGINS = [f"https://{domain}" for domain in ALLOWED_HOSTS]

INSTALLED_APPS = [
"daphne",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down
1 change: 1 addition & 0 deletions contact_form/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async def send_email_async(message: str, name: str = "", email: str = "") -> Non
payload = {
"from": settings.CONTACT_FORM_FROM,
"to": settings.CONTACT_FORM_TO,
"reply_to": email,
"subject": "Contact Form Submission from stuartm.nz",
"html": f"<ul><li>Name: {name}</li><li>Email: {email}</li><li>Message:<br>{message}</li></ul>",
"text": f"Name: {name}\n\nEmail: {email}\n\nMessage:\n\n{message}\n\n",
Expand Down
23 changes: 22 additions & 1 deletion contact_form/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,28 @@

# A simple view to display the converter HTML template.
async def contact_form(request: HttpRequest, contact_form_title: str = "Contact Form") -> HttpResponse:
"""Render the contact form template."""
"""Async view for the contact form.
This displays the contact form, or processes the form data if it was submitted and then displays the success.
An optional title can be passed in to customise the title of the contact form. This is useful so the form can be
used in multiple places with different titles. For example, in the spf_generator app, the contact form is added to
`urls.py` file as follows:
```python
urlpatterns = [
path("contact/", contact_form, {"contact_form_title": "Request a New SPF Record"}, name="contact_form"),
path("", generate_spf_record, name="spf_generator"),
]
```
Args:
request (HttpRequest): The HTTP request.
contact_form_title (str): The title for the contact form.
Returns:
HttpResponse: The HTTP response.
"""
if request.method == "POST":
form = ContactForm(request.POST)
if form.is_valid():
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
app:
build: .
entrypoint: /app/entrypoint.sh
command: uv run --no-cache daphne -b 0.0.0.0 -p 8000 --proxy-headers config.asgi:application
command: uv run --no-cache gunicorn --worker-tmp-dir /dev/shm --workers=2 --worker-class uvicorn_worker.UvicornWorker --bind 0.0.0.0:8000 config.asgi:application
user: "1000"
environment:
- "S3_BUCKET=${S3_BUCKET}"
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sync-up:

# Run the Django development server
run:
{{uvr}} manage.py runserver
{{uvr}} gunicorn --workers=2 --worker-class uvicorn_worker.UvicornWorker --bind 127.0.0.1:8000 config.asgi:application

# Make migrations
makemigrations:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ dependencies = [
"pygments>=2.18.0",
"djpress-publish-mastodon>=1.0.0",
"httpx>=0.27.2",
"daphne>=4.1.2",
"uvicorn>=0.32.1",
"uvicorn-worker>=0.2.0",
]

[tool.curlylint.rules]
Expand Down
291 changes: 37 additions & 254 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit 02d3eac

Please sign in to comment.