send mail upon modification
This commit is contained in:
parent
1cf12421f0
commit
5b398c223e
6 changed files with 45 additions and 28 deletions
|
@ -134,3 +134,4 @@ CAS_SERVER_URL = 'https://cas.eleves.ens.fr/'
|
|||
|
||||
CAS_VERSION = "2"
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
|
|
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
|||
|
||||
|
||||
class FichesConfig(AppConfig):
|
||||
name = 'fiches'
|
||||
name = "fiches"
|
||||
|
|
|
@ -15,13 +15,13 @@ class ProfileForm(forms.ModelForm):
|
|||
"thurne",
|
||||
"text_field",
|
||||
"printing",
|
||||
"keep_me"
|
||||
"keep_me",
|
||||
]
|
||||
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
name = forms.CharField(label='Nom/Surnom', max_length=1023, required=False)
|
||||
year = forms.IntegerField(label='Promotion', required=False)
|
||||
name = forms.CharField(label="Nom/Surnom", max_length=1023, required=False)
|
||||
year = forms.IntegerField(label="Promotion", required=False)
|
||||
department = forms.ModelMultipleChoiceField(
|
||||
queryset=Department.objects.all(), required=False
|
||||
)
|
||||
|
@ -29,8 +29,8 @@ class SearchForm(forms.Form):
|
|||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
if (
|
||||
not cleaned_data['name']
|
||||
and not cleaned_data['year']
|
||||
and not cleaned_data['department']
|
||||
not cleaned_data["name"]
|
||||
and not cleaned_data["year"]
|
||||
and not cleaned_data["department"]
|
||||
):
|
||||
raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
|
||||
raise forms.ValidationError(("Tous les champs sont vides"), code="invalid")
|
||||
|
|
6
fiches/templates/fiches/mail/mail_modif.txt
Normal file
6
fiches/templates/fiches/mail/mail_modif.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
Bonjour {{profile.full_name}},
|
||||
|
||||
Ta fiche annuaire a été modifiée !
|
||||
|
||||
Cordialement,
|
||||
le Klub Dev
|
|
@ -2,6 +2,6 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('<int:id>',views.fiche, name='fiche'),
|
||||
path('edit',views.fiche_modif, name='fiche_modif')
|
||||
path("<int:id>", views.fiche, name="fiche"),
|
||||
path("edit", views.fiche_modif, name="fiche_modif"),
|
||||
]
|
||||
|
|
|
@ -7,54 +7,64 @@ from django.urls import reverse
|
|||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
||||
@login_required
|
||||
def fiche(request, id):
|
||||
profile = get_object_or_404(Profile, id=id)
|
||||
return render(request, 'fiches/fiche.html', {"profile": profile})
|
||||
return render(request, "fiches/fiche.html", {"profile": profile})
|
||||
|
||||
|
||||
@login_required
|
||||
def fiche_modif(request):
|
||||
profile = request.user.profile
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
form = ProfileForm(request.POST, instance=profile)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect(reverse('fiche', args=(profile.id,)))
|
||||
send_mail(
|
||||
"Fiche annuaire modifée",
|
||||
render_to_string("fiches/mail/mail_modif.txt", {"profile": profile}),
|
||||
"klub-dev@ens.psl.eu",
|
||||
["{}@clipper.ens.psl.eu".format(request.user.username)],
|
||||
fail_silently=False,
|
||||
)
|
||||
return redirect(reverse("fiche", args=(profile.id,)))
|
||||
|
||||
else:
|
||||
form = ProfileForm(instance=profile)
|
||||
return render(request, 'fiches/fiches_modif.html', {"form": form})
|
||||
|
||||
return render(request, "fiches/fiches_modif.html", {"form": form})
|
||||
|
||||
@login_required
|
||||
def home(request):
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
form = SearchForm(request.POST)
|
||||
if form.is_valid():
|
||||
result = Profile.objects.filter(
|
||||
Q(full_name__icontains=form.cleaned_data['name'])
|
||||
| Q(nickname__icontains=form.cleaned_data['name'])
|
||||
)
|
||||
return render(
|
||||
request, 'fiches/home.html', {"form": form, "result": result}
|
||||
Q(full_name__icontains=form.cleaned_data["name"])
|
||||
| Q(nickname__icontains=form.cleaned_data["name"])
|
||||
)
|
||||
return render(request, "fiches/home.html", {"form": form, "result": result})
|
||||
|
||||
else:
|
||||
form = SearchForm()
|
||||
return render(request, 'fiches/home.html', {"form": form})
|
||||
return render(request, "fiches/home.html", {"form": form})
|
||||
|
||||
|
||||
@login_required
|
||||
def birthday(request):
|
||||
today = timezone.now()
|
||||
result = list(Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month
|
||||
))
|
||||
result = list(
|
||||
Profile.objects.filter(birth_date__day=today.day, birth_date__month=today.month)
|
||||
)
|
||||
for i in range(1, 7):
|
||||
today = today + timedelta(days=1)
|
||||
result += list(Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month)
|
||||
result += list(
|
||||
Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month
|
||||
)
|
||||
return render(request, 'fiches/birthday.html', {"result": result})
|
||||
)
|
||||
return render(request, "fiches/birthday.html", {"result": result})
|
||||
|
|
Loading…
Reference in a new issue