change review transfer
This commit is contained in:
parent
6b83003eac
commit
41c842e224
|
|
@ -61,8 +61,7 @@ class NewsQuerySet(TranslationQuerysetMixin):
|
||||||
return self.order_by('-start')
|
return self.order_by('-start')
|
||||||
|
|
||||||
def rating_value(self):
|
def rating_value(self):
|
||||||
# return self.annotate(rating=models.Count('ratings__ip', distinct=True))
|
return self.annotate(rating=models.Count('ratings__ip', distinct=True))
|
||||||
return self.annotate(rating='views_count__count') # TODO: совместить новый и старый функционал
|
|
||||||
|
|
||||||
def with_base_related(self):
|
def with_base_related(self):
|
||||||
"""Return qs with related objects."""
|
"""Return qs with related objects."""
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ class Review(BaseAttributes, TranslatedFieldsMixin):
|
||||||
related_name='reviews',
|
related_name='reviews',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
verbose_name=_('Reviewer'),
|
verbose_name=_('Reviewer'),
|
||||||
|
null=True, default=None, blank=True
|
||||||
)
|
)
|
||||||
country = models.ForeignKey(
|
country = models.ForeignKey(
|
||||||
'location.Country',
|
'location.Country',
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,8 @@ def transfer_languages():
|
||||||
|
|
||||||
def transfer_reviews():
|
def transfer_reviews():
|
||||||
establishments = Establishment.objects.filter(old_id__isnull=False).values_list('old_id', flat=True)
|
establishments = Establishment.objects.filter(old_id__isnull=False).values_list('old_id', flat=True)
|
||||||
users = User.objects.filter(old_id__isnull=False).values_list('old_id', flat=True)
|
|
||||||
queryset = Reviews.objects.filter(
|
queryset = Reviews.objects.filter(
|
||||||
establishment_id__in=list(establishments),
|
establishment_id__in=list(establishments),
|
||||||
reviewer_id__in=list(users),
|
|
||||||
).values('id', 'reviewer_id', 'aasm_state', 'created_at', 'establishment_id', 'mark', 'vintage')
|
).values('id', 'reviewer_id', 'aasm_state', 'created_at', 'establishment_id', 'mark', 'vintage')
|
||||||
|
|
||||||
serialized_data = ReviewSerializer(data=list(queryset.values()), many=True)
|
serialized_data = ReviewSerializer(data=list(queryset.values()), many=True)
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
from search_indexes.signals import update_document
|
# from search_indexes.signals import update_document
|
||||||
|
|
|
||||||
|
|
@ -1,67 +1,67 @@
|
||||||
"""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']
|
||||||
|
#
|
||||||
app_label_model_name_to_filter = {
|
# app_label_model_name_to_filter = {
|
||||||
('location','country'): 'address__city__country',
|
# ('location','country'): 'address__city__country',
|
||||||
('location','city'): 'address__city',
|
# ('location','city'): 'address__city',
|
||||||
('location', 'address'): 'address',
|
# ('location', 'address'): 'address',
|
||||||
# todo: remove after migration
|
# # todo: remove after migration
|
||||||
('establishment', 'establishmenttype'): 'establishment_type',
|
# ('establishment', 'establishmenttype'): 'establishment_type',
|
||||||
('establishment', 'establishmentsubtype'): 'establishment_subtypes',
|
# ('establishment', 'establishmentsubtype'): 'establishment_subtypes',
|
||||||
('tag', 'tag'): 'tags',
|
# ('tag', 'tag'): 'tags',
|
||||||
}
|
# }
|
||||||
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
# filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||||
if filter_name:
|
# if filter_name:
|
||||||
qs = Establishment.objects.filter(**{filter_name: instance})
|
# qs = Establishment.objects.filter(**{filter_name: instance})
|
||||||
for product in qs:
|
# for product in qs:
|
||||||
registry.update(product)
|
# registry.update(product)
|
||||||
|
#
|
||||||
|
#
|
||||||
@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']
|
||||||
app_label_model_name_to_filter = {
|
# app_label_model_name_to_filter = {
|
||||||
('location','country'): 'country',
|
# ('location','country'): 'country',
|
||||||
('news','newstype'): 'news_type',
|
# ('news','newstype'): 'news_type',
|
||||||
('tag', 'tag'): 'tags',
|
# ('tag', 'tag'): 'tags',
|
||||||
}
|
# }
|
||||||
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
# filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||||
if filter_name:
|
# if filter_name:
|
||||||
qs = News.objects.filter(**{filter_name: instance})
|
# qs = News.objects.filter(**{filter_name: instance})
|
||||||
for product in qs:
|
# for product in qs:
|
||||||
registry.update(product)
|
# registry.update(product)
|
||||||
|
#
|
||||||
|
#
|
||||||
@receiver(post_save)
|
# @receiver(post_save)
|
||||||
def update_product(sender, **kwargs):
|
# def update_product(sender, **kwargs):
|
||||||
from product.models import Product
|
# from product.models import Product
|
||||||
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']
|
||||||
app_label_model_name_to_filter = {
|
# app_label_model_name_to_filter = {
|
||||||
('product','productstandard'): 'standards',
|
# ('product','productstandard'): 'standards',
|
||||||
('product', 'producttype'): 'product_type',
|
# ('product', 'producttype'): 'product_type',
|
||||||
('tag','tag'): 'tags',
|
# ('tag','tag'): 'tags',
|
||||||
('location', 'wineregion'): 'wine_region',
|
# ('location', 'wineregion'): 'wine_region',
|
||||||
('location', 'winesubregion'): 'wine_sub_region',
|
# ('location', 'winesubregion'): 'wine_sub_region',
|
||||||
('location', 'winevillage'): 'wine_village',
|
# ('location', 'winevillage'): 'wine_village',
|
||||||
('establishment', 'establishment'): 'establishment',
|
# ('establishment', 'establishment'): 'establishment',
|
||||||
}
|
# }
|
||||||
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
# filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||||
if filter_name:
|
# if filter_name:
|
||||||
qs = Product.objects.filter(**{filter_name: instance})
|
# qs = Product.objects.filter(**{filter_name: instance})
|
||||||
for product in qs:
|
# for product in qs:
|
||||||
registry.update(product)
|
# registry.update(product)
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,8 @@ class ReviewSerializer(serializers.Serializer):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_reviewer(data):
|
def get_reviewer(data):
|
||||||
|
if data['reviewer_id'] and not data['reviewer_id'] == -1:
|
||||||
user = User.objects.filter(old_id=data['reviewer_id']).first()
|
user = User.objects.filter(old_id=data['reviewer_id']).first()
|
||||||
if not user:
|
|
||||||
raise ValueError(f"User account not found with old_id {data['reviewer_id']}")
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user