Revert "disable ES"

This reverts commit cc9c641
This commit is contained in:
Kuroshini 2020-01-22 21:29:32 +03:00
parent 4a1676abcd
commit 8cc5355200

View File

@ -1,69 +1,69 @@
# """Search indexes app signals."""
# from django.db.models.signals import post_save
# from django.dispatch import receiver
#
#
# @receiver(post_save)
# def update_document(sender, **kwargs):
# from establishment.models import Establishment
# from search_indexes.tasks import es_update
# app_label = sender._meta.app_label
# model_name = sender._meta.model_name
# instance = kwargs['instance']
#
# app_label_model_name_to_filter = {
# ('location', 'country'): 'address__city__country',
# ('location', 'city'): 'address__city',
# ('location', 'address'): 'address',
# # todo: remove after migration
# ('establishment', 'establishmenttype'): 'establishment_type',
# ('establishment', 'establishmentsubtype'): 'establishment_subtypes',
# # ('tag', 'tag'): 'tags',
# }
# filter_name = app_label_model_name_to_filter.get((app_label, model_name))
# if filter_name:
# qs = Establishment.objects.filter(**{filter_name: instance})
# for item in qs:
# es_update(item)
#
#
# @receiver(post_save)
# def update_news(sender, **kwargs):
# from news.models import News
# from search_indexes.tasks import es_update
# app_label = sender._meta.app_label
# model_name = sender._meta.model_name
# instance = kwargs['instance']
# app_label_model_name_to_filter = {
# ('location', 'country'): 'country',
# # ('news', 'newstype'): 'news_type',
# # ('tag', 'tag'): 'tags',
# }
# filter_name = app_label_model_name_to_filter.get((app_label, model_name))
# if filter_name:
# qs = News.objects.filter(**{filter_name: instance})
# for item in qs:
# es_update(item)
#
#
# @receiver(post_save)
# def update_product(sender, **kwargs):
# from product.models import Product
# from search_indexes.tasks import es_update
# app_label = sender._meta.app_label
# model_name = sender._meta.model_name
# instance = kwargs['instance']
# app_label_model_name_to_filter = {
# ('product', 'productstandard'): 'standards',
# ('product', 'producttype'): 'product_type',
# # ('tag', 'tag'): 'tags',
# # ('location', 'wineregion'): 'wine_region',
# # ('location', 'winesubregion'): 'wine_sub_region',
# # ('location', 'winevillage'): 'wine_village',
# ('establishment', 'establishment'): 'establishment',
# }
# filter_name = app_label_model_name_to_filter.get((app_label, model_name))
# if filter_name:
# qs = Product.objects.filter(**{filter_name: instance})
# for product in qs:
# es_update(product)
"""Search indexes app signals."""
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save)
def update_document(sender, **kwargs):
from establishment.models import Establishment
from search_indexes.tasks import es_update
app_label = sender._meta.app_label
model_name = sender._meta.model_name
instance = kwargs['instance']
app_label_model_name_to_filter = {
('location', 'country'): 'address__city__country',
('location', 'city'): 'address__city',
('location', 'address'): 'address',
# todo: remove after migration
('establishment', 'establishmenttype'): 'establishment_type',
('establishment', 'establishmentsubtype'): 'establishment_subtypes',
# ('tag', 'tag'): 'tags',
}
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
if filter_name:
qs = Establishment.objects.filter(**{filter_name: instance})
for item in qs:
es_update(item)
@receiver(post_save)
def update_news(sender, **kwargs):
from news.models import News
from search_indexes.tasks import es_update
app_label = sender._meta.app_label
model_name = sender._meta.model_name
instance = kwargs['instance']
app_label_model_name_to_filter = {
('location', 'country'): 'country',
# ('news', 'newstype'): 'news_type',
# ('tag', 'tag'): 'tags',
}
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
if filter_name:
qs = News.objects.filter(**{filter_name: instance})
for item in qs:
es_update(item)
@receiver(post_save)
def update_product(sender, **kwargs):
from product.models import Product
from search_indexes.tasks import es_update
app_label = sender._meta.app_label
model_name = sender._meta.model_name
instance = kwargs['instance']
app_label_model_name_to_filter = {
('product', 'productstandard'): 'standards',
('product', 'producttype'): 'product_type',
# ('tag', 'tag'): 'tags',
# ('location', 'wineregion'): 'wine_region',
# ('location', 'winesubregion'): 'wine_sub_region',
# ('location', 'winevillage'): 'wine_village',
('establishment', 'establishment'): 'establishment',
}
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
if filter_name:
qs = Product.objects.filter(**{filter_name: instance})
for product in qs:
es_update(product)