From 6f9b9e4127e551621b27e4e88c5dc23c6a0f84ac Mon Sep 17 00:00:00 2001 From: Juliette Luiselli Date: Mon, 25 Mar 2019 22:30:25 +0100 Subject: [PATCH 01/11] html page d'accueil et css --- annuaire/urls.py | 3 +- fiches/static/fiches/css/style.css | 352 +++++++++++++++++++++++++++++ fiches/templates/fiches/base.html | 60 +++++ fiches/templates/fiches/fiche.html | 1 + fiches/urls.py | 6 + fiches/views.py | 3 + picture/pnmadela2.jpg | Bin 0 -> 3561 bytes 7 files changed, 424 insertions(+), 1 deletion(-) create mode 100644 fiches/static/fiches/css/style.css create mode 100644 fiches/templates/fiches/base.html create mode 100644 fiches/templates/fiches/fiche.html create mode 100644 fiches/urls.py create mode 100644 picture/pnmadela2.jpg diff --git a/annuaire/urls.py b/annuaire/urls.py index 1d7e4ba..22e75b3 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -14,8 +14,9 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('fiche/', include('fiches.urls')) ] diff --git a/fiches/static/fiches/css/style.css b/fiches/static/fiches/css/style.css new file mode 100644 index 0000000..63a70ef --- /dev/null +++ b/fiches/static/fiches/css/style.css @@ -0,0 +1,352 @@ +html { + background: url(../images/background-motif.png) repeat; + color: #FFF; + font-family: Verdana, Verdana, Geneva, sans-serif; +} + +body { + margin: 0 0 0.8em 0; + background: transparent url(../images/background.png) no-repeat center top; + min-height: 538px; +} + +img { + border: 0; +} + +a:link { + background-color: inherit; + color: #7978DA; + text-decoration: none; +} + +a:visited { + background-color: inherit; + color: #9CA6FF; + text-decoration: none; +} + +a:hover { + background-color: inherit; + color: #006CE3; + text-decoration: underline; +} + +p { + margin-top: 0.6em; + margin-bottom: 0.6em; +} + +.ens { + color: #89C4FF; + background-color: inherit; +} + +.tiny { + font-size: 0.8em; +} + +.verytiny { + font-size: 0.7em; +} + +.dark { + color: #666; + background-color: inherit; +} + +.center { + text-align: center; +} + +.right { + float: right; +} + +.spacer { + width: 100%; + clear: both; +} + +.error { + font-weight: bold; + color: #FB0000; + background-color: inherit; +} + +.warning { + font-weight: bold; + color: #FF8A00; + background-color: inherit; +} + +.mainspacer { + width: 100%; + height: 0.8em; +} + +.success { + font-weight: bold; + color: #00E000; + background-color: inherit; +} + +.success a:link { + background-color: inherit; + color: #008800; + text-decoration: none; +} + +.success a:visited { + background-color: inherit; + color: #008800; + text-decoration: none; +} + +.success a:hover { + background-color: inherit; + color: #4FFF4F; + text-decoration: underline; +} + +.block { + background-color: #333; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + text-align: justify; + padding: 0.5em 0.5em; + margin: 0 1em 1em 1em; +} + +#main { + padding-top: 0.5em; + margin-left: 1em; + background-color: transparent; + color: #FFF; + width: 40em; + float: left; +} + +#header { + margin: 0 1em 0 1em; + float: left; + text-align: center; +} + +#header h1 { + margin-top: 0; + font-family: Georgia, sans-serif; +} + +#header h1 a:link, #header h1 a:visited { + color: #FFF; + background-color: inherit; + text-decoration: none; +} + +#header h1 a:hover { + text-decoration: underline; +} + +#language_switch { + margin-top: 0.5em; + float: left; +} + +#language_switch form { + float: left; + padding: 0; + margin-left: 0.5em; +} + +#content { +} + +#content h3 { + margin-top: 0; + margin-bottom: 0.2em; +} + +#content h4 { + margin-top: 0.5em; + margin-bottom: 0.2em; +} + +#footer { + padding: 0.2em 0; + margin: 1em 5em 0 5em; + clear: both; + background-color: #333; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + text-align: center; +} + +#contact { + margin: 0.5em 8em 0 8em; +} + +#search { + margin-bottom: 1em; +} + +.errorlist { + display: inline; + margin-top: 0; + margin-bottom: 0; + padding-left: 0; +} + +.errorlist li { + display: inline; + font-weight: bold; + color: #E00000; + background-color: inherit; +} + +#advanced_search { + border: 1px solid #CCC; + padding: 0.5em; + margin-bottom: 1em; +} + +.advanced_filter { + width: 50%; + margin-top: 1px; + margin-bottom: 1px; + float: left; +} + +.advanced_filter input { + max-width: 60%; +} + +.submit_button { + text-align: center; +} + +.add_delete_button { + text-align: right; + margin: 0.3em; +} + +#pdflink { + text-align: right; + font-size: 0.8em; +} + +#picture { + width: 8em; + float: left; +} + +#picture img { + margin-top: 0.3em; + max-width: 8em; +} + +#infos { + padding-left: 1em; + float: left; + width: 31em; +} + +#ficheedit { + margin-top: 0; + padding-top: 0; +} + +.editfield { + padding-top: 0.2em; + padding-bottom: 0.2em; +} + +.editfield input { +} + +.editfield textarea { + margin-left: auto; + margin-right: auto; + margin-top:0.2em; + display: block; + width: 98%; + height: 3em; +} + +.message { + margin-top: 0.3em; + margin-bottom: 0.3em; + text-align: center; +} + +.long_message { + margin-top: 0.6em; + margin-bottom: 0.6em; + text-align: justify; +} + +fieldset.address .editfield textarea, fieldset.quote .editfield textarea { + height: 3em; +} + +fieldset.address, fieldset.quote { + padding-bottom: 0.2em; +} + +#main-login-container { + width: 500px; + margin: 3.5em auto; +} + +#main-login-container h3.error { + text-align: center; + width: 100%; + margin-bottom: 20px; + font-size: 1.3em; + font-family: 'Droid Serif', serif; +} + +#main-login { + width: 500px; + border: 15px solid #333; + -webkit-border-radius: 20px; + -moz-border-radius: 20px; + border-radius: 20px; +} + +#main-login.login_block { + padding: 2em; + box-shadow: 0 0 100px #AAA inset; +} + +a#login_clipper, a#login_outsider { + float: left; + display: block; + width: 250px; + height: 200px; + text-align: center; + font-family: 'Droid Serif', serif; + font-size: 1.3em; + font-weight: bold; + line-height: 190px; + text-decoration: none; + color: #FFF; +} + +a#login_clipper { + background-color: #123E96; + box-shadow: 0 0 100px #040C78 inset; +} + +a#login_clipper:hover { + background-color: #164BB6; +} + +a#login_outsider { + background-color: #961221; + box-shadow: 0 0 100px #780411 inset; +} + +a#login_outsider:hover { + background-color: #B31729; +} diff --git a/fiches/templates/fiches/base.html b/fiches/templates/fiches/base.html new file mode 100644 index 0000000..dcfe049 --- /dev/null +++ b/fiches/templates/fiches/base.html @@ -0,0 +1,60 @@ +{% load i18n %} +{% load staticfiles %} + + + + + + {% block title_onglet %}{% trans "Annuaire des élèves de l'ENS" %}{% endblock %} + + + +{% block extrahead %}{% endblock %} +{# Pour pouvoir ajouter des trucs dans le head sur une autre page #} + + + +
+
+ + {% block contentspacer %}{% endblock %} + {% block content %}{% endblock %} + +
+ +
+ + {% block contact %} + + {% trans "Contacter l'équipe annuaire" %} + + + powered by Django, KDENS + +
+ {% endblock %} + +
+
+
+ + diff --git a/fiches/templates/fiches/fiche.html b/fiches/templates/fiches/fiche.html new file mode 100644 index 0000000..ee8a4db --- /dev/null +++ b/fiches/templates/fiches/fiche.html @@ -0,0 +1 @@ +{% extends "fiches/base.html" %} \ No newline at end of file diff --git a/fiches/urls.py b/fiches/urls.py new file mode 100644 index 0000000..a155217 --- /dev/null +++ b/fiches/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('',views.fiche, name='fiche') + ] \ No newline at end of file diff --git a/fiches/views.py b/fiches/views.py index 91ea44a..367322e 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -1,3 +1,6 @@ from django.shortcuts import render # Create your views here. + +def fiche(request): + return render(request,'fiches/fiche.html',{}) \ No newline at end of file diff --git a/picture/pnmadela2.jpg b/picture/pnmadela2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d53a11a8b697e9915f32863b1025675c954a5de3 GIT binary patch literal 3561 zcmbW%XHXMbn+Nbf5}HU6f`AxefJ;*@VCYqPPH&qzM>-NRbjD5~T(%(tAe) z1TIJoQj`{&AU#y2OA%S_`|j+{?5ExRKXcBP=b1C-H)rOYPn^#I*z|RfIsh6P0D$JA z0O!*HO#lNO9X%bGfu5e8k&%Ikne#I9rAy2_S2$QXuk-Rluk-Tp!2~6QVep#*e0(Bu zqBkX_5C{anu!4%bw6er)g!Dg$&@eJGGGAimzI>Tm`Uc+(>Hl-i+W_ngfD8Z@NCOAZ zveN+BY0f(V{1^8G)BG!d{|pT+5Co>9X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O-ZV^6_(f{J6|Gdw@erUp(yz%V}vdZW~F6KO!iS@ysq#NCFS MZ(mG&-kwkX2lz{uS^xk5 literal 0 HcmV?d00001 From 9f254fc839401c71c96be70274b67a8b1a8f02e3 Mon Sep 17 00:00:00 2001 From: Juliette Luiselli Date: Mon, 8 Apr 2019 20:07:38 +0200 Subject: [PATCH 02/11] add import --- annuaire/urls.py | 1 + 1 file changed, 1 insertion(+) diff --git a/annuaire/urls.py b/annuaire/urls.py index 22e75b3..125db47 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -13,6 +13,7 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings from django.contrib import admin from django.urls import path, include From a672e439e8079fcf20058a6d548556bff9ec8343 Mon Sep 17 00:00:00 2001 From: Juliette Luiselli Date: Mon, 8 Apr 2019 21:47:50 +0200 Subject: [PATCH 03/11] page fiche (html) --- .gitignore | 6 +- annuaire/settings.py | 6 +- annuaire/urls.py | 4 ++ fiches/migrations/0002_auto_20190408_1929.py | 24 +++++++ fiches/models.py | 12 +++- fiches/static/fiches/css/style.css | 3 +- fiches/templates/fiches/fiche.html | 67 ++++++++++++++++++- fiches/urls.py | 2 +- fiches/views.py | 9 ++- picture/pnmadela2.jpg | Bin 3561 -> 0 bytes 10 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 fiches/migrations/0002_auto_20190408_1929.py delete mode 100644 picture/pnmadela2.jpg diff --git a/.gitignore b/.gitignore index 1e6486a..51af000 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,7 @@ *~ *# -/media/archives/* -/media/images/* -/media/documents/* -/media/original_images/* -/media/admin +/media/picture /recensements/ /venv/ diff --git a/annuaire/settings.py b/annuaire/settings.py index 614c878..32af7e0 100644 --- a/annuaire/settings.py +++ b/annuaire/settings.py @@ -103,7 +103,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/dev/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'fr-fr' TIME_ZONE = 'UTC' @@ -118,3 +118,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/dev/howto/static-files/ STATIC_URL = '/static/' + +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + +MEDIA_URL = '/media/' \ No newline at end of file diff --git a/annuaire/urls.py b/annuaire/urls.py index 125db47..0c8e865 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -16,8 +16,12 @@ Including another URLconf from django.conf import settings from django.contrib import admin from django.urls import path, include +from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('fiche/', include('fiches.urls')) ] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/fiches/migrations/0002_auto_20190408_1929.py b/fiches/migrations/0002_auto_20190408_1929.py new file mode 100644 index 0000000..6b5f8eb --- /dev/null +++ b/fiches/migrations/0002_auto_20190408_1929.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2 on 2019-04-08 19:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('fiches', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='phone', + name='profile', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fiches.Profile', verbose_name='profil'), + ), + migrations.AlterField( + model_name='social', + name='profile', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fiches.Profile', verbose_name='profil'), + ), + ] diff --git a/fiches/models.py b/fiches/models.py index beeac8d..9324314 100644 --- a/fiches/models.py +++ b/fiches/models.py @@ -26,23 +26,31 @@ class Profile(models.Model): keep_me = models.BooleanField( default=False, verbose_name=_("conserver la fiche annuaire ?") ) + def __str__(self): + return self.full_name class Department(models.Model): name = models.CharField(max_length=1023, verbose_name=_("nom du département")) + def __str__(self): + return self.name class Phone(models.Model): - profile = models.OneToOneField( + profile = models.ForeignKey( Profile, on_delete=models.CASCADE, verbose_name=_("profil") ) name = models.CharField(max_length=1023, verbose_name=_("type")) number = models.CharField(max_length=1023, verbose_name=_("numéro")) + def __str__(self): + return "{} : {}".format(self.name, self.number) class Social(models.Model): - profile = models.OneToOneField( + profile = models.ForeignKey( Profile, on_delete=models.CASCADE, verbose_name=_("profil") ) name = models.CharField(max_length=1023, verbose_name=_("type")) content = models.CharField(max_length=1023, verbose_name=_("contenu")) + def __str__(self): + return "{} : {}".format(self.name, self.content) \ No newline at end of file diff --git a/fiches/static/fiches/css/style.css b/fiches/static/fiches/css/style.css index 63a70ef..a5780d0 100644 --- a/fiches/static/fiches/css/style.css +++ b/fiches/static/fiches/css/style.css @@ -1,12 +1,11 @@ html { - background: url(../images/background-motif.png) repeat; + background-color: black; color: #FFF; font-family: Verdana, Verdana, Geneva, sans-serif; } body { margin: 0 0 0.8em 0; - background: transparent url(../images/background.png) no-repeat center top; min-height: 538px; } diff --git a/fiches/templates/fiches/fiche.html b/fiches/templates/fiches/fiche.html index ee8a4db..f51cb68 100644 --- a/fiches/templates/fiches/fiche.html +++ b/fiches/templates/fiches/fiche.html @@ -1 +1,66 @@ -{% extends "fiches/base.html" %} \ No newline at end of file +{% extends "fiches/base.html" %} +{% block content %} +
+
+ +
+
+

