diff --git a/README.md b/README.md index 5ceba83..9440a7e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,24 @@ Vous pouvez alors lancez le serveur de développement python manage.py runserver +## Configuration de la recherche + +Il faut installer elasticsearch 5.*. C'est compliqué. Mais en suivant https://www.elastic.co/guide/en/elasticsearch/reference/5.4/deb.html ça va. + + wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - + sudo apt-get install apt-transport-https + echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list + sudo apt-get update && sudo apt-get install elasticsearch + + sudo systemctl daemon-reload + sudo systemctl enable elasticsearch.service + sudo systemctl start elasticsearch.service + +Et puis, de retour dans le virtualenv python + + python manage.py search_index --rebuild + +Si des erreurs s'affichent, il y a une cachuète dans le beurre. ## Changer le CSS diff --git a/avisstage/documents.py b/avisstage/documents.py new file mode 100644 index 0000000..75a0aaf --- /dev/null +++ b/avisstage/documents.py @@ -0,0 +1,39 @@ +from django_elasticsearch_dsl import DocType, Index, fields +from .models import Stage, AvisStage, AvisLieu + +stage = Index('stages') +stage.settings( + number_of_shards=1, + number_of_replicas=0 +) + +@stage.doc_type +class StageDocument(DocType): + lieux = fields.ObjectField(properties={ + 'nom': fields.StringField(), + 'pays': fields.StringField(), + }) + thematiques = fields.StringField() + matieres = fields.StringField() + + class Meta: + model = Stage + fields = [ + 'sujet', + 'encadrants', + 'type_stage', + 'niveau_scol', + 'structure' + ] + + def prepare_thematiques(self, instance): + return ", ".join(instance.thematiques.all().values_list("slug", flat=True)) + + def prepare_matieres(self, instance): + return ", ".join(instance.matieres.all().values_list("slug", flat=True)) + + def prepare_niveau_scol(self, instance): + return instance.get_niveau_scol_display() + + def prepare_type_stage(self, instance): + return instance.type_stage_fancy diff --git a/experiENS/settings_base.py b/experiENS/settings_base.py index cac52f3..40b0332 100644 --- a/experiENS/settings_base.py +++ b/experiENS/settings_base.py @@ -30,6 +30,8 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'django.contrib.gis', + 'django_elasticsearch_dsl', + 'tastypie', 'django_cas_ng', 'braces', diff --git a/experiENS/settings_dev.py b/experiENS/settings_dev.py index 7200a82..4c894ce 100644 --- a/experiENS/settings_dev.py +++ b/experiENS/settings_dev.py @@ -26,3 +26,9 @@ STATIC_ROOT = "/home/evarin/Bureau/experiENS/static/" EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' STATIC_URL = "/experiens/static/" + +ELASTICSEARCH_DSL = { + 'default': { + 'hosts': 'localhost:9200' + }, +} diff --git a/requirements.txt b/requirements.txt index 145279f..f52c4b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ django-taggit-autosuggest pytz django-tastypie lxml +git+https://github.com/sabricot/django-elasticsearch-dsl