finer research function
This commit is contained in:
parent
cac6bd390b
commit
49fa15eb23
7 changed files with 98 additions and 15 deletions
|
@ -17,10 +17,12 @@ 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
|
||||||
|
|
||||||
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')
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from fiches.models import Profile
|
from fiches.models import Profile, Department
|
||||||
|
|
||||||
|
|
||||||
class ProfileForm(forms.ModelForm):
|
class ProfileForm(forms.ModelForm):
|
||||||
|
@ -20,4 +20,11 @@ class ProfileForm(forms.ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(forms.Form):
|
class SearchForm(forms.Form):
|
||||||
name = forms.CharField(label='search name', max_length=1023)
|
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)
|
||||||
|
|
||||||
|
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')
|
47
fiches/migrations/0003_auto_20200108_2306.py
Normal file
47
fiches/migrations/0003_auto_20200108_2306.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# Generated by Django 2.2.9 on 2020-01-08 23:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fiches', '0002_auto_20190408_1929'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='department',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=255, verbose_name='nom du département'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='phone',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=255, verbose_name='type'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='social',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=255, verbose_name='type'),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Mail',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='type')),
|
||||||
|
('mail', models.CharField(max_length=1023, verbose_name='adresse mail')),
|
||||||
|
('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fiches.Profile', verbose_name='profil')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Address',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='type')),
|
||||||
|
('content', models.CharField(max_length=1023, verbose_name='adresse')),
|
||||||
|
('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fiches.Profile', verbose_name='profil')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -18,13 +18,19 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<h1>
|
<h1>
|
||||||
{% block title %}{% trans "Annuaire des élèves de l'ENS" %}{% endblock %}
|
{% block title %} <a href='{% url "home" %}'>{% trans "Annuaire des élèves de l'ENS" %}</a>{% endblock %}
|
||||||
</h1>
|
</h1>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% blocktrans %}Connecté en tant que <tt>{{ user }}</tt>{% endblocktrans %}<br />
|
{% blocktrans %}Connecté en tant que <tt>{{ user }}</tt>{% endblocktrans %}<br />
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% block leftmenu %}{% endblock %}
|
<nav>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
22
fiches/templates/fiches/home.html
Normal file
22
fiches/templates/fiches/home.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{% 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 %}
|
|
@ -2,7 +2,6 @@ from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('<int:id>', views.fiche, name='fiche'),
|
path('<int:id>',views.fiche, name='fiche'),
|
||||||
path('edit', views.fiche_modif, name='fiche_modif'),
|
path('edit',views.fiche_modif, name='fiche_modif')
|
||||||
path('search', views.search, name='search'),
|
]
|
||||||
]
|
|
||||||
|
|
|
@ -26,15 +26,15 @@ def fiche_modif(request):
|
||||||
return render(request, 'fiches/fiches_modif.html', {"form": form})
|
return render(request, 'fiches/fiches_modif.html', {"form": form})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search(request):
|
def home(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = SearchForm(request.POST)
|
form = SearchForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
name = form.cleaned_data["name"]
|
result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name'])
|
||||||
result = Profile.objects.filter(full_name__icontains=name)
|
return render(request,'fiches/home.html',{"form":form, "result":result})
|
||||||
context = {"form": form, "result": result}
|
|
||||||
return render(request, 'fiches/search.html', context)
|
|
||||||
else:
|
else:
|
||||||
form = SearchForm()
|
form = SearchForm()
|
||||||
return render(request, 'fiches/search.html', {"form": form})
|
return render(request,'fiches/home.html',{"form":form})
|
||||||
|
|
Loading…
Reference in a new issue