Commit 074558c0 authored by Fabien Zucchet's avatar Fabien Zucchet

Merge branch 'search-feature' into 'master'

Search feature

See merge request !43
parents 77f4cb3d 6f4a2953
......@@ -9,7 +9,11 @@ mysqlclient = "*"
ddtrace = "*"
oauth_vr = {git = "https://gitlab.viarezo.fr/ViaRezo/oauth-django-module.git", editable = true, ref = "master"}
[dev-packages]
pylint = "*"
django-debug-toolbar = "*"
pyyaml = "*"
[requires]
python_version = "3.5"
python_version = ">3.5"
......@@ -46,7 +46,7 @@ body {
} */
h1, h2, h3, h4 {
font-family: earthorbiter;
font-family: earthorbiter;
}
.ui.cards {
......@@ -56,4 +56,10 @@ h1, h2, h3, h4 {
footer {
position: absolute;
bottom: 0;
}
.center-div {
margin: 0 auto;
text-align: center;
width: 300px;
}
\ No newline at end of file
<div class="ui horizontal divider">Recherche</div>
<div class="ui container">
<div class="ui container">
<div class="ui left icon action input fluid disabled">
<i class="search icon"></i>
<input placeholder="Nom du cours, du document..." type="text"/>
<div class="ui blue submit button">Rechercher</div>
</div>
<form method="GET" action="/search" >
<div class="ui left icon action input fluid">
<i class="search icon"></i>
<input placeholder="Nom du cours, du professeur, du document..." type="text" name="query">
<button class="ui blue submit button" type="submit">Rechercher</button>
</div>
</form>
</div>
</div>
\ No newline at end of file
<div class="ui fluid card">
<div class="content">
<div class="header">
<i class="student icon"></i>
{{ teacher.firstName }} {{teacher.lastName }}
</div>
<div class="ui list">
<div class="item" title="Email"><i class="envelope icon"></i> {{ teacher.email }}</div>
<div class="item" title="Département"><i class="industry icon"></i> {{ teacher.department }}</div>
<div class="item" title="Bureau"><i class="coffee icon"></i> {{ teacher.office }}</div>
</div>
</div>
</div>
\ No newline at end of file
{% extends "core/base.html" %}
{% block content %}
{% include "core/components/searchbar.html" %}
</br>
<div class="center-div">
{% if count == 0 %}
<h1 class="ui header">Aucun résultat trouvé !</h1>
{% elif count == 1 %}
<h1 class="ui header">1 résultat trouvé !</h1>
{% else %}
<h1 class="ui header">{{ count }} résultats trouvés !</h1>
{% endif %}
</div>
{% if results_course|length > 0 %}
<div class="ui horizontal divider">Cours</div>
<div class="ui cards three column stackable grid container">
{% for course in results_course %}
{% include "core/components/course_sum.html" %}
{% endfor %}
</div>
{% endif %}
{% if results_teacher|length > 0 %}
<div class="ui horizontal divider">Professeurs</div>
<div class="ui cards three column stackable grid container">
{% for teacher in results_teacher %}
{% include "core/components/teacher_sum.html" %}
{% endfor %}
</div>
{% endif %}
{% if results_document|length > 0 %}
<div class="ui horizontal divider">Documents</div>
<div class="ui cards three column stackable grid container">
{% for document in results_document %}
{% include "core/components/document_sum.html" %}
{% endfor %}
</div>
{% endif %}
{% endblock content %}
\ No newline at end of file
......@@ -40,4 +40,6 @@ urlpatterns = [
# Like
path("like/<type>/<int:id>", views.like, name="like"),
path("dislike/<type>/<int:id>", views.dislike, name="dislike"),
# Search
path("search", views.search, name="search"),
]
import datetime
import unicodedata
import logging
from django.shortcuts import render, redirect
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.db.models import Count
from django.db.models import Count, Q
from django.http import HttpResponseRedirect, HttpResponse
from .models import Course, Document, User, Teacher, CourseComment, DocumentComment, CourseLike, DocumentLike
from .forms import PostDocumentCommentForm, PostDocumentForm, PostCourseCommentForm, PostCourseForm, PostTeacherForm
from .utils import count_to_moderate
logger = logging.getLogger(__name__)
# Create your views here.
@login_required
......@@ -674,6 +676,22 @@ def reset_CGU(request):
user.save()
return legal(request)
@login_required
def search(request):
# Only accept GET
if request.method != "GET":
return HttpResponse("False")
query = request.GET.get("query", '')
results_course = Course.objects.filter(name__icontains=query, isAccepted=True).order_by('name')
results_teacher = Teacher.objects.filter(Q(firstName__icontains=query) | Q(lastName__icontains=query) & Q(isAccepted=True)).order_by('lastName')
results_document = Document.objects.filter(name__icontains=query, isAccepted=True).order_by('name')
return render(request, 'core/search.html', {
'results_course': results_course,
'results_teacher': results_teacher,
'results_document': results_document,
'count': len(results_course) + len(results_teacher) + len(results_document)
})
@csrf_exempt
@login_required
......
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
# TODO: documenter l'utilisation en local
import os
from django.urls import reverse_lazy
from django.utils.http import urlencode
......@@ -44,6 +44,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'core.apps.CoreConfig',
'ddtrace.contrib.django',
'debug_toolbar',
]
MIDDLEWARE = [
......@@ -56,6 +57,7 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'core.middleware.CGUMiddleware',
'core.middleware.MessagesMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware'
]
ROOT_URLCONF = 'nofistv2.urls'
......
......@@ -15,10 +15,19 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
handler404 = 'core.views.handler404'
# handler500=handler404
urlpatterns = [
path('auth/', include('oauth_vr.urls')),
path('admin/', admin.site.urls),
path('', include('core.urls')),
]
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
\ No newline at end of file
- model: core.Course
pk: 1
fields:
name: Test
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 2
fields:
name: Jean
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 3
fields:
name: Ptsdf
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 4
fields:
name: Abdsl
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 5
fields:
name: Asjkbd
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 6
fields:
name: Nourm
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 7
fields:
name: Molusqi
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 8
fields:
name: Noines
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 9
fields:
name: Mokqlk
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 10
fields:
name: Mlodje
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 11
fields:
name: Jeasqmme
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 12
fields:
name: JeNmqlee
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 13
fields:
name: Janslq
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 14
fields:
name: Jeasf
year: 2A
type: 'Tronc commun'
- model: core.Course
pk: 15
fields:
name: Jeasdcf
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 16
fields:
name: Jearoe
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 17
fields:
name: Jambon
year: 1A
type: 'Tronc commun'
- model: core.Course
pk: 18
fields:
name: Jeannot
year: 1A
type: 'Tronc commun'
- model: core.Teacher
pk: 1
fields:
firstName: John
lastName: Cagnol
email: jean@ds.fr
department: Maths
office: maison
......@@ -4,7 +4,7 @@
* Les fichiers seront stockés sous files/accepted pour ceux en ligne, et sous files/toAccept pour ceux en attente d'acceptation
* Structure du fichier core/conf.py :
* client_id
## Table of contents
* [Repository Documentation](#repository-documentation)
* [Labels](#labels)
......@@ -121,7 +121,7 @@ courses: {
* `item` : page name to display differently active menu items
#### `searchbar.html`
> Display a Search Bar. **This feature is not available.**
> Display a Search Bar.
#### `teacher_moderation.html`
> Display a teacher with Accept and Reject buttons for moderation purpose.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment