diff --git a/annuaire/urls.py b/annuaire/urls.py index 5697b50..17f0e1d 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -17,10 +17,12 @@ 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 urlpatterns = [ path('admin/', admin.site.urls), - path('fiche/', include('fiches.urls')) + path('fiche/', include('fiches.urls')), + path('', home, name='home') ] if settings.DEBUG: diff --git a/fiches/forms.py b/fiches/forms.py index 8a487a3..83c20c0 100644 --- a/fiches/forms.py +++ b/fiches/forms.py @@ -1,5 +1,5 @@ from django import forms -from fiches.models import Profile +from fiches.models import Profile, Department class ProfileForm(forms.ModelForm): @@ -20,4 +20,11 @@ class ProfileForm(forms.ModelForm): 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') \ No newline at end of file diff --git a/fiches/migrations/0003_auto_20200108_2306.py b/fiches/migrations/0003_auto_20200108_2306.py new file mode 100644 index 0000000..014794e --- /dev/null +++ b/fiches/migrations/0003_auto_20200108_2306.py @@ -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')), + ], + ), + ] diff --git a/fiches/templates/fiches/base.html b/fiches/templates/fiches/base.html index dcfe049..9c076eb 100644 --- a/fiches/templates/fiches/base.html +++ b/fiches/templates/fiches/base.html @@ -18,13 +18,19 @@

- {% block title %}{% trans "Annuaire des élèves de l'ENS" %}{% endblock %} + {% block title %} {% trans "Annuaire des élèves de l'ENS" %}{% endblock %}

{% if user.is_authenticated %} {% blocktrans %}Connecté en tant que {{ user }}{% endblocktrans %}
{% endif %} - {% block leftmenu %}{% endblock %} +
diff --git a/fiches/templates/fiches/home.html b/fiches/templates/fiches/home.html new file mode 100644 index 0000000..3d47ff0 --- /dev/null +++ b/fiches/templates/fiches/home.html @@ -0,0 +1,22 @@ +{% extends "fiches/base.html" %} +{% block content %} + +

Chercher quelqu'un.e dans l'annuaire

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ + +
+ +
+ + +{% endblock %} \ No newline at end of file diff --git a/fiches/urls.py b/fiches/urls.py index 688a581..918c628 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -2,7 +2,6 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.fiche, name='fiche'), - path('edit', views.fiche_modif, name='fiche_modif'), - path('search', views.search, name='search'), -] + path('',views.fiche, name='fiche'), + path('edit',views.fiche_modif, name='fiche_modif') + ] diff --git a/fiches/views.py b/fiches/views.py index a1207a9..d0a9303 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -26,15 +26,15 @@ def fiche_modif(request): return render(request, 'fiches/fiches_modif.html', {"form": form}) + @login_required -def search(request): +def home(request): if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): - name = form.cleaned_data["name"] - result = Profile.objects.filter(full_name__icontains=name) - context = {"form": form, "result": result} - return render(request, 'fiches/search.html', context) + result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name']) + return render(request,'fiches/home.html',{"form":form, "result":result}) + else: form = SearchForm() - return render(request, 'fiches/search.html', {"form": form}) + return render(request,'fiches/home.html',{"form":form})