Added birthday page

This commit is contained in:
Ju Luiselli 2020-02-08 14:10:14 +01:00
parent df06c5d2a4
commit 0a3e9b28df
7 changed files with 38 additions and 25 deletions

View file

@ -17,12 +17,13 @@ from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.conf.urls.static import static from django.conf.urls.static import static
from fiches.views import home from fiches.views import home, birthday
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('fiche/', include('fiches.urls')), path('fiche/', include('fiches.urls')),
path('', home, name='home') path('', home, name='home'),
path('birthday', birthday, name='birthday')
] ]
if settings.DEBUG: if settings.DEBUG:

View file

@ -33,6 +33,9 @@ class Profile(models.Model):
def __str__(self): def __str__(self):
return self.full_name return self.full_name
def birthday():
return self.birth_date.strftime("%d%m")
class Department(models.Model): class Department(models.Model):
name = models.CharField(max_length=255, verbose_name=_("nom du département")) name = models.CharField(max_length=255, verbose_name=_("nom du département"))

View file

@ -28,7 +28,7 @@
<a href='{% url "home" %}'> Accueil </a> <a href='{% url "home" %}'> Accueil </a>
<a href='{% url "fiche_modif" %}'> Modifier sa fiche d'annuaire </a> <a href='{% url "fiche_modif" %}'> Modifier sa fiche d'annuaire </a>
<a href='{% url "fiche" request.user.profile.id %}'> Consulter sa fiche d'annuaire </a> <a href='{% url "fiche" request.user.profile.id %}'> Consulter sa fiche d'annuaire </a>
<a href=''> Anniversaires à venir </a> <a href='{% url "birthday" %}'> Anniversaires à venir </a>
</nav> </nav>
</div> </div>

View file

@ -0,0 +1,17 @@
{% extends "fiches/base.html" %}
{% block content %}
<h2> Anniversaires </h2>
<div>
<ul>
{% for profile in result %}
<li><a href="{% url 'fiche' profile.id %}">{{profile.full_name}}
</a> ({{ profile.department.all|join:", " }} {{profile.promotion}}) : {{ profile.birth_date|date:"j F" }} </li>
{% endfor %}
</ul>
</div>
{% endblock %}

View file

@ -1,7 +1,7 @@
{% extends "fiches/base.html" %} {% extends "fiches/base.html" %}
{% block content %} {% block content %}
<h2> Chercher quelqu'un.e dans l'annuaire </h2> <h2> Chercher quelqu'un·e dans l'annuaire </h2>
<form method='post' action=""> <form method='post' action="">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}

View file

@ -1,21 +0,0 @@
{% extends "fiches/base.html" %}
{% block content %}
<h2> Chercher quelqu'un.e dans l'annuaire </h2>
<form method='post' action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Recherche">
</form>
<div>
<ul>
{% for profile in result %}
<li><a href="{% url 'fiche' profile.id %}">{{profile.full_name}} {{profile.departement}}
</a> </li>
{% endfor %}
</ul>
</div>
{% endblock %}

View file

@ -5,6 +5,8 @@ from fiches.models import Profile
from fiches.forms import ProfileForm, SearchForm from fiches.forms import ProfileForm, SearchForm
from django.urls import reverse from django.urls import reverse
from django.db.models import Q from django.db.models import Q
from django.utils import timezone
from datetime import timedelta
@login_required @login_required
@ -39,3 +41,14 @@ def home(request):
else: else:
form = SearchForm() 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})