From 0a3e9b28dfcf5dfc7ca09cae45de929c010ffc8c Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Sat, 8 Feb 2020 14:10:14 +0100 Subject: [PATCH] Added birthday page --- annuaire/urls.py | 5 +++-- fiches/models.py | 3 +++ fiches/templates/fiches/base.html | 2 +- fiches/templates/fiches/birthday.html | 17 +++++++++++++++++ fiches/templates/fiches/home.html | 2 +- fiches/templates/fiches/search.html | 21 --------------------- fiches/views.py | 13 +++++++++++++ 7 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 fiches/templates/fiches/birthday.html delete mode 100644 fiches/templates/fiches/search.html 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/models.py b/fiches/models.py index 7793fdb..02ff5ab 100644 --- a/fiches/models.py +++ b/fiches/models.py @@ -33,6 +33,9 @@ class Profile(models.Model): def __str__(self): return self.full_name + def birthday(): + return self.birth_date.strftime("%d%m") + class Department(models.Model): name = models.CharField(max_length=255, verbose_name=_("nom du département")) 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..0b30ca5 --- /dev/null +++ b/fiches/templates/fiches/birthday.html @@ -0,0 +1,17 @@ +{% extends "fiches/base.html" %} +{% block content %} + +

Anniversaires

+ + +
+ +
+ + +{% endblock %} \ No newline at end of file diff --git a/fiches/templates/fiches/home.html b/fiches/templates/fiches/home.html index 28a9b20..c2d2f52 100644 --- a/fiches/templates/fiches/home.html +++ b/fiches/templates/fiches/home.html @@ -1,7 +1,7 @@ {% extends "fiches/base.html" %} {% block content %} -

Chercher quelqu'un.e dans l'annuaire

+

Chercher quelqu'un·e dans l'annuaire

{% csrf_token %} {{ form.as_p }} 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

- - {% csrf_token %} - {{ form.as_p }} - -
- -
- -
- - -{% endblock %} diff --git a/fiches/views.py b/fiches/views.py index 5b50a4b..649060e 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 @@ -39,3 +41,14 @@ def home(request): else: form = SearchForm() 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}) +