From f9f62bd1b607148d67d00126eee8e1cc340f00da Mon Sep 17 00:00:00 2001 From: Evarin Date: Wed, 26 Dec 2018 19:06:18 +0100 Subject: [PATCH] =?UTF-8?q?Pagination=20et=20mise=20en=20cache=20des=20r?= =?UTF-8?q?=C3=A9sultats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avisstage/models.py | 2 +- avisstage/sass/_miniheader.scss | 62 +++ avisstage/sass/_recherche.scss | 220 +++++----- avisstage/sass/_responsive.scss | 62 +-- avisstage/static/css/screen.css | 387 +++++++++--------- avisstage/static/js/recherche.js | 81 +++- avisstage/templates/avisstage/base.html | 2 +- .../avisstage/recherche/resultats.html | 47 +-- .../avisstage/recherche/stage_items.html | 38 ++ avisstage/templatetags/avisstage_tags.py | 6 + avisstage/urls.py | 1 + avisstage/views_search.py | 74 +++- 12 files changed, 569 insertions(+), 413 deletions(-) create mode 100644 avisstage/sass/_miniheader.scss create mode 100644 avisstage/templates/avisstage/recherche/stage_items.html diff --git a/avisstage/models.py b/avisstage/models.py index f13b8b0..873e3bf 100644 --- a/avisstage/models.py +++ b/avisstage/models.py @@ -94,7 +94,7 @@ def create_user_profile(sender, instance, created, **kwargs): profil.save() except ldap.LDAPError: pass -post_save.connect(create_user_profile, sender=User) +#post_save.connect(create_user_profile, sender=User) # # Lieu de stage diff --git a/avisstage/sass/_miniheader.scss b/avisstage/sass/_miniheader.scss new file mode 100644 index 0000000..20ed42e --- /dev/null +++ b/avisstage/sass/_miniheader.scss @@ -0,0 +1,62 @@ + +header { + z-index: 40; + position: fixed; + top: 0px; + left: 0px; + width: 100%; + display: block; + max-height:100vh; + overflow-y: auto; + + h1 { + padding: 10px; + } + #showmenu { + display: block; + float: right; + padding: 10px; + + img { + width: 35px; + } + } + nav { + clear: both; + text-align: right; + + ul { + display: none; + + li { + display: block; + a { + display: block; + padding: 10px 20px; + height: auto; + text-align:right; + + br { + display: none; + } + .username:after { + content: " | "; + } + } + } + } + } +} +header.expanded { + nav ul { + display:block; + } +} + +h1 { + font-size: 2em; +} + +h2 { + font-size: 1.6em; +} diff --git a/avisstage/sass/_recherche.scss b/avisstage/sass/_recherche.scss index 1d8d252..23d842b 100644 --- a/avisstage/sass/_recherche.scss +++ b/avisstage/sass/_recherche.scss @@ -1,93 +1,96 @@ -section.content.recherche { - form.recherche { - .generale { - display: inline-block; - text-align: right; - position: relative; - left: 50%; - transform: translateX(-50%); - width: 500px; - max-width: 100%; - white-space: nowrap; +body.recherche { - span { - display:flex; - } - - input[type="text"] { - max-width: 500px; - padding: 10px; - border: 1px solid $fond; - margin:0 5px; - } - input { - display: inline; - } - } + section.content { + form.recherche { + .generale { + display: inline-block; + text-align: right; + position: relative; + left: 50%; + transform: translateX(-50%); + width: 500px; + max-width: 100%; + white-space: nowrap; - .avancee { - background: #fff; - display: none; - padding: 15px; - margin-bottom: 15px; - - &.expanded { - display:block; - } - - .help_text { - font-style: italic; - font-size: 0.9em; - } - - ul { - margin: 0 -5px; - display: flexbox; - display: flex; - flex-wrap: wrap; - justify-content: space-between; - width: 100%; + span { + display:flex; + } - li { - flex-grow: 1; - width: 22%; - min-width: 150px; - margin: 5px 0; - padding: 0 10px; + input[type="text"] { + max-width: 500px; + padding: 10px; + border: 1px solid $fond; + margin:0 5px; + } + input { + display: inline; + } + } - label { - font-weight: bold; - font-size: 0.9em; - } + .avancee { + background: #fff; + display: none; + padding: 15px; + margin-bottom: 15px; + + &.expanded { + display:block; + } + + .help_text { + font-style: italic; + font-size: 0.9em; + } + + ul { + margin: 0 -5px; + display: flexbox; + display: flex; + flex-wrap: wrap; + justify-content: space-between; + width: 100%; - input[type="text"], input[type='number'], select { - display: block; + li { + flex-grow: 1; + width: 22%; min-width: 150px; - display: inline-block; - width: 100%; - font-size: 0.9em; - background-color: #f8f8f8; + margin: 5px 0; + padding: 0 10px; + + label { + font-weight: bold; + font-size: 0.9em; + } + + input[type="text"], input[type='number'], select { + display: block; + min-width: 150px; + display: inline-block; + width: 100%; + font-size: 0.9em; + background-color: #f8f8f8; + } + &.btnsubmit { + text-align:right; + } + &.field__sujet, &.field__contexte { + width:45%; + min-width: 300px; + } + } - &.btnsubmit { - text-align:right; - } - &.field__sujet, &.field__contexte { - width:45%; - min-width: 300px; - } - } } } - } - .recherche-carte, .recherche-liste { - position:relative; - } + .recherche-carte, .recherche-liste { + position:relative; + } - .numresults { - font-size: 0.9em; - font-weight: bold; + .numresults { + font-size: 0.9em; + font-weight: bold; + } } &.vue-hybride #voir_hybride, @@ -124,14 +127,14 @@ section.content.recherche { left: 60px; } - &.vue-hybride, &.vue-carte { + &.vue-hybride section.content, + &.vue-carte section.content { width: 100%; min-width: unset; max-width: unset; min-height: unset; max-height: unset; - height: 90vh; - height: calc(100vh - 30px); + height: 100vh; padding: 0; margin: 0; @@ -145,7 +148,8 @@ section.content.recherche { } &.vue-liste .recherche-carte, - &.vue-carte .recherche-liste { + &.vue-carte .recherche-liste, + &.vue-carte header { display: none; } @@ -156,31 +160,41 @@ section.content.recherche { } &.vue-hybride { - display: flex; + + @import "_miniheader.scss"; + + header { + position: fixed; + top: 0; + left: 0; + width: 500px; + z-index: 15; + } + section.content { + display: flex; - .recherche-liste { - width: 100%; - min-width: 400px; - max-width: 500px; - flex: 1; - - .dates { - display:none; - } - ul.infos li { - font-size: 0.8em; - font-weight: normal; - &.year { - display: inline-block; + .recherche-liste { + padding-top: 60px; + width: 500px; + + .dates { + display:none; + } + ul.infos li { + font-size: 0.8em; + font-weight: normal; + &.year { + display: inline-block; + } } } - } - .recherche-carte { - flex: 1.5; - width: 100%; + .recherche-carte { + flex: 1.5; + width: 100%; - .vue-options { - display:none; + .vue-options { + display:none; + } } } } diff --git a/avisstage/sass/_responsive.scss b/avisstage/sass/_responsive.scss index 5ab865d..408579f 100644 --- a/avisstage/sass/_responsive.scss +++ b/avisstage/sass/_responsive.scss @@ -18,67 +18,7 @@ } @media screen and (max-width: 600px) { - header { - z-index: 40; - position: fixed; - top: 0px; - left: 0px; - width: 100%; - display: block; - max-height:100vh; - overflow-y: auto; - - h1 { - padding: 10px; - } - #showmenu { - display: block; - float: right; - padding: 10px; - - img { - width: 35px; - } - } - nav { - clear: both; - text-align: right; - - ul { - display: none; - - li { - display: block; - a { - display: block; - padding: 10px 20px; - height: auto; - text-align:right; - - br { - display: none; - } - .username:after { - content: " | "; - } - } - } - } - } - } - header.expanded { - nav ul { - display:block; - } - } - - h1 { - font-size: 2em; - } - - h2 { - font-size: 1.6em; - } + @import "_miniheader.scss"; #feedback-button { transform: unset; diff --git a/avisstage/static/css/screen.css b/avisstage/static/css/screen.css index 188b13b..f91e8d5 100644 --- a/avisstage/static/css/screen.css +++ b/avisstage/static/css/screen.css @@ -1225,8 +1225,8 @@ table.stats td, table.stats th { text-align: center; } -/* line 3, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .generale { +/* line 5, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .generale { display: inline-block; text-align: right; position: relative; @@ -1236,39 +1236,39 @@ section.content.recherche form.recherche .generale { max-width: 100%; white-space: nowrap; } -/* line 13, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .generale span { +/* line 15, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .generale span { display: flex; } -/* line 17, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .generale input[type="text"] { +/* line 19, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .generale input[type="text"] { max-width: 500px; padding: 10px; border: 1px solid #8fcc33; margin: 0 5px; } -/* line 23, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .generale input { +/* line 25, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .generale input { display: inline; } -/* line 28, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee { +/* line 30, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee { background: #fff; display: none; padding: 15px; margin-bottom: 15px; } -/* line 34, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee.expanded { +/* line 36, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee.expanded { display: block; } -/* line 38, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee .help_text { +/* line 40, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee .help_text { font-style: italic; font-size: 0.9em; } -/* line 43, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee ul { +/* line 45, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee ul { margin: 0 -5px; display: flexbox; display: flex; @@ -1276,21 +1276,21 @@ section.content.recherche form.recherche .avancee ul { justify-content: space-between; width: 100%; } -/* line 51, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee ul li { +/* line 53, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee ul li { flex-grow: 1; width: 22%; min-width: 150px; margin: 5px 0; padding: 0 10px; } -/* line 58, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee ul li label { +/* line 60, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee ul li label { font-weight: bold; font-size: 0.9em; } -/* line 63, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee ul li input[type="text"], section.content.recherche form.recherche .avancee ul li input[type='number'], section.content.recherche form.recherche .avancee ul li select { +/* line 65, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee ul li input[type="text"], body.recherche section.content form.recherche .avancee ul li input[type='number'], body.recherche section.content form.recherche .avancee ul li select { display: block; min-width: 150px; display: inline-block; @@ -1298,152 +1298,222 @@ section.content.recherche form.recherche .avancee ul li input[type="text"], sect font-size: 0.9em; background-color: #f8f8f8; } -/* line 71, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee ul li.btnsubmit { +/* line 73, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee ul li.btnsubmit { text-align: right; } -/* line 74, ../../sass/_recherche.scss */ -section.content.recherche form.recherche .avancee ul li.field__sujet, section.content.recherche form.recherche .avancee ul li.field__contexte { +/* line 76, ../../sass/_recherche.scss */ +body.recherche section.content form.recherche .avancee ul li.field__sujet, body.recherche section.content form.recherche .avancee ul li.field__contexte { width: 45%; min-width: 300px; } -/* line 84, ../../sass/_recherche.scss */ -section.content.recherche .recherche-carte, section.content.recherche .recherche-liste { +/* line 86, ../../sass/_recherche.scss */ +body.recherche section.content .recherche-carte, body.recherche section.content .recherche-liste { position: relative; } -/* line 88, ../../sass/_recherche.scss */ -section.content.recherche .numresults { +/* line 90, ../../sass/_recherche.scss */ +body.recherche section.content .numresults { font-size: 0.9em; font-weight: bold; } -/* line 93, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride #voir_hybride, section.content.recherche.vue-carte #voir_carte, section.content.recherche.vue-liste #voir_liste { +/* line 96, ../../sass/_recherche.scss */ +body.recherche.vue-hybride #voir_hybride, body.recherche.vue-carte #voir_carte, body.recherche.vue-liste #voir_liste { background: #d2ebad; color: #000; } -/* line 100, ../../sass/_recherche.scss */ -section.content.recherche .vue-options { +/* line 103, ../../sass/_recherche.scss */ +body.recherche .vue-options { text-align: center; } -/* line 102, ../../sass/_recherche.scss */ -section.content.recherche .vue-options ul { +/* line 105, ../../sass/_recherche.scss */ +body.recherche .vue-options ul { display: inline-block; border-radius: 5px; overflow: hidden; } -/* line 107, ../../sass/_recherche.scss */ -section.content.recherche .vue-options ul li { +/* line 110, ../../sass/_recherche.scss */ +body.recherche .vue-options ul li { display: inline-block; background: #fff; padding: 10px; } -/* line 111, ../../sass/_recherche.scss */ -section.content.recherche .vue-options ul li a { +/* line 114, ../../sass/_recherche.scss */ +body.recherche .vue-options ul li a { display: block; padding: 10px; margin: -10px; } -/* line 120, ../../sass/_recherche.scss */ -section.content.recherche .recherche-carte .vue-options { +/* line 123, ../../sass/_recherche.scss */ +body.recherche .recherche-carte .vue-options { position: absolute; z-index: 3; top: 15px; left: 60px; } -/* line 127, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride, section.content.recherche.vue-carte { +/* line 130, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content, body.recherche.vue-carte section.content { width: 100%; min-width: unset; max-width: unset; min-height: unset; max-height: unset; - height: 90vh; - height: calc(100vh - 30px); + height: 100vh; padding: 0; margin: 0; } -/* line 138, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-carte, section.content.recherche.vue-hybride .recherche-liste, section.content.recherche.vue-carte .recherche-carte, section.content.recherche.vue-carte .recherche-liste { +/* line 141, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-carte, body.recherche.vue-hybride section.content .recherche-liste, body.recherche.vue-carte section.content .recherche-carte, body.recherche.vue-carte section.content .recherche-liste { height: 100%; } -/* line 141, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-liste, section.content.recherche.vue-carte .recherche-liste { +/* line 144, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-liste, body.recherche.vue-carte section.content .recherche-liste { overflow-y: auto; padding: 15px; } -/* line 147, ../../sass/_recherche.scss */ -section.content.recherche.vue-liste .recherche-carte, section.content.recherche.vue-carte .recherche-liste { +/* line 150, ../../sass/_recherche.scss */ +body.recherche.vue-liste .recherche-carte, body.recherche.vue-carte .recherche-liste, body.recherche.vue-carte header { display: none; } -/* line 152, ../../sass/_recherche.scss */ -section.content.recherche.vue-carte .recherche-carte, section.content.recherche.vue-liste .recherche-liste { +/* line 156, ../../sass/_recherche.scss */ +body.recherche.vue-carte .recherche-carte, body.recherche.vue-liste .recherche-liste { display: block; width: 100%; } -/* line 158, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride { - display: flex; -} -/* line 161, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-liste { +/* line 2, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header { + z-index: 40; + position: fixed; + top: 0px; + left: 0px; width: 100%; - min-width: 400px; - max-width: 500px; - flex: 1; + display: block; + max-height: 100vh; + overflow-y: auto; } -/* line 167, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-liste .dates { +/* line 12, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header h1 { + padding: 10px; +} +/* line 15, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header #showmenu { + display: block; + float: right; + padding: 10px; +} +/* line 20, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header #showmenu img { + width: 35px; +} +/* line 24, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header nav { + clear: both; + text-align: right; +} +/* line 28, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header nav ul { display: none; } -/* line 170, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-liste ul.infos li { +/* line 31, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header nav ul li { + display: block; +} +/* line 33, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header nav ul li a { + display: block; + padding: 10px 20px; + height: auto; + text-align: right; +} +/* line 39, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header nav ul li a br { + display: none; +} +/* line 42, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header nav ul li a .username:after { + content: " | "; +} +/* line 51, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride header.expanded nav ul { + display: block; +} +/* line 56, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride h1 { + font-size: 2em; +} +/* line 60, ../../sass/_miniheader.scss */ +body.recherche.vue-hybride h2 { + font-size: 1.6em; +} +/* line 166, ../../sass/_recherche.scss */ +body.recherche.vue-hybride header { + position: fixed; + top: 0; + left: 0; + width: 500px; + z-index: 15; +} +/* line 173, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content { + display: flex; +} +/* line 176, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-liste { + padding-top: 60px; + width: 500px; +} +/* line 180, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-liste .dates { + display: none; +} +/* line 183, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-liste ul.infos li { font-size: 0.8em; font-weight: normal; } -/* line 173, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-liste ul.infos li.year { +/* line 186, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-liste ul.infos li.year { display: inline-block; } -/* line 178, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-carte { +/* line 191, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-carte { flex: 1.5; width: 100%; } -/* line 182, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride .recherche-carte .vue-options { +/* line 195, ../../sass/_recherche.scss */ +body.recherche.vue-hybride section.content .recherche-carte .vue-options { display: none; } -/* line 188, ../../sass/_recherche.scss */ -section.content.recherche #carte { +/* line 202, ../../sass/_recherche.scss */ +body.recherche #carte { width: 100%; height: 100%; } -/* line 193, ../../sass/_recherche.scss */ -section.content.recherche .recherche-liste.recherche-details { +/* line 207, ../../sass/_recherche.scss */ +body.recherche .recherche-liste.recherche-details { display: none !important; } -/* line 196, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride.vue-details .recherche-liste { +/* line 210, ../../sass/_recherche.scss */ +body.recherche.vue-hybride.vue-details .recherche-liste { display: none; } -/* line 199, ../../sass/_recherche.scss */ -section.content.recherche.vue-hybride.vue-details .recherche-liste.recherche-details { +/* line 213, ../../sass/_recherche.scss */ +body.recherche.vue-hybride.vue-details .recherche-liste.recherche-details { display: block !important; } @media screen and (max-width: 600px) { - /* line 207, ../../sass/_recherche.scss */ + /* line 221, ../../sass/_recherche.scss */ section.content.recherche.vue-hybride, section.content.recherche.vue-carte { height: calc(100vh - 60px); margin-top: 60px; } - /* line 214, ../../sass/_recherche.scss */ + /* line 228, ../../sass/_recherche.scss */ section.content.recherche .recherche-liste ul li.stage:not(.expanded) ul.infos { max-height: 115px; overflow-y: hidden; position: relative; } - /* line 219, ../../sass/_recherche.scss */ + /* line 233, ../../sass/_recherche.scss */ section.content.recherche .recherche-liste ul li.stage:not(.expanded) ul.infos:after { position: absolute; content: "⋅⋅⋅"; @@ -1456,35 +1526,35 @@ section.content.recherche.vue-hybride.vue-details .recherche-liste.recherche-det text-align: center; border-top: 1px solid #ccc; } - /* line 233, ../../sass/_recherche.scss */ + /* line 247, ../../sass/_recherche.scss */ section.content.recherche .recherche-liste ul li.stage:not(.expanded) a.hoverlink { display: none; } - /* line 237, ../../sass/_recherche.scss */ + /* line 251, ../../sass/_recherche.scss */ section.content.recherche .recherche-liste .dates .detail { display: none; } - /* line 243, ../../sass/_recherche.scss */ + /* line 257, ../../sass/_recherche.scss */ ul.messages { display: none; } } @media screen and (max-width: 500px), screen and (max-width: 800px) and (orientation: portrait) { - /* line 251, ../../sass/_recherche.scss */ + /* line 265, ../../sass/_recherche.scss */ section.content.recherche form.recherche .generale span input { font-size: 0.9em; flex: 1; } - /* line 255, ../../sass/_recherche.scss */ + /* line 269, ../../sass/_recherche.scss */ section.content.recherche form.recherche .generale span input[type=submit] { white-space: normal; } - /* line 259, ../../sass/_recherche.scss */ + /* line 273, ../../sass/_recherche.scss */ section.content.recherche.vue-hybride, section.content.recherche.vue-carte { flex-direction: column; } - /* line 260, ../../sass/_recherche.scss */ + /* line 274, ../../sass/_recherche.scss */ section.content.recherche.vue-hybride .recherche-liste, section.content.recherche.vue-carte .recherche-liste { max-width: 100vw; min-width: unset; @@ -1512,76 +1582,7 @@ section.content.recherche.vue-hybride.vue-details .recherche-liste.recherche-det } } @media screen and (max-width: 600px) { - /* line 21, ../../sass/_responsive.scss */ - header { - z-index: 40; - position: fixed; - top: 0px; - left: 0px; - width: 100%; - display: block; - max-height: 100vh; - overflow-y: auto; - } - /* line 31, ../../sass/_responsive.scss */ - header h1 { - padding: 10px; - } - /* line 34, ../../sass/_responsive.scss */ - header #showmenu { - display: block; - float: right; - padding: 10px; - } - /* line 39, ../../sass/_responsive.scss */ - header #showmenu img { - width: 35px; - } - /* line 43, ../../sass/_responsive.scss */ - header nav { - clear: both; - text-align: right; - } - /* line 47, ../../sass/_responsive.scss */ - header nav ul { - display: none; - } - /* line 50, ../../sass/_responsive.scss */ - header nav ul li { - display: block; - } - /* line 52, ../../sass/_responsive.scss */ - header nav ul li a { - display: block; - padding: 10px 20px; - height: auto; - text-align: right; - } - /* line 58, ../../sass/_responsive.scss */ - header nav ul li a br { - display: none; - } - /* line 61, ../../sass/_responsive.scss */ - header nav ul li a .username:after { - content: " | "; - } - - /* line 70, ../../sass/_responsive.scss */ - header.expanded nav ul { - display: block; - } - - /* line 75, ../../sass/_responsive.scss */ - h1 { - font-size: 2em; - } - - /* line 79, ../../sass/_responsive.scss */ - h2 { - font-size: 1.6em; - } - - /* line 83, ../../sass/_responsive.scss */ + /* line 23, ../../sass/_responsive.scss */ #feedback-button { transform: unset; top: 0px; @@ -1592,79 +1593,79 @@ section.content.recherche.vue-hybride.vue-details .recherche-liste.recherche-det background: rgba(0, 0, 0, 0.5); } - /* line 92, ../../sass/_responsive.scss */ + /* line 32, ../../sass/_responsive.scss */ .content { margin-top: 70px; padding: 15px 3vw; } - /* line 97, ../../sass/_responsive.scss */ + /* line 37, ../../sass/_responsive.scss */ article.stage h3 { margin-top: 10px; } - /* line 101, ../../sass/_responsive.scss */ + /* line 41, ../../sass/_responsive.scss */ article.stage section .avis-texte, article.stage section .chapo { padding: 3px 10px; } - /* line 107, ../../sass/_responsive.scss */ + /* line 47, ../../sass/_responsive.scss */ article.stage section #stage-map { height: 200px; width: 100%; } - /* line 113, ../../sass/_responsive.scss */ + /* line 53, ../../sass/_responsive.scss */ article.stage section.misc .misc-content.withmap { display: block; } - /* line 116, ../../sass/_responsive.scss */ + /* line 56, ../../sass/_responsive.scss */ article.stage section.misc .misc-content.withmap > div { display: block; vertical-align: top; } - /* line 120, ../../sass/_responsive.scss */ + /* line 60, ../../sass/_responsive.scss */ article.stage section.misc .misc-content.withmap .map { width: 80%; min-width: 250px; min-height: 200px; margin: 0 auto; } - /* line 126, ../../sass/_responsive.scss */ + /* line 66, ../../sass/_responsive.scss */ article.stage section.misc .misc-content.withmap .desc { padding: 5px; } - /* line 134, ../../sass/_responsive.scss */ + /* line 74, ../../sass/_responsive.scss */ article.stage section .plusmoins > div { display: block; } - /* line 137, ../../sass/_responsive.scss */ + /* line 77, ../../sass/_responsive.scss */ article.stage section .plusmoins > div > *, article.stage section .plusmoins > div:before { display: block; } - /* line 141, ../../sass/_responsive.scss */ + /* line 81, ../../sass/_responsive.scss */ article.stage section .plusmoins > div:before { text-align: left; width: 100%; font-size: 1.5em; } - /* line 146, ../../sass/_responsive.scss */ + /* line 86, ../../sass/_responsive.scss */ article.stage section .plusmoins > div.moins:before { text-align: right; margin-top: 5px; } - /* line 155, ../../sass/_responsive.scss */ + /* line 95, ../../sass/_responsive.scss */ article.stage .section-wrapper { display: block; margin-left: 0; } - /* line 159, ../../sass/_responsive.scss */ + /* line 99, ../../sass/_responsive.scss */ article.stage .section-wrapper .toc-wrapper, article.stage .section-wrapper > section { display: block; } - /* line 162, ../../sass/_responsive.scss */ + /* line 102, ../../sass/_responsive.scss */ article.stage .section-wrapper .toc-wrapper { max-width: unset; width: unset; } - /* line 166, ../../sass/_responsive.scss */ + /* line 106, ../../sass/_responsive.scss */ article.stage .section-wrapper .toc { display: none; position: relative; @@ -1673,65 +1674,65 @@ section.content.recherche.vue-hybride.vue-details .recherche-liste.recherche-det padding: 4px; } - /* line 176, ../../sass/_responsive.scss */ + /* line 116, ../../sass/_responsive.scss */ .homeh1 { display: block; } - /* line 178, ../../sass/_responsive.scss */ + /* line 118, ../../sass/_responsive.scss */ .homeh1 > * { display: block; } - /* line 183, ../../sass/_responsive.scss */ + /* line 123, ../../sass/_responsive.scss */ article.promo .explications { display: block; } - /* line 185, ../../sass/_responsive.scss */ + /* line 125, ../../sass/_responsive.scss */ article.promo .explications div { max-width: 100%; display: block; } - /* line 192, ../../sass/_responsive.scss */ + /* line 132, ../../sass/_responsive.scss */ .condensed-stages { display: block; } - /* line 195, ../../sass/_responsive.scss */ + /* line 135, ../../sass/_responsive.scss */ .condensed-stages li:before, .condensed-stages li, .condensed-stages a { display: block; width: auto; max-width: auto; } - /* line 201, ../../sass/_responsive.scss */ + /* line 141, ../../sass/_responsive.scss */ .condensed-stages li:before { padding: 3px 15px; } - /* line 205, ../../sass/_responsive.scss */ + /* line 145, ../../sass/_responsive.scss */ .condensed-stages li.stage-ajout:before { display: none; } - /* line 210, ../../sass/_responsive.scss */ + /* line 150, ../../sass/_responsive.scss */ ul.infos { display: flex; flex-wrap: wrap; justify-content: space-between; } - /* line 219, ../../sass/_responsive.scss */ + /* line 159, ../../sass/_responsive.scss */ .stage-liste li .misc-hdr .dates .detail { display: inline; } - /* line 222, ../../sass/_responsive.scss */ + /* line 162, ../../sass/_responsive.scss */ .stage-liste li .misc-hdr .dates .year { padding: 0; } - /* line 230, ../../sass/_responsive.scss */ + /* line 170, ../../sass/_responsive.scss */ form .field { display: block; } - /* line 233, ../../sass/_responsive.scss */ + /* line 173, ../../sass/_responsive.scss */ form .field label, form .field .label { display: block; text-align: left; @@ -1740,18 +1741,18 @@ section.content.recherche.vue-hybride.vue-details .recherche-liste.recherche-det margin-top: 0; width: auto; } - /* line 242, ../../sass/_responsive.scss */ + /* line 182, ../../sass/_responsive.scss */ form .field .help_text { text-align: right; color: #395214; } - /* line 247, ../../sass/_responsive.scss */ + /* line 187, ../../sass/_responsive.scss */ form .field .input { padding-left: 20px; display: block; text-align: right; } - /* line 253, ../../sass/_responsive.scss */ + /* line 193, ../../sass/_responsive.scss */ form .field input, form .field textarea, form .field div.tinymce, form .field select { background: #f4faeb; } diff --git a/avisstage/static/js/recherche.js b/avisstage/static/js/recherche.js index 03735b5..56e61c4 100644 --- a/avisstage/static/js/recherche.js +++ b/avisstage/static/js/recherche.js @@ -1,7 +1,8 @@ -function InterfaceRecherche(STATIC_ROOT, API_LIEU, lieux) { +function InterfaceRecherche(STATIC_ROOT, API_LIEU, ITEMS_URL, lieux) { var interface_mode, main_container; var lieux_map = {}, lieux_list = [], stages_map = {}, lieux_db = {}; - var stages_data = {}; + var stages_db = {}; + var details_liste_data; var marqueurs = L.markerClusterGroup(); var marqueurs_db = {}; var changevue; @@ -13,7 +14,7 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, lieux) { // TODO se souvenir des préférences d'affichage function initInterface() { - main_container = $(".content.recherche"); + main_container = $("body"); if (main_container.hasClass("vue-liste")) { interface_mode = "liste"; } else if (main_container.hasClass("vue-carte")) { @@ -43,6 +44,17 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, lieux) { }); changeInterface(interface_mode); + initLoadMoreAJAX(); + referenceStageItems($("#resultats").children()); + } + + function referenceStageItems (stages, hard) { + $.each(stages, function(i, item) { + if (item.id === undefined) return; + var iid = Number(item.id.split("-")[2]); + if (stages_db[iid] !== undefined && !hard) return; + stages_db[iid] = $(item); + }); } // Changement d'affichage : mise à jour des classes et démarrage de la carte si nécessaire @@ -53,8 +65,8 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, lieux) { function changeInterface(mode) { interface_mode = mode; - $(".content.recherche").removeClass("vue-carte vue-hybride vue-liste") - .addClass("vue-"+mode); + main_container.removeClass("vue-carte vue-hybride vue-liste") + .addClass("vue-"+mode); if (mode=="hybride" || mode=="carte") { initCarte(); map.invalidateSize(); @@ -84,7 +96,7 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, lieux) { var greenIcon = makeIcon('red'); var blueIcon = makeIcon('blue', 1.2); - // Chargeùent des infos + // Chargement des infos function onLoadLieux(data){ console.log(data); var lieux = data.objects; @@ -133,7 +145,7 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, lieux) { var html = $("
").html(marqueur._popup_header); var stageliste = $("
-

