mirror of
https://github.com/Superredstone/patrickcanal.it.git
synced 2026-11-19 04:41:15 +01:00
feat(portfolio): add email contact
This commit is contained in:
13 files changed
+161
-25
No files matched your search
@@ -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
@@ -0,0 +1 @@
|
|||||||
|
var htmx=function(){"use strict";const Q={onLoad:null,process:null,on:null,off:null,trigger:null,ajax:null,find:null,findAll:null,closest:null,values:function(e,t){const n=dn(e,t||"post");return n.values},remove:null,addClass:null,removeClass:null,toggleClass:null,takeClass:null,swap:null,defineExtension:null,removeExtension:null,logAll:null,logNone:null,logger:null,config:{historyEnabled:true,historyCacheSize:10,refreshOnHistoryMiss:false,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:20,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",addedClass:"htmx-added",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",allowEval:true,allowScriptTags:true,inlineScriptNonce:"",inlineStyleNonce:"",attributesToSettle:["class","style","width","height"],withCredentials:false,timeout:0,wsReconnectDelay:"full-jitter",wsBinaryType:"blob",disableSelector:"[hx-disable], [data-hx-disable]",scrollBehavior:"instant",defaultFocusScroll:false,getCacheBusterParam:false,globalViewTransitions:false,methodsThatUseUrlParams:["get","delete"],selfRequestsOnly:true,ignoreTitle:false,scrollIntoViewOnBoost:true,triggerSpecsCache:null,disableInheritance:false,responseHandling:[{code:"204",swap:false},{code:"[23]..",swap:true},{code:"[45]..",swap:false,error:true}],allowNestedOobSwaps:true,historyRestoreAsHxRequest:true,reportValidityOfForms:false},parseInterval:null,location:location,_:null,version:"2.0.10"};Q.onLoad=j;Q.process=Ft;Q.on=ye;Q.off=xe;Q.trigger=ae;Q.ajax=Nn;Q.find=f;Q.findAll=y;Q.closest=g;Q.remove=z;Q.addClass=w;Q.removeClass=b;Q.toggleClass=G;Q.takeClass=W;Q.swap=_e;Q.defineExtension=_n;Q.removeExtension=zn;Q.logAll=$;Q.logNone=_;Q.parseInterval=d;Q._=e;const n={addTriggerHandler:St,bodyContains:se,canAccessLocalStorage:U,findThisElement:we,filterValues:yn,swap:_e,hasAttribute:s,getAttributeValue:a,getClosestAttributeValue:ne,getClosestMatch:A,getExpressionVars:Rn,getHeaders:mn,getInputValues:dn,getInternalData:oe,getSwapSpecification:bn,getTriggerSpecs:st,getTarget:Se,makeFragment:P,mergeObjects:le,makeSettleInfo:Sn,oobSwap:He,querySelectorExt:ce,settleImmediately:Yt,shouldCancel:ht,triggerEvent:ae,triggerErrorEvent:fe,withExtensions:Vt};const de=["get","post","put","delete","patch"];const R=de.map(function(e){return"[hx-"+e+"], [data-hx-"+e+"]"}).join(", ");function d(e){if(e==undefined){return undefined}let t=NaN;if(e.slice(-2)=="ms"){t=parseFloat(e.slice(0,-2))}else if(e.slice(-1)=="s"){t=parseFloat(e.slice(0,-1))*1e3}else if(e.slice(-1)=="m"){t=parseFloat(e.slice(0,-1))*1e3*60}else{t=parseFloat(e)}return isNaN(t)?undefined:t}function ee(e,t){return e instanceof Element&&e.getAttribute(t)}function s(e,t){return!!e.hasAttribute&&(e.hasAttribute(t)||e.hasAttribute("data-"+t))}function a(e,t){return ee(e,t)||ee(e,"data-"+t)}function c(e){const t=e.parentElement;if(!t&&e.parentNode instanceof ShadowRoot)return e.parentNode;return t}function te(){return document}function q(e,t){return e.getRootNode?e.getRootNode({composed:t}):te()}function A(e,t){while(e&&!t(e)){e=c(e)}return e||null}function o(e,t,n){const r=a(t,n);const o=a(t,"hx-disinherit");var i=a(t,"hx-inherit");if(e!==t){if(Q.config.disableInheritance){if(i&&(i==="*"||i.split(" ").indexOf(n)>=0)){return r}else{return null}}if(o&&(o==="*"||o.split(" ").indexOf(n)>=0)){return"unset"}}return r}function ne(t,n){let r=null;A(t,function(e){return!!(r=o(t,ue(e),n))});if(r!=="unset"){return r}}function h(e,t){return e instanceof Element&&e.matches(t)}function N(e){const t=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i;const n=t.exec(e);if(n){return n[1].toLowerCase()}else{return""}}function I(e){if("parseHTMLUnsafe"in Document){return Document.parseHTMLUnsafe(e)}const t=new DOMParser;return t.parseFromString(e,"text/html")}function L(e,t){while(t.childNodes.length>0){e.append(t.childNodes[0])}}function r(e){const t=te().createElement("script");ie(e.attributes,function(e){t.setAttribute(e.name,e.value)});t.textContent=e.textContent;t.async=false;if(Q.config.inlineScriptNonce){t.nonce=Q.config.inlineScriptNonce}return t}function i(e){return e.matches("script")&&(e.type==="text/javascript"||e.type==="module"||e.type==="")}function D(e){Array.from(e.querySelectorAll("script")).forEach(e=>{if(i(e)){const t=r(e);const n=e.parentNode;try{n.insertBefore(t,e)}catch(e){H(e)}finally{e.remove()}}})}function P(e){const t=e.replace(/<head(\s[^>]*)?>[\s\S]*?<\/head>/i,"");const n=N(t);let r;if(n==="html"){r=new DocumentFragment;const i=I(e);L(r,i.body);r.title=i.title}else if(n==="body"){r=new DocumentFragment;const i=I(t);L(r,i.body);r.title=i.title}else{const i=I('<body><template class="internal-htmx-wrapper">'+t+"</template></body>");r=i.querySelector("template").content;r.title=i.title;var o=r.querySelector("title");if(o&&o.parentNode===r){o.remove();r.title=o.innerText}}if(r){if(Q.config.allowScriptTags){D(r)}else{r.querySelectorAll("script").forEach(e=>e.remove())}}return r}function re(e){if(e){e()}}function t(e,t){return Object.protLine truncated
|
||||||
Reference in new issue
Block a user