{{ profile.full_name }} + ({{ profile.promotion }}) + {% if profile.nickname %} + alias:{{ profile.nickname }})

+ {% endif %} +

+ {% if profile.department.exists %} + Département{{ profile.department.count|pluralize}} : + {% endif %} + {% for dep in profile.department.all %} + {{ dep }} + {% if not forloop.last %} + , + {% endif %} + {% endfor %} + {% if profile.birth_date %} +

+

+ {% if profile.phone_set.exists %} + Téléphone{{ profile.phone_set.count|pluralize}} : + {% endif %} + {% for ph in profile.phone_set.all %} + {{ ph }} + {% if not forloop.last %} + ,
+ {% endif %} + {% endfor %} +

+

+ {% if profile.social_set.exists %} + {{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} : + {% endif %} + {% for ph in profile.social_set.all %} + {{ ph }} + {% if not forloop.last %} + ,
+ {% endif %} + {% endfor %} +

+

+ Date de naissance : {{ profile.birth_date }} +

+ {% endif %} + + {% if profile.thurne %} +

+ Thurne : {{ profile.thurne }} +

+ {% endif %} +
+
+
+ {% if profile.text_field %} +

+ Champ libre : {{ profile.text_field }} +

+ {% endif %} +
+{% endblock %} \ No newline at end of file diff --git a/fiches/urls.py b/fiches/urls.py index a155217..c9dd17a 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -2,5 +2,5 @@ from django.urls import path from . import views urlpatterns = [ - path('',views.fiche, name='fiche') + path('',views.fiche, name='fiche') ] \ No newline at end of file diff --git a/fiches/views.py b/fiches/views.py index 367322e..214d33f 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -1,6 +1,11 @@ from django.shortcuts import render +from django.shortcuts import get_object_or_404 +from .models import Profile # Create your views here. -def fiche(request): - return render(request,'fiches/fiche.html',{}) \ No newline at end of file +def fiche(request,id): + profile=get_object_or_404(Profile,id=id) + return render(request,'fiches/fiche.html',{"profile":profile}) + + diff --git a/picture/pnmadela2.jpg b/picture/pnmadela2.jpg deleted file mode 100644 index d53a11a8b697e9915f32863b1025675c954a5de3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3561 zcmbW%XHXMbn+Nbf5}HU6f`AxefJ;*@VCYqPPH&qzM>-NRbjD5~T(%(tAe) z1TIJoQj`{&AU#y2OA%S_`|j+{?5ExRKXcBP=b1C-H)rOYPn^#I*z|RfIsh6P0D$JA z0O!*HO#lNO9X%bGfu5e8k&%Ikne#I9rAy2_S2$QXuk-Rluk-Tp!2~6QVep#*e0(Bu zqBkX_5C{anu!4%bw6er)g!Dg$&@eJGGGAimzI>Tm`Uc+(>Hl-i+W_ngfD8Z@NCOAZ zveN+BY0f(V{1^8G)BG!d{|pT+5Co>9XJBNybTLrJ2B4(@0%<`&Fc<{7m=3w<13>KH zD>tO>&~cbJ(8GN=rNfBX3<4U}A0ehg+k&?peZv`Z@CyAQEFv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a0cbbb0eba85cb0d90b833 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Wed, 8 Jan 2020 23:36:03 +0100 Subject: [PATCH 04/11] Added requirements to project --- requirements-dev.txt | 6 ++++++ requirements.txt | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 requirements-dev.txt create mode 100644 requirements.txt diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..dd43e61 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,6 @@ +-r requirements.txt +django-debug-toolbar +ipython +black +flake8 +isort \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7f901d9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +django==3.0.* +Pillow \ No newline at end of file From 20c1c5581d127594a0942c7d0a994790d97a5bb9 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Wed, 8 Jan 2020 23:50:09 +0100 Subject: [PATCH 05/11] Problems with Django3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7f901d9..1b3a0c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -django==3.0.* +django==2.2.* Pillow \ No newline at end of file From 39a69c4d95cd69c4ff6bfba1dec779548cd3e7b2 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Thu, 9 Jan 2020 00:07:59 +0100 Subject: [PATCH 06/11] Added mails & adresse --- fiches/admin.py | 7 ++++++- fiches/models.py | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/fiches/admin.py b/fiches/admin.py index 97f45d4..9da72e0 100644 --- a/fiches/admin.py +++ b/fiches/admin.py @@ -3,9 +3,14 @@ from fiches.models import Profile from fiches.models import Department from fiches.models import Phone from fiches.models import Social +from fiches.models import Mail +from fiches.models import Address + # Register your models here. admin.site.register(Profile) admin.site.register(Department) admin.site.register(Phone) -admin.site.register(Social) \ No newline at end of file +admin.site.register(Social) +admin.site.register(Mail) +admin.site.register(Address) \ No newline at end of file diff --git a/fiches/models.py b/fiches/models.py index 9324314..a0b96b2 100644 --- a/fiches/models.py +++ b/fiches/models.py @@ -31,7 +31,7 @@ class Profile(models.Model): class Department(models.Model): - name = models.CharField(max_length=1023, verbose_name=_("nom du département")) + name = models.CharField(max_length=255, verbose_name=_("nom du département")) def __str__(self): return self.name @@ -40,7 +40,7 @@ class Phone(models.Model): profile = models.ForeignKey( Profile, on_delete=models.CASCADE, verbose_name=_("profil") ) - name = models.CharField(max_length=1023, verbose_name=_("type")) + name = models.CharField(max_length=255, verbose_name=_("type")) number = models.CharField(max_length=1023, verbose_name=_("numéro")) def __str__(self): return "{} : {}".format(self.name, self.number) @@ -50,7 +50,25 @@ class Social(models.Model): profile = models.ForeignKey( Profile, on_delete=models.CASCADE, verbose_name=_("profil") ) - name = models.CharField(max_length=1023, verbose_name=_("type")) + name = models.CharField(max_length=255, verbose_name=_("type")) content = models.CharField(max_length=1023, verbose_name=_("contenu")) + def __str__(self): + return "{} : {}".format(self.name, self.content) + +class Mail(models.Model): + profile = models.ForeignKey( + Profile, on_delete=models.CASCADE, verbose_name=_("profil") + ) + name = models.CharField(max_length=255, verbose_name=_("type")) + mail = models.CharField(max_length=1023, verbose_name=_("adresse mail")) + def __str__(self): + return "{} : {}".format(self.name, self.mail) + +class Address(models.Model): + profile = models.ForeignKey( + Profile, on_delete=models.CASCADE, verbose_name=_("profil") + ) + name = models.CharField(max_length=255, verbose_name=_("type")) + content = models.CharField(max_length=1023, verbose_name=_("adresse")) def __str__(self): return "{} : {}".format(self.name, self.content) \ No newline at end of file From 47dd122603f491f6e3d1deddc2a4e2f98029b380 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Wed, 15 Jan 2020 20:58:10 +0100 Subject: [PATCH 07/11] added profile editing --- fiches/forms.py | 18 ++++++++++++++++++ fiches/models.py | 2 +- fiches/templates/fiches/fiche.html | 4 ++-- fiches/templates/fiches/fiches_modif.html | 11 +++++++++++ fiches/urls.py | 3 ++- fiches/views.py | 22 +++++++++++++++++++--- 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 fiches/forms.py create mode 100644 fiches/templates/fiches/fiches_modif.html diff --git a/fiches/forms.py b/fiches/forms.py new file mode 100644 index 0000000..e987871 --- /dev/null +++ b/fiches/forms.py @@ -0,0 +1,18 @@ +from django import forms +from fiches.models import Profile + +class ProfileForm(forms.ModelForm): + class Meta: + model = Profile + fields = [ + "full_name", + "nickname", + "picture", + "department", + "promotion", + "birth_date", + "thurne", + "text_field", + "printing", + "keep_me" + ] \ No newline at end of file diff --git a/fiches/models.py b/fiches/models.py index a0b96b2..4bd9c44 100644 --- a/fiches/models.py +++ b/fiches/models.py @@ -6,7 +6,7 @@ from django.contrib.auth.models import User class Profile(models.Model): user = models.OneToOneField( - User, on_delete=models.CASCADE, verbose_name=_("utilisateur") + User, on_delete=models.CASCADE, verbose_name=_("utilisateur"), related_name='profile' ) full_name = models.CharField(max_length=1023, verbose_name=_("nom")) nickname = models.CharField(blank=True, max_length=1023, verbose_name=_("surnom")) diff --git a/fiches/templates/fiches/fiche.html b/fiches/templates/fiches/fiche.html index f51cb68..a21c0be 100644 --- a/fiches/templates/fiches/fiche.html +++ b/fiches/templates/fiches/fiche.html @@ -1,8 +1,8 @@ {% extends "fiches/base.html" %} {% block content %}
-
- +
+

{{ profile.full_name }} diff --git a/fiches/templates/fiches/fiches_modif.html b/fiches/templates/fiches/fiches_modif.html new file mode 100644 index 0000000..87bfed1 --- /dev/null +++ b/fiches/templates/fiches/fiches_modif.html @@ -0,0 +1,11 @@ +{% extends "fiches/base.html" %} +{% block content %} +

Modifier ma page d'annuaire

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ + +{% endblock %} \ No newline at end of file diff --git a/fiches/urls.py b/fiches/urls.py index c9dd17a..034c7bf 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -2,5 +2,6 @@ from django.urls import path from . import views urlpatterns = [ - path('',views.fiche, name='fiche') + path('',views.fiche, name='fiche'), + path('edit',views.fiche_modif, name='fiche_modif') ] \ No newline at end of file diff --git a/fiches/views.py b/fiches/views.py index 214d33f..8a15d7c 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -1,11 +1,27 @@ from django.shortcuts import render -from django.shortcuts import get_object_or_404 -from .models import Profile +from django.shortcuts import get_object_or_404,redirect +from django.contrib.auth.decorators import login_required +from fiches.models import Profile +from fiches.forms import ProfileForm +from django.urls import reverse # Create your views here. - +@login_required def fiche(request,id): profile=get_object_or_404(Profile,id=id) return render(request,'fiches/fiche.html',{"profile":profile}) +@login_required +def fiche_modif(request): + profile = request.user.profile + if request.method == 'POST': + form = ProfileForm(request.POST, instance=profile) + if form.is_valid(): + form.save() + return redirect(reverse('fiche',args=(profile.id,))) + + else: + form = ProfileForm(instance=profile) + + return render(request,'fiches/fiches_modif.html',{"form":form}) From 674d41172ebd99e131846795ad00b1eff5ecacf5 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Wed, 15 Jan 2020 21:27:37 +0100 Subject: [PATCH 08/11] added basic search function --- fiches/forms.py | 5 ++++- fiches/templates/fiches/search.html | 21 +++++++++++++++++++++ fiches/urls.py | 3 ++- fiches/views.py | 13 ++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 fiches/templates/fiches/search.html diff --git a/fiches/forms.py b/fiches/forms.py index e987871..2ebe60b 100644 --- a/fiches/forms.py +++ b/fiches/forms.py @@ -15,4 +15,7 @@ class ProfileForm(forms.ModelForm): "text_field", "printing", "keep_me" - ] \ No newline at end of file + ] + +class SearchForm(forms.Form): + name = forms.CharField(label='search name', max_length=1023) \ No newline at end of file diff --git a/fiches/templates/fiches/search.html b/fiches/templates/fiches/search.html new file mode 100644 index 0000000..9d77921 --- /dev/null +++ b/fiches/templates/fiches/search.html @@ -0,0 +1,21 @@ +{% 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 034c7bf..6ee1a8c 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -3,5 +3,6 @@ from . import views urlpatterns = [ path('',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') ] \ No newline at end of file diff --git a/fiches/views.py b/fiches/views.py index 8a15d7c..3d51c57 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render from django.shortcuts import get_object_or_404,redirect from django.contrib.auth.decorators import login_required from fiches.models import Profile -from fiches.forms import ProfileForm +from fiches.forms import ProfileForm, SearchForm from django.urls import reverse # Create your views here. @@ -25,3 +25,14 @@ def fiche_modif(request): form = ProfileForm(instance=profile) return render(request,'fiches/fiches_modif.html',{"form":form}) + +@login_required +def search(request): + if request.method == 'POST': + form = SearchForm(request.POST) + if form.is_valid(): + result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name']) + return render(request,'fiches/search.html',{"form":form,"result":result}) + else: + form = SearchForm() + return render(request,'fiches/search.html',{"form":form}) From cac6bd390b5a55a1a2483a81bc3a50439af05ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 27 Jan 2020 19:58:25 +0100 Subject: [PATCH 09/11] Cosmetic whitespace changes --- annuaire/settings.py | 5 +- annuaire/urls.py | 2 +- fiches/admin.py | 3 +- fiches/forms.py | 32 +++--- fiches/models.py | 15 ++- fiches/templates/fiches/fiche.html | 126 +++++++++++----------- fiches/templates/fiches/fiches_modif.html | 14 +-- fiches/templates/fiches/search.html | 30 +++--- fiches/tests.py | 3 - fiches/urls.py | 8 +- fiches/views.py | 48 +++++---- 11 files changed, 149 insertions(+), 137 deletions(-) diff --git a/annuaire/settings.py b/annuaire/settings.py index 32af7e0..657cae3 100644 --- a/annuaire/settings.py +++ b/annuaire/settings.py @@ -86,7 +86,8 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + 'NAME': + 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', @@ -121,4 +122,4 @@ STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') -MEDIA_URL = '/media/' \ No newline at end of file +MEDIA_URL = '/media/' diff --git a/annuaire/urls.py b/annuaire/urls.py index 0c8e865..5697b50 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -24,4 +24,4 @@ urlpatterns = [ ] if settings.DEBUG: - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/fiches/admin.py b/fiches/admin.py index 9da72e0..b059338 100644 --- a/fiches/admin.py +++ b/fiches/admin.py @@ -7,10 +7,9 @@ from fiches.models import Mail from fiches.models import Address -# Register your models here. admin.site.register(Profile) admin.site.register(Department) admin.site.register(Phone) admin.site.register(Social) admin.site.register(Mail) -admin.site.register(Address) \ No newline at end of file +admin.site.register(Address) diff --git a/fiches/forms.py b/fiches/forms.py index 2ebe60b..8a487a3 100644 --- a/fiches/forms.py +++ b/fiches/forms.py @@ -1,21 +1,23 @@ from django import forms from fiches.models import Profile + class ProfileForm(forms.ModelForm): - class Meta: - model = Profile - fields = [ - "full_name", - "nickname", - "picture", - "department", - "promotion", - "birth_date", - "thurne", - "text_field", - "printing", - "keep_me" - ] + class Meta: + model = Profile + fields = [ + "full_name", + "nickname", + "picture", + "department", + "promotion", + "birth_date", + "thurne", + "text_field", + "printing", + "keep_me" + ] + class SearchForm(forms.Form): - name = forms.CharField(label='search name', max_length=1023) \ No newline at end of file + name = forms.CharField(label='search name', max_length=1023) diff --git a/fiches/models.py b/fiches/models.py index 4bd9c44..7793fdb 100644 --- a/fiches/models.py +++ b/fiches/models.py @@ -6,7 +6,10 @@ from django.contrib.auth.models import User class Profile(models.Model): user = models.OneToOneField( - User, on_delete=models.CASCADE, verbose_name=_("utilisateur"), related_name='profile' + User, + on_delete=models.CASCADE, + verbose_name=_("utilisateur"), + related_name="profile", ) full_name = models.CharField(max_length=1023, verbose_name=_("nom")) nickname = models.CharField(blank=True, max_length=1023, verbose_name=_("surnom")) @@ -26,12 +29,14 @@ class Profile(models.Model): keep_me = models.BooleanField( default=False, verbose_name=_("conserver la fiche annuaire ?") ) + def __str__(self): return self.full_name class Department(models.Model): name = models.CharField(max_length=255, verbose_name=_("nom du département")) + def __str__(self): return self.name @@ -42,6 +47,7 @@ class Phone(models.Model): ) name = models.CharField(max_length=255, verbose_name=_("type")) number = models.CharField(max_length=1023, verbose_name=_("numéro")) + def __str__(self): return "{} : {}".format(self.name, self.number) @@ -52,23 +58,28 @@ class Social(models.Model): ) name = models.CharField(max_length=255, verbose_name=_("type")) content = models.CharField(max_length=1023, verbose_name=_("contenu")) + def __str__(self): return "{} : {}".format(self.name, self.content) + class Mail(models.Model): profile = models.ForeignKey( Profile, on_delete=models.CASCADE, verbose_name=_("profil") ) name = models.CharField(max_length=255, verbose_name=_("type")) mail = models.CharField(max_length=1023, verbose_name=_("adresse mail")) + def __str__(self): return "{} : {}".format(self.name, self.mail) + class Address(models.Model): profile = models.ForeignKey( Profile, on_delete=models.CASCADE, verbose_name=_("profil") ) name = models.CharField(max_length=255, verbose_name=_("type")) content = models.CharField(max_length=1023, verbose_name=_("adresse")) + def __str__(self): - return "{} : {}".format(self.name, self.content) \ No newline at end of file + return "{} : {}".format(self.name, self.content) diff --git a/fiches/templates/fiches/fiche.html b/fiches/templates/fiches/fiche.html index a21c0be..7458f52 100644 --- a/fiches/templates/fiches/fiche.html +++ b/fiches/templates/fiches/fiche.html @@ -1,66 +1,66 @@ {% extends "fiches/base.html" %} {% block content %} -
-
- -
-
-

{{ profile.full_name }} - ({{ profile.promotion }}) - {% if profile.nickname %} - alias:{{ profile.nickname }})

