mirror of
https://github.com/Superredstone/patrickcanal.it.git
synced 2026-09-20 09:41:14 +02:00
feat(portfolio): add email contact
This commit is contained in:
@@ -10,6 +10,7 @@ devenv.local.yaml
|
|||||||
|
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
|
|
||||||
|
.ruff_cache
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
local_settings.py
|
local_settings.py
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# patrickcanal.it
|
||||||
|
|
||||||
|
## Required variables
|
||||||
|
### Portfolio
|
||||||
|
- MAILER_HOST
|
||||||
|
- EMAIL_CONTACT
|
||||||
+15
-15
@@ -3,11 +3,11 @@
|
|||||||
"devenv": {
|
"devenv": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "src/modules",
|
"dir": "src/modules",
|
||||||
"lastModified": 1786975632,
|
"lastModified": 1789304775,
|
||||||
"narHash": "sha256-3N/pfn4/ADlkTzHJWgClmKD1mTLyVJNFxLbDMMHl/xw=",
|
"narHash": "sha256-WPuZ7LbqlQ8n+kocw8oo4sNvHy//LXBTAHOqRDp5I5c=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "devenv",
|
"repo": "devenv",
|
||||||
"rev": "c972cb46d511e690c942e6ee3309a7e8b9a20475",
|
"rev": "e6f5e1e6cda3a75bad3e0a4af97eb9e70bc9e127",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -55,11 +55,11 @@
|
|||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1784288435,
|
"lastModified": 1788267358,
|
||||||
"narHash": "sha256-ReRHaLgr/uVqdD8afFSn+myXIfpHeOhP0yYe0TJqAA8=",
|
"narHash": "sha256-nt+lUqYVpc9Y6JeMd2WmXzCDojasdadKo0mWcluvY2Y=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "git-hooks.nix",
|
"repo": "git-hooks.nix",
|
||||||
"rev": "43b3c1ab9d40fb1dbb008f451988a91e375825e9",
|
"rev": "27555e2624241fb116b49095df4caaee85a25691",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -70,11 +70,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1782918843,
|
"lastModified": 1787631388,
|
||||||
"narHash": "sha256-ETYnV9U7Sr+A45dohzZdfCZKOss4qrTkO+wgNZNvEc0=",
|
"narHash": "sha256-vMiXptXarfSdJb1Gkc+FYVOAibuBRj7qxGa8z68q1Uw=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "e8273b29fe1390ec8d4603f2477357555291432e",
|
"rev": "ac6b2166e7a9375683b8e98f860f273222337b16",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -108,11 +108,11 @@
|
|||||||
"nixpkgs-src": {
|
"nixpkgs-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1786098110,
|
"lastModified": 1787394516,
|
||||||
"narHash": "sha256-shi1tjDhCGGd0kIgVPNY03V8NBWSTzhMSFDb7IqSoec=",
|
"narHash": "sha256-pRGOQSClnXNI2iLUG6DYpsGvYcuw0drOutVZFTJNw90=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "afb4584a80bbf779ce0f691509ff902d188c2b3d",
|
"rev": "c8f90650c15282fa8656a041bfbbd2403997a9a7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -127,11 +127,11 @@
|
|||||||
"nixpkgs-src": "nixpkgs-src"
|
"nixpkgs-src": "nixpkgs-src"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1786472144,
|
"lastModified": 1787753358,
|
||||||
"narHash": "sha256-W1wLGKZKGtnTWGRFgjbsVQleuO6jgMweaSAbFltLkN0=",
|
"narHash": "sha256-Tl77VbWyAKrOfRNQhL6JbQtb/MLzbYa/1RG1gWWfICk=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "devenv-nixpkgs",
|
"repo": "devenv-nixpkgs",
|
||||||
"rev": "ea21d30f66a051c7cd750692a2af8d56e0ec4bfb",
|
"rev": "256551e45f6303e142ab4a98be1bf243feb77dc0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
@@ -11,6 +10,5 @@
|
|||||||
enable = true;
|
enable = true;
|
||||||
requirements = ./requirements.txt;
|
requirements = ./requirements.txt;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'post_office',
|
||||||
'portfolio'
|
'portfolio'
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -114,6 +115,7 @@ USE_I18N = True
|
|||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
from patrickcanal_it.local_settings import *
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/6.1/howto/static-files/
|
# https://docs.djangoproject.com/en/6.1/howto/static-files/
|
||||||
@@ -126,9 +128,16 @@ STATICFILES_DIRS = [
|
|||||||
|
|
||||||
# Email
|
# Email
|
||||||
# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration
|
# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration
|
||||||
|
EMAIL_BACKEND = 'post_office.EmailBackend'
|
||||||
|
# TODO: Replace old mail backend with new once post_office supports it
|
||||||
|
# MAILERS = {
|
||||||
|
# 'default': {
|
||||||
|
# 'BACKEND': 'post_office.EmailBackend',
|
||||||
|
# },
|
||||||
|
# 'smtp': {
|
||||||
|
# 'BACKEND': 'django.core.mail.backends.smtp.EmailBackend',
|
||||||
|
# 'OPTIONS': {'host': MAILER_HOST, 'port': 587},
|
||||||
|
# },
|
||||||
|
# }
|
||||||
|
# POST_OFFICE = {'DEFAULT_MAILER': 'smtp'}
|
||||||
|
|
||||||
MAILERS = {
|
|
||||||
'default': {
|
|
||||||
'BACKEND': 'django.core.mail.backends.console.EmailBackend',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<link rel="stylesheet" href="{% static 'fontawesome-7/css/all.min.css' %}">
|
<link rel="stylesheet" href="{% static 'fontawesome-7/css/all.min.css' %}">
|
||||||
<script src="{% static 'tabler/tabler.min.js' %}"></script>
|
<script src="{% static 'tabler/tabler.min.js' %}"></script>
|
||||||
<script src="{% static 'tailwindcss/tailwindcss.min.js' %}"></script>
|
<script src="{% static 'tailwindcss/tailwindcss.min.js' %}"></script>
|
||||||
|
<script src="{% static 'htmx/htmx.min.js' %}"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="d-flex flex-column">
|
<body class="d-flex flex-column">
|
||||||
<header class="navbar navbar-expand-md d-print-none">
|
<header class="navbar navbar-expand-md d-print-none">
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
|
||||||
|
class TablerEmailInput(forms.EmailInput):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
attrs = kwargs.setdefault("attrs", {})
|
||||||
|
attrs.update(
|
||||||
|
{
|
||||||
|
"class": "form-control",
|
||||||
|
"placeholder": "example@mail.com",
|
||||||
|
"autocomplete": "off",
|
||||||
|
"minlength": "4",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class TablerTextInput(forms.TextInput):
|
||||||
|
def __init__(self, placeholder=None, *args, **kwargs):
|
||||||
|
attrs = kwargs.setdefault("attrs", {})
|
||||||
|
attrs.update(
|
||||||
|
{
|
||||||
|
"class": "form-control",
|
||||||
|
"placeholder": placeholder,
|
||||||
|
"autocomplete": "off",
|
||||||
|
"minlength": "4",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class TablerTextArea(forms.Textarea):
|
||||||
|
def __init__(self, placeholder=None, *args, **kwargs):
|
||||||
|
attrs = kwargs.setdefault("attrs", {})
|
||||||
|
attrs.update(
|
||||||
|
{
|
||||||
|
"class": "form-control",
|
||||||
|
"placeholder": placeholder,
|
||||||
|
"autocomplete": "off",
|
||||||
|
"minlength": "4",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class ContactForm(forms.Form):
|
||||||
|
email = forms.EmailField(max_length=50, min_length=4, widget=TablerEmailInput())
|
||||||
|
subject = forms.CharField(
|
||||||
|
max_length=200,
|
||||||
|
min_length=4,
|
||||||
|
widget=TablerTextInput(placeholder=_("Your message")),
|
||||||
|
)
|
||||||
|
message = forms.CharField(max_length=5000, min_length=10, widget=TablerTextArea())
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n static %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="container mt-4 fs-2">
|
||||||
|
<div>{% trans "Thanks for contacting me!" %}</div>
|
||||||
|
<a href="{% url 'index' %}" class="btn btn-primary mt-4">{% trans "Go back" %}</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<a href="{% url 'projects' %}" class="btn btn-primary btn-lg me-2">My projects</a>
|
<a href="{% url 'projects' %}" class="btn btn-primary btn-lg me-2">My projects</a>
|
||||||
<a href="" class="btn btn-outline-secondary btn-lg">Contact me</a>
|
<a href="#contact-me" class="btn btn-outline-secondary btn-lg">Contact me</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -111,5 +111,35 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="hr"></div>
|
||||||
|
<div class="row d-flex justify-content-center mb-4">
|
||||||
|
<div class="card col-md-6" id="contact-me">
|
||||||
|
<div class="card-body">
|
||||||
|
<h3 class="card-title fs-2">
|
||||||
|
<b>
|
||||||
|
<i class="fa-solid fa-envelope"></i>
|
||||||
|
{% trans "Contact me" %}
|
||||||
|
</b>
|
||||||
|
</h3>
|
||||||
|
<form action="{% url 'contact' %}" method="post" id="contact-form">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% for field in contact_form %}
|
||||||
|
<div class="form-floating mb-2">
|
||||||
|
{{ field }}
|
||||||
|
<label for="{{ field.id }}">{{ field.label }}</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<button class="btn btn-primary" type="submit">{% trans "Send" %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<style>
|
||||||
|
textarea {
|
||||||
|
height: 10rem !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ from portfolio import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.PortfolioView.as_view(), name="portfolio"),
|
path("", views.PortfolioView.as_view(), name="portfolio"),
|
||||||
path("projects/", views.ProjectList.as_view(), name="projects"),
|
path("projects/", views.ProjectList.as_view(), name="projects"),
|
||||||
|
path("contact/", views.ContactSend.as_view(), name="contact"),
|
||||||
]
|
]
|
||||||
|
|||||||
+28
-2
@@ -1,17 +1,43 @@
|
|||||||
|
from django.conf import settings
|
||||||
|
from django.http.response import HttpResponseBadRequest
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import ListView, TemplateView
|
from django.views.generic import ListView, TemplateView
|
||||||
|
from post_office import mail
|
||||||
|
|
||||||
from portfolio import models
|
from portfolio import forms, models
|
||||||
|
|
||||||
|
|
||||||
class PortfolioView(TemplateView):
|
class PortfolioView(TemplateView):
|
||||||
template_name = "index.html"
|
template_name = "index.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
contact_form = forms.ContactForm()
|
||||||
return {
|
return {
|
||||||
"job_experiences": models.JobExperience.objects.all().order_by("-start")
|
"job_experiences": models.JobExperience.objects.all().order_by("-start"),
|
||||||
|
"contact_form": contact_form,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ProjectList(ListView):
|
class ProjectList(ListView):
|
||||||
template_name = "project_list.html"
|
template_name = "project_list.html"
|
||||||
model = models.Project
|
model = models.Project
|
||||||
|
|
||||||
|
|
||||||
|
class ContactSend(TemplateView):
|
||||||
|
template_name = "contact_thanks.html"
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
form = forms.ContactForm(request.POST)
|
||||||
|
|
||||||
|
if not form.is_valid():
|
||||||
|
return HttpResponseBadRequest(_("Invalid request"))
|
||||||
|
|
||||||
|
mail.send(
|
||||||
|
subject=form.cleaned_data["subject"],
|
||||||
|
message=form.cleaned_data["message"],
|
||||||
|
sender=settings.EMAIL_HOST_USER,
|
||||||
|
cc=form.cleaned_data["email"],
|
||||||
|
recipients=[settings.EMAIL_CONTACT],
|
||||||
|
)
|
||||||
|
|
||||||
|
return super().get(request, *args, **kwargs)
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
django
|
django
|
||||||
djlint
|
djlint
|
||||||
|
django-post_office
|
||||||
|
|||||||
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user