diff --git a/annuaire/urls.py b/annuaire/urls.py
index 17f0e1d..b8febf5 100644
--- a/annuaire/urls.py
+++ b/annuaire/urls.py
@@ -17,12 +17,13 @@ from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
-from fiches.views import home
+from fiches.views import home, birthday
urlpatterns = [
path('admin/', admin.site.urls),
path('fiche/', include('fiches.urls')),
- path('', home, name='home')
+ path('', home, name='home'),
+ path('birthday', birthday, name='birthday')
]
if settings.DEBUG:
diff --git a/fiches/forms.py b/fiches/forms.py
index 83c20c0..d978399 100644
--- a/fiches/forms.py
+++ b/fiches/forms.py
@@ -22,9 +22,15 @@ class ProfileForm(forms.ModelForm):
class SearchForm(forms.Form):
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)
+ department = forms.ModelMultipleChoiceField(
+ queryset=Department.objects.all(), required=False
+ )
def clean(self):
cleaned_data = super().clean()
- if (not cleaned_data['name'] and not cleaned_data['year'] and not cleaned_data['department']):
- raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
\ No newline at end of file
+ if (
+ not cleaned_data['name']
+ and not cleaned_data['year']
+ and not cleaned_data['department']
+ ):
+ raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
diff --git a/fiches/templates/fiches/base.html b/fiches/templates/fiches/base.html
index 9c076eb..0e4fa7b 100644
--- a/fiches/templates/fiches/base.html
+++ b/fiches/templates/fiches/base.html
@@ -28,7 +28,7 @@
Accueil
Modifier sa fiche d'annuaire
Consulter sa fiche d'annuaire
- Anniversaires à venir
+ Anniversaires à venir
diff --git a/fiches/templates/fiches/birthday.html b/fiches/templates/fiches/birthday.html
new file mode 100644
index 0000000..6e203bf
--- /dev/null
+++ b/fiches/templates/fiches/birthday.html
@@ -0,0 +1,15 @@
+{% extends "fiches/base.html" %}
+{% block content %}
+
+
Anniversaires
+
+
+
+ {% for profile in result %}
+ - {{profile.full_name}}
+ ({{ profile.department.all|join:", " }} {{profile.promotion}}) : {{ profile.birth_date|date:"j F" }}
+ {% endfor %}
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/fiches/templates/fiches/home.html b/fiches/templates/fiches/home.html
index 3d47ff0..b503bd1 100644
--- a/fiches/templates/fiches/home.html
+++ b/fiches/templates/fiches/home.html
@@ -1,22 +1,20 @@
{% extends "fiches/base.html" %}
{% block content %}
- Chercher quelqu'un.e dans l'annuaire
+ Chercher quelqu'un·e dans l'annuaire
-
-
{% endblock %}
\ No newline at end of file
diff --git a/fiches/templates/fiches/search.html b/fiches/templates/fiches/search.html
deleted file mode 100644
index 15eb066..0000000
--- a/fiches/templates/fiches/search.html
+++ /dev/null
@@ -1,21 +0,0 @@
-{% extends "fiches/base.html" %}
-{% block content %}
-
- Chercher quelqu'un.e dans l'annuaire
-
-
-
-
-
-{% endblock %}
diff --git a/fiches/views.py b/fiches/views.py
index 5b50a4b..6178a14 100644
--- a/fiches/views.py
+++ b/fiches/views.py
@@ -5,6 +5,8 @@ from fiches.models import Profile
from fiches.forms import ProfileForm, SearchForm
from django.urls import reverse
from django.db.models import Q
+from django.utils import timezone
+from datetime import timedelta
@login_required
@@ -23,19 +25,36 @@ def fiche_modif(request):
return redirect(reverse('fiche', args=(profile.id,)))
else:
form = ProfileForm(instance=profile)
-
return render(request, 'fiches/fiches_modif.html', {"form": form})
-
@login_required
def home(request):
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})
+ 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}
+ )
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
+ ))
+ 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)
+ )
+ return render(request, 'fiches/birthday.html', {"result": result})