- {% endif %} -

- {% if profile.department.exists %} - Département{{ profile.department.count|pluralize}} : - {% endif %} - {% for dep in profile.department.all %} - {{ dep }} - {% if not forloop.last %} - , - {% endif %} - {% endfor %} - {% if profile.birth_date %} -

-

- {% if profile.phone_set.exists %} - Téléphone{{ profile.phone_set.count|pluralize}} : - {% endif %} - {% for ph in profile.phone_set.all %} - {{ ph }} - {% if not forloop.last %} - ,
- {% endif %} - {% endfor %} -

-

- {% if profile.social_set.exists %} - {{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} : - {% endif %} - {% for ph in profile.social_set.all %} - {{ ph }} - {% if not forloop.last %} - ,
- {% endif %} - {% endfor %} -

-

- Date de naissance : {{ profile.birth_date }} -

- {% endif %} +
+
+ +
+
+

{{ profile.full_name }} + ({{ profile.promotion }}) + {% if profile.nickname %} + alias:{{ profile.nickname }})

+ {% endif %} +

+ {% if profile.department.exists %} + Département{{ profile.department.count|pluralize}} : + {% endif %} + {% for dep in profile.department.all %} + {{ dep }} + {% if not forloop.last %} + , + {% endif %} + {% endfor %} + {% if profile.birth_date %} +

