mirror of
https://github.com/Superredstone/patrickcanal.it.git
synced 2026-09-28 05:07:53 +02:00
feat(portfolio): add email contact
This commit is contained in:
@@ -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 class="text-center">
|
||||
<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>
|
||||
@@ -111,5 +111,35 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</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>
|
||||
<style>
|
||||
textarea {
|
||||
height: 10rem !important;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -5,4 +5,5 @@ from portfolio import views
|
||||
urlpatterns = [
|
||||
path("", views.PortfolioView.as_view(), name="portfolio"),
|
||||
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 post_office import mail
|
||||
|
||||
from portfolio import models
|
||||
from portfolio import forms, models
|
||||
|
||||
|
||||
class PortfolioView(TemplateView):
|
||||
template_name = "index.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
contact_form = forms.ContactForm()
|
||||
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):
|
||||
template_name = "project_list.html"
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user