{{ stages|length }} expérience{{ stages|length|pluralize }} trouvée{{ stages|length|pluralize }}

+

{{ paginator.paginator.count }} expérience{{ paginator.paginator.count|pluralize }} trouvée{{ paginator.paginator.count|pluralize }}

{% endif %} @@ -82,12 +51,16 @@
{% endif %} diff --git a/avisstage/templates/avisstage/recherche/stage_items.html b/avisstage/templates/avisstage/recherche/stage_items.html new file mode 100644 index 0000000..a8bf646 --- /dev/null +++ b/avisstage/templates/avisstage/recherche/stage_items.html @@ -0,0 +1,38 @@ +{% load avisstage_tags %} +{% for stage in stages %} + {% if tri == '-date_maj' %} + {% ifchanged stage.date_maj.date %}
  • Mis à jour le {{ stage.date_maj.date }}
  • {% endifchanged %} + {% endif %} +
  • +
    +

    {{ stage.sujet }} par {{ stage.auteur.nom }}

    +

    {{ stage.date_debut|date:"d/m" }}{{ stage.date_fin|date:"d/m" }}{{ stage.date_debut|date:"Y" }}

    +
    +
    +
      +
    • {{ stage.get_type_stage_display }}
    • + {% if stage.structure %}
    • {{ stage.structure }}
    • {% endif %} + {% for lieu in stage.lieux.all %}
    • {{ lieu.nom }}
    • {% endfor %} + {% for matiere in stage.matieres.all %} +
    • {{ matiere.nom }}
    • + {% endfor %} + {% for thematique in stage.thematiques.all %} +
    • {{ thematique.name }}
    • + {% endfor %} +
    • {{ stage.date_debut|date:"Y" }}
    • +
    • Avis stage {{ stage.len_avis_stage|avis_len }}
    • +
    • Avis lieux {{ stage.len_avis_lieux|avis_len }}
    • +
    +
    +   +
  • +{% empty %} +
  • Aucun stage ne correspond à votre recherche et vos critères
  • +{% endfor %} +{% if paginator %} + +{% endif %} diff --git a/avisstage/templatetags/avisstage_tags.py b/avisstage/templatetags/avisstage_tags.py index 98d9ebb..3118e4f 100644 --- a/avisstage/templatetags/avisstage_tags.py +++ b/avisstage/templatetags/avisstage_tags.py @@ -33,3 +33,9 @@ def avis_len(value): return "court" else: return "long" + +@register.simple_tag +def url_replace(request, field, value): + dict_ = request.GET.copy() + dict_[field] = value + return dict_.urlencode() diff --git a/avisstage/urls.py b/avisstage/urls.py index 15c3bc9..59f35b8 100644 --- a/avisstage/urls.py +++ b/avisstage/urls.py @@ -23,6 +23,7 @@ urlpatterns = [ url(r'^profil/edit/$', views.ProfilEdit.as_view(), name='profil_edit'), url(r'^recherche/$', views.recherche, name='recherche'), url(r'^recherche/resultats/$', views.recherche_resultats, name='recherche_resultats'), + url(r'^recherche/items/$', views.stage_items, name='stage_items'), url(r'^feedback/$', views.feedback, name='feedback'), url(r'^moderation/$', views.statistiques, name='moderation'), url(r'^api/', include(v1_api.urls)), diff --git a/avisstage/views_search.py b/avisstage/views_search.py index 4b1baf0..5614055 100644 --- a/avisstage/views_search.py +++ b/avisstage/views_search.py @@ -1,16 +1,21 @@ # coding: utf-8 -from django.shortcuts import render, redirect, get_object_or_404 -from django.contrib.auth.decorators import login_required +from datetime import date from django import forms +from django.contrib.auth.decorators import login_required +from django.core.cache import cache +from django.core.paginator import Paginator from django.db.models import Q +from django.http import JsonResponse, HttpResponseBadRequest +from django.shortcuts import render, redirect, get_object_or_404 + +import json from .documents import StageDocument from .models import Stage from .statics import TYPE_LIEU_OPTIONS, TYPE_STAGE_OPTIONS, NIVEAU_SCOL_OPTIONS -from datetime import date # Recherche class SearchForm(forms.Form): @@ -137,13 +142,66 @@ def recherche_resultats(request): if request.method == "GET": form = SearchForm(request.GET) if form.is_valid(): - stages, tri = cherche(**form.cleaned_data) - stages = stages.prefetch_related('lieux', 'auteur', 'matieres', 'thematiques') - lieux = [[stageid, lieuid] for (stageid, lieuid) in stages.values_list('id', 'lieux') if lieuid is not None] + page = request.GET.get("page", 1) + search_args = form.cleaned_data + + # Gestion du cache + cache_key = json.dumps(search_args, sort_keys=True) + cached = cache.get(cache_key) + if cached is None: + # Requête effective + stages, tri = cherche(**search_args) + stageids = stages.values_list('id', flat=True) + lieux = [[stageid, lieuid] for (stageid, lieuid) in stages.values_list('id', 'lieux') if lieuid is not None] + + # Sauvegarde dans le cache + to_cache = {"stages": stageids, "lieux": lieux, "tri": tri} + cache.set(cache_key, to_cache, 600) + else: + # Lecture du cache + stageids = cached["stages"] + lieux = cached["lieux"] + tri = cached["tri"] + + # Pagination + paginator = Paginator(stageids, 25) + try: + stageids = paginator.page(page) + except InvalidPage: + stageids = [] + + if cached is None: + stages = stages[stageids.start_index()-1:stageids.end_index()] + else: + stages = Stage.objects.filter(id__in=stageids) + + stages = stages.prefetch_related('lieux', 'auteur', + 'matieres', 'thematiques') else: form = SearchForm() if stages: vue = 'vue-hybride' - return render(request, 'avisstage/recherche/resultats.html', - {"form": form, "stages":stages, + + # Version JSON pour recherche dynamique + if request.GET.get("format") == "json": + return JsonResponse({"stages": stages, "page": page, + "num_pages": paginator.num_pages}) + + template_name = 'avisstage/recherche/resultats.html' + if request.GET.get("format") == "raw": + template_name = 'avisstage/recherche/stage_items.html' + return render(request, template_name, + {"form": form, "stages": stages, "paginator": stageids, "tri": tri, "vue": vue, "lieux": lieux}) + +@login_required +def stage_items(request): + try: + stageids = [int(a) for a in request.GET.get("ids", "").split(';')] + except ValueError: + return HttpResponseBadRequest("Paramètre incorrect") + stages = Stage.objects.filter(id__in=stageids)\ + .prefetch_related('lieux', 'auteur', + 'matieres', 'thematiques') + return render(request, 'avisstage/recherche/stage_items.html', + {"stages": stages})