Fix off elastic

This commit is contained in:
Виктор Гладких 2019-11-13 12:12:16 +03:00
parent 9fcaa6747a
commit cb127ef879
3 changed files with 81 additions and 81 deletions

View File

@ -1 +1 @@
from search_indexes.signals import update_document # from search_indexes.signals import update_document

View File

@ -1,77 +1,77 @@
"""Search indexes app signals.""" # """Search indexes app signals."""
from django.db.models.signals import post_save # from django.db.models.signals import post_save
from django.dispatch import receiver # from django.dispatch import receiver
from django_elasticsearch_dsl.registries import registry # from django_elasticsearch_dsl.registries import registry
#
#
@receiver(post_save) # @receiver(post_save)
def update_document(sender, **kwargs): # def update_document(sender, **kwargs):
from establishment.models import Establishment # from establishment.models import Establishment
app_label = sender._meta.app_label # app_label = sender._meta.app_label
model_name = sender._meta.model_name # model_name = sender._meta.model_name
instance = kwargs['instance'] # instance = kwargs['instance']
#
if app_label == 'location': # if app_label == 'location':
if model_name == 'country': # if model_name == 'country':
establishments = Establishment.objects.filter( # establishments = Establishment.objects.filter(
address__city__country=instance) # address__city__country=instance)
for establishment in establishments: # for establishment in establishments:
registry.update(establishment) # registry.update(establishment)
if model_name == 'city': # if model_name == 'city':
establishments = Establishment.objects.filter( # establishments = Establishment.objects.filter(
address__city=instance) # address__city=instance)
for establishment in establishments: # for establishment in establishments:
registry.update(establishment) # registry.update(establishment)
if model_name == 'address': # if model_name == 'address':
establishments = Establishment.objects.filter( # establishments = Establishment.objects.filter(
address=instance) # address=instance)
for establishment in establishments: # for establishment in establishments:
registry.update(establishment) # registry.update(establishment)
#
if app_label == 'establishment': # if app_label == 'establishment':
# todo: remove after migration # # todo: remove after migration
from establishment import models as establishment_models # from establishment import models as establishment_models
if model_name == 'establishmenttype': # if model_name == 'establishmenttype':
if isinstance(instance, establishment_models.EstablishmentType): # if isinstance(instance, establishment_models.EstablishmentType):
establishments = Establishment.objects.filter( # establishments = Establishment.objects.filter(
establishment_type=instance) # establishment_type=instance)
for establishment in establishments: # for establishment in establishments:
registry.update(establishment) # registry.update(establishment)
if model_name == 'establishmentsubtype': # if model_name == 'establishmentsubtype':
if isinstance(instance, establishment_models.EstablishmentSubType): # if isinstance(instance, establishment_models.EstablishmentSubType):
establishments = Establishment.objects.filter( # establishments = Establishment.objects.filter(
establishment_subtypes=instance) # establishment_subtypes=instance)
for establishment in establishments: # for establishment in establishments:
registry.update(establishment) # registry.update(establishment)
#
if app_label == 'tag': # if app_label == 'tag':
if model_name == 'tag': # if model_name == 'tag':
establishments = Establishment.objects.filter(tags=instance) # establishments = Establishment.objects.filter(tags=instance)
for establishment in establishments: # for establishment in establishments:
registry.update(establishment) # registry.update(establishment)
#
#
@receiver(post_save) # @receiver(post_save)
def update_news(sender, **kwargs): # def update_news(sender, **kwargs):
from news.models import News # from news.models import News
app_label = sender._meta.app_label # app_label = sender._meta.app_label
model_name = sender._meta.model_name # model_name = sender._meta.model_name
instance = kwargs['instance'] # instance = kwargs['instance']
#
if app_label == 'location': # if app_label == 'location':
if model_name == 'country': # if model_name == 'country':
qs = News.objects.filter(country=instance) # qs = News.objects.filter(country=instance)
for news in qs: # for news in qs:
registry.update(news) # registry.update(news)
#
if app_label == 'news': # if app_label == 'news':
if model_name == 'newstype': # if model_name == 'newstype':
qs = News.objects.filter(news_type=instance) # qs = News.objects.filter(news_type=instance)
for news in qs: # for news in qs:
registry.update(news) # registry.update(news)
#
if app_label == 'tag': # if app_label == 'tag':
if model_name == 'tag': # if model_name == 'tag':
qs = News.objects.filter(tags=instance) # qs = News.objects.filter(tags=instance)
for news in qs: # for news in qs:
registry.update(news) # registry.update(news)

View File

@ -66,7 +66,7 @@ PROJECT_APPS = [
'partner.apps.PartnerConfig', 'partner.apps.PartnerConfig',
'product.apps.ProductConfig', 'product.apps.ProductConfig',
'recipe.apps.RecipeConfig', 'recipe.apps.RecipeConfig',
'search_indexes.apps.SearchIndexesConfig', # 'search_indexes.apps.SearchIndexesConfig',
'translation.apps.TranslationConfig', 'translation.apps.TranslationConfig',
'configuration.apps.ConfigurationConfig', 'configuration.apps.ConfigurationConfig',
'timetable.apps.TimetableConfig', 'timetable.apps.TimetableConfig',
@ -79,8 +79,8 @@ PROJECT_APPS = [
EXTERNAL_APPS = [ EXTERNAL_APPS = [
'corsheaders', 'corsheaders',
'django_elasticsearch_dsl', # 'django_elasticsearch_dsl',
'django_elasticsearch_dsl_drf', # 'django_elasticsearch_dsl_drf',
'django_filters', 'django_filters',
'drf_yasg', 'drf_yasg',
'fcm_django', 'fcm_django',