Send link via email
This commit is contained in:
parent
bcd7f6dc18
commit
c16d0db8ca
8 changed files with 59 additions and 15 deletions
2
Pipfile
2
Pipfile
|
@ -13,8 +13,8 @@ gunicorn = "*"
|
||||||
dj-database-url = "*"
|
dj-database-url = "*"
|
||||||
"psycopg2-binary" = "*"
|
"psycopg2-binary" = "*"
|
||||||
django-dotenv = "*"
|
django-dotenv = "*"
|
||||||
django-mailgun = "*"
|
|
||||||
uuid = "*"
|
uuid = "*"
|
||||||
|
django-anymail = {extras = ["mailgun"]}
|
||||||
|
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
17
Pipfile.lock
generated
17
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "43a1e1084af30da4a5ce423a0086c023152fb78a989cf7425035ea6d2a02fd0e"
|
"sha256": "9a19cd2cc896f2304c510ff49bada489a31b1b1ac412af5c44c36f5cf43605a3"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -46,6 +46,14 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==2.0.5"
|
"version": "==2.0.5"
|
||||||
},
|
},
|
||||||
|
"django-anymail": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:9058c1009adbd926213fb2f18d20a8592e23c63f845a4aaa63c51b6476a4638a",
|
||||||
|
"sha256:969ea878da44b54ef2229241da9f0e9a72886c9dea14186ba6733939b63320f4"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==2.2"
|
||||||
|
},
|
||||||
"django-bootstrap4": {
|
"django-bootstrap4": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:6db4a27b33851833e68b96344f9df063150dcace8d4787ebfc21eceb55196945"
|
"sha256:6db4a27b33851833e68b96344f9df063150dcace8d4787ebfc21eceb55196945"
|
||||||
|
@ -61,13 +69,6 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==1.4.2"
|
"version": "==1.4.2"
|
||||||
},
|
},
|
||||||
"django-mailgun": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:d795076d18c0aa66fbac37f8b428f036417a3ec7ecc2d6499c021d318d60bfff"
|
|
||||||
],
|
|
||||||
"index": "pypi",
|
|
||||||
"version": "==0.9.1"
|
|
||||||
},
|
|
||||||
"gunicorn": {
|
"gunicorn": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:7ef2b828b335ed58e3b64ffa84caceb0a7dd7c5ca12f217241350dec36a1d5dc",
|
"sha256:7ef2b828b335ed58e3b64ffa84caceb0a7dd7c5ca12f217241350dec36a1d5dc",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 21:21
|
# Generated by Django 2.0.5 on 2018-05-21 21:57
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -51,6 +51,7 @@ class Migration(migrations.Migration):
|
||||||
('first_name', models.CharField(max_length=100, verbose_name='prénom')),
|
('first_name', models.CharField(max_length=100, verbose_name='prénom')),
|
||||||
('last_name', models.CharField(max_length=100, verbose_name='nom')),
|
('last_name', models.CharField(max_length=100, verbose_name='nom')),
|
||||||
('phone_number', models.CharField(max_length=10, verbose_name='numéro de téléphone')),
|
('phone_number', models.CharField(max_length=10, verbose_name='numéro de téléphone')),
|
||||||
|
('email', models.EmailField(max_length=254, verbose_name='adresse email')),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'enseignant',
|
'verbose_name': 'enseignant',
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Teacher(models.Model):
|
||||||
first_name = models.CharField('prénom', max_length=100)
|
first_name = models.CharField('prénom', max_length=100)
|
||||||
last_name = models.CharField('nom', max_length=100)
|
last_name = models.CharField('nom', max_length=100)
|
||||||
phone_number = models.CharField('numéro de téléphone', max_length=10)
|
phone_number = models.CharField('numéro de téléphone', max_length=10)
|
||||||
|
email = models.EmailField('adresse email')
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
10
manuels/templates/manuels/email.html
Normal file
10
manuels/templates/manuels/email.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<html>
|
||||||
|
<p>Bonjour {{ teacher.first_name }},</p>
|
||||||
|
<p>
|
||||||
|
Voici votre lien pour la gestion des manuels scolaires :
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="text-align: center;">
|
||||||
|
{{ link }}
|
||||||
|
</p>
|
||||||
|
</html>
|
|
@ -11,7 +11,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<h4 class="alert-heading">Attention</h4>
|
<h4 class="alert-heading">Attention</h4>
|
||||||
<p class="mb-0">Pensez à <strong>sauvegarder cette page dans vos favoris</strong>.<br>
|
<p class="mb-0">
|
||||||
|
Ce lien vous a été envoyé par email. N'oubliez pas de vérifier vos courriers indésirables.<br>
|
||||||
|
Pensez à <strong>sauvegarder cette page dans vos favoris</strong>.<br>
|
||||||
Si vous perdez ce lien, vous ne risquez de ne plus être en mesure d'accéder à votre espace personnel
|
Si vous perdez ce lien, vous ne risquez de ne plus être en mesure d'accéder à votre espace personnel
|
||||||
et vous ne pourrez plus ajouter de livre à votre liste.
|
et vous ne pourrez plus ajouter de livre à votre liste.
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.core.mail import EmailMultiAlternatives
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.template.loader import render_to_string
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views.generic import CreateView, ListView
|
from django.views.generic import CreateView, ListView
|
||||||
|
|
||||||
|
@ -9,7 +14,7 @@ from manuels.models import Teacher, Book
|
||||||
|
|
||||||
class HomePageView(CreateView):
|
class HomePageView(CreateView):
|
||||||
model = Teacher
|
model = Teacher
|
||||||
fields = ['first_name', 'last_name', 'phone_number']
|
fields = '__all__'
|
||||||
template_name = 'manuels/home_page.html'
|
template_name = 'manuels/home_page.html'
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
@ -19,6 +24,26 @@ class HomePageView(CreateView):
|
||||||
|
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
response = super().form_valid(form)
|
||||||
|
dest = form.cleaned_data['email']
|
||||||
|
link = self.request.build_absolute_uri(reverse('list_books', args=[str(self.object.pk)]))
|
||||||
|
msg = EmailMultiAlternatives(
|
||||||
|
subject='Gestion des manuels scolaires',
|
||||||
|
body=f'Bonjour {self.object.first_name},\n'
|
||||||
|
f'Voici votre lien pour la gestion des manuels scolaires : {link}',
|
||||||
|
from_email=settings.SERVER_EMAIL,
|
||||||
|
to=[dest],
|
||||||
|
)
|
||||||
|
reply_to = [os.getenv('REPLY_TO')]
|
||||||
|
if reply_to:
|
||||||
|
msg.reply_to = reply_to
|
||||||
|
msg.attach_alternative(
|
||||||
|
render_to_string('manuels/email.html', {'link': link, 'teacher': self.object}), "text/html"
|
||||||
|
)
|
||||||
|
msg.send()
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class BaseTeacherView:
|
class BaseTeacherView:
|
||||||
teacher = None
|
teacher = None
|
||||||
|
|
|
@ -50,6 +50,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'anymail',
|
||||||
'bootstrap4',
|
'bootstrap4',
|
||||||
'manuels',
|
'manuels',
|
||||||
]
|
]
|
||||||
|
@ -134,6 +135,9 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||||
|
|
||||||
LOGIN_REDIRECT_URL = 'rooms-list'
|
LOGIN_REDIRECT_URL = 'rooms-list'
|
||||||
|
|
||||||
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
|
ANYMAIL = {
|
||||||
MAILGUN_ACCESS_KEY = os.getenv('MAILGUN_ACCESS_KEY', '')
|
"MAILGUN_API_KEY": os.getenv('MAILGUN_ACCESS_KEY', ''),
|
||||||
MAILGUN_SERVER_NAME = os.getenv('MAILGUN_SERVER_NAME', '')
|
"MAILGUN_SENDER_DOMAIN": os.getenv('MAILGUN_SERVER_NAME', ''),
|
||||||
|
}
|
||||||
|
|
||||||
|
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
|
||||||
|
|
Loading…
Reference in a new issue