+

+ {% if profile.phone_set.exists %} + Téléphone{{ profile.phone_set.count|pluralize}} : + {% endif %} + {% for ph in profile.phone_set.all %} + {{ ph }} + {% if not forloop.last %} + ,
+ {% endif %} + {% endfor %} +

+

+ {% if profile.social_set.exists %} + {{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} : + {% endif %} + {% for ph in profile.social_set.all %} + {{ ph }} + {% if not forloop.last %} + ,
+ {% endif %} + {% endfor %} +

+

+ Date de naissance : {{ profile.birth_date }} +

+ {% endif %} - {% if profile.thurne %} -

- Thurne : {{ profile.thurne }} -

- {% endif %} -
-
-
- {% if profile.text_field %} -

- Champ libre : {{ profile.text_field }} -

- {% endif %} -
-{% endblock %} \ No newline at end of file + {% if profile.thurne %} +

+ Thurne : {{ profile.thurne }} +

+ {% endif %} +
+
+
+ {% if profile.text_field %} +

+ Champ libre : {{ profile.text_field }} +

+ {% endif %} +
+{% endblock %} diff --git a/fiches/templates/fiches/fiches_modif.html b/fiches/templates/fiches/fiches_modif.html index 87bfed1..f98dd19 100644 --- a/fiches/templates/fiches/fiches_modif.html +++ b/fiches/templates/fiches/fiches_modif.html @@ -1,11 +1,11 @@ {% extends "fiches/base.html" %} {% block content %} -

Modifier ma page d'annuaire

-
- {% csrf_token %} - {{ form.as_p }} - -
+

Modifier ma page d'annuaire

+
+ {% csrf_token %} + {{ form.as_p }} + +
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/fiches/templates/fiches/search.html b/fiches/templates/fiches/search.html index 9d77921..15eb066 100644 --- a/fiches/templates/fiches/search.html +++ b/fiches/templates/fiches/search.html @@ -1,21 +1,21 @@ {% extends "fiches/base.html" %} {% block content %} -

Chercher quelqu'un.e dans l'annuaire

-
- {% csrf_token %} - {{ form.as_p }} - -
+

Chercher quelqu'un.e dans l'annuaire

+
+ {% csrf_token %} + {{ form.as_p }} + +
-
- -
+
+ +
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/fiches/tests.py b/fiches/tests.py index 7ce503c..e69de29 100644 --- a/fiches/tests.py +++ b/fiches/tests.py @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/fiches/urls.py b/fiches/urls.py index 6ee1a8c..688a581 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -2,7 +2,7 @@ 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') - ] \ No newline at end of file + path('', views.fiche, name='fiche'), + path('edit', views.fiche_modif, name='fiche_modif'), + path('search', views.search, name='search'), +] diff --git a/fiches/views.py b/fiches/views.py index 3d51c57..a1207a9 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -1,38 +1,40 @@ from django.shortcuts import render -from django.shortcuts import get_object_or_404,redirect +from django.shortcuts import get_object_or_404, redirect from django.contrib.auth.decorators import login_required from fiches.models import Profile from fiches.forms import ProfileForm, SearchForm from django.urls import reverse -# Create your views here. + @login_required -def fiche(request,id): - profile=get_object_or_404(Profile,id=id) - return render(request,'fiches/fiche.html',{"profile":profile}) +def fiche(request, id): + profile = get_object_or_404(Profile, id=id) + return render(request, 'fiches/fiche.html', {"profile": profile}) @login_required def fiche_modif(request): - profile = request.user.profile - if request.method == 'POST': - form = ProfileForm(request.POST, instance=profile) - if form.is_valid(): - form.save() - return redirect(reverse('fiche',args=(profile.id,))) + profile = request.user.profile + if request.method == 'POST': + form = ProfileForm(request.POST, instance=profile) + if form.is_valid(): + form.save() + return redirect(reverse('fiche', args=(profile.id,))) + else: + form = ProfileForm(instance=profile) + + return render(request, 'fiches/fiches_modif.html', {"form": form}) - else: - form = ProfileForm(instance=profile) - - return render(request,'fiches/fiches_modif.html',{"form":form}) @login_required def search(request): - if request.method == 'POST': - form = SearchForm(request.POST) - if form.is_valid(): - result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name']) - return render(request,'fiches/search.html',{"form":form,"result":result}) - else: - form = SearchForm() - return render(request,'fiches/search.html',{"form":form}) + 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) + else: + form = SearchForm() + return render(request, 'fiches/search.html', {"form": form}) From 49fa15eb236cfb9d6ebcfa34b7dea8df4ce9ec04 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Sat, 8 Feb 2020 11:02:39 +0100 Subject: [PATCH 10/11] finer research function --- annuaire/urls.py | 4 +- fiches/forms.py | 11 ++++- fiches/migrations/0003_auto_20200108_2306.py | 47 ++++++++++++++++++++ fiches/templates/fiches/base.html | 10 ++++- fiches/templates/fiches/home.html | 22 +++++++++ fiches/urls.py | 7 ++- fiches/views.py | 12 ++--- 7 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 fiches/migrations/0003_auto_20200108_2306.py create mode 100644 fiches/templates/fiches/home.html 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}) From a360ebcae6f374c19e3e79644f30df1466306709 Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Sat, 8 Feb 2020 11:15:43 +0100 Subject: [PATCH 11/11] added nickname to search --- fiches/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fiches/views.py b/fiches/views.py index d0a9303..5b50a4b 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required from fiches.models import Profile from fiches.forms import ProfileForm, SearchForm from django.urls import reverse +from django.db.models import Q @login_required @@ -32,7 +33,7 @@ def home(request): if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): - result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name']) + 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: