Merge branch '4-page-des-anniversaires' into 'master'
Resolve "Page des anniversaires" Closes #4 See merge request klub-dev-ens/annuaire!3
This commit is contained in:
commit
49a5675bd7
7 changed files with 54 additions and 36 deletions
|
@ -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:
|
||||
|
|
|
@ -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']):
|
||||
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')
|
|
@ -28,7 +28,7 @@
|
|||
<a href='{% url "home" %}'> Accueil </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=''> Anniversaires à venir </a>
|
||||
<a href='{% url "birthday" %}'> Anniversaires à venir </a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
|
15
fiches/templates/fiches/birthday.html
Normal file
15
fiches/templates/fiches/birthday.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{% 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 %}
|
|
@ -1,22 +1,20 @@
|
|||
{% extends "fiches/base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h2> Chercher quelqu'un.e dans l'annuaire </h2>
|
||||
<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}}
|
||||
<li><a href="{% url 'fiche' profile.id %}">{{profile.full_name}} ({{ profile.department.all|join:", " }} {{profile.promotion}})
|
||||
</a> </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -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 %}
|
|
@ -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})
|
||||
|
|
Loading…
Reference in a new issue