mirror of
https://github.com/Superredstone/patrickcanal.it.git
synced 2026-09-20 17:51:12 +02:00
feat(portfolio): add email contact
This commit is contained in:
+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