ES as separate server

This commit is contained in:
Kuroshini 2019-11-18 20:12:58 +03:00
parent c7033d4b10
commit 5c4c4c60c3
8 changed files with 41 additions and 14 deletions

View File

@ -22,11 +22,10 @@ from django.core.validators import MinValueValidator, MaxValueValidator
from collection.models import Collection
from location.models import Address
from main.models import Award, Currency
from tag.models import TagCategory
from review.models import Review
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
TranslatedFieldsMixin, BaseAttributes, GalleryModelMixin,
IntermediateGalleryModelMixin)
IntermediateGalleryModelMixin, HasTagsMixin)
# todo: establishment type&subtypes check
@ -320,7 +319,7 @@ class EstablishmentQuerySet(models.QuerySet):
return self.exclude(address__city__country__in=countries)
class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin, HasTagsMixin):
"""Establishment model."""
# todo: delete image URL fields after moving on gallery
@ -418,9 +417,9 @@ class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, Translat
@property
def visible_tags(self):
return self.tags.exclude(category__value_type=TagCategory.BOOLEAN)\
return super().visible_tags\
.exclude(category__index_name__in=['guide', 'collection', 'purchased_item',
'business_tag', 'business_tags_de'])
'business_tag', 'business_tags_de'])\
# todo: recalculate toque_number
def recalculate_toque_number(self):

View File

@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
from rest_framework.reverse import reverse
from rating.models import Rating, ViewCount
from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin,
from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin, HasTagsMixin,
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin)
from utils.querysets import TranslationQuerysetMixin
from django.conf import settings
@ -126,7 +126,7 @@ class NewsQuerySet(TranslationQuerysetMixin):
)
class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin):
class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixin):
"""News model."""
STR_FIELD_NAME = 'title'

View File

@ -64,7 +64,7 @@ class NewsBaseSerializer(ProjectModelSerializer):
title_translated = TranslatedField()
subtitle_translated = TranslatedField()
news_type = NewsTypeSerializer(read_only=True)
tags = TagBaseSerializer(read_only=True, many=True)
tags = TagBaseSerializer(read_only=True, many=True, source='related_tags')
in_favorites = serializers.BooleanField(allow_null=True)
view_counter = serializers.IntegerField(read_only=True)

View File

@ -7,7 +7,7 @@ from django.db.models import Case, When
from django.utils.translation import gettext_lazy as _
from django.core.validators import MaxValueValidator, MinValueValidator
from utils.models import (BaseAttributes, ProjectBaseMixin,
from utils.models import (BaseAttributes, ProjectBaseMixin, HasTagsMixin,
TranslatedFieldsMixin, TJSONField,
GalleryModelMixin, IntermediateGalleryModelMixin)
@ -131,7 +131,7 @@ class ProductQuerySet(models.QuerySet):
)
class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes):
class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes, HasTagsMixin):
"""Product models."""
EARLIEST_VINTAGE_YEAR = 1700
@ -256,8 +256,8 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes):
@property
def related_tags(self):
return self.tags.exclude(category__index_name__in=['sugar-content', 'wine-color', 'bottles-produced',
'serial-number', 'grape-variety']).prefetch_related('category')
return super().visible_tags.exclude(category__index_name__in=['sugar-content', 'wine-color',
'bottles-produced','serial-number', 'grape-variety'])
@property
def display_name(self):

View File

@ -34,6 +34,13 @@ class NewsDocument(Document):
'value': fields.KeywordField()
},
multi=True)
visible_tags = fields.ObjectField(
properties={
'id': fields.IntegerField(attr='id'),
'label': fields.ObjectField(attr='label_indexing',
properties=OBJECT_FIELD_PROPERTIES),
},
multi=True)
class Django:

View File

@ -107,6 +107,14 @@ class ProductDocument(Document):
},
multi=True
)
related_tags = fields.ObjectField(
properties={
'id': fields.IntegerField(),
'label': fields.ObjectField(attr='label_indexing', properties=OBJECT_FIELD_PROPERTIES),
'value': fields.KeywordField(),
},
multi=True
)
name = fields.TextField(attr='display_name', analyzer='english')
name_ru = fields.TextField(attr='display_name', analyzer='russian')
name_fr = fields.TextField(attr='display_name', analyzer='french')

View File

@ -148,7 +148,7 @@ class NewsDocumentSerializer(DocumentSerializer):
title_translated = serializers.SerializerMethodField(allow_null=True)
subtitle_translated = serializers.SerializerMethodField(allow_null=True)
news_type = NewsTypeSerializer()
tags = TagsDocumentSerializer(many=True)
tags = TagsDocumentSerializer(many=True, source='visible_tags')
class Meta:
"""Meta class."""
@ -214,7 +214,7 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
class ProductDocumentSerializer(DocumentSerializer):
"""Product document serializer"""
tags = TagsDocumentSerializer(many=True)
tags = TagsDocumentSerializer(many=True, source='related_tags')
subtypes = ProductSubtypeDocumentSerializer(many=True, allow_null=True)
wine_region = WineRegionDocumentSerializer(allow_null=True)
wine_colors = TagDocumentSerializer(many=True)

View File

@ -418,4 +418,17 @@ class IntermediateGalleryModelMixin(models.Model):
return self.image.title if self.image.title else self.id
class HasTagsMixin(models.Model):
"""Mixin for filtering tags"""
@property
def visible_tags(self):
return self.tags.filter(category__public=True).prefetch_related('category')\
.exclude(category__value_type='bool')
class Meta:
"""Meta class."""
abstract = True
timezone.datetime.now().date().isoformat()