ES as separate server
This commit is contained in:
parent
c7033d4b10
commit
5c4c4c60c3
|
|
@ -22,11 +22,10 @@ from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from collection.models import Collection
|
from collection.models import Collection
|
||||||
from location.models import Address
|
from location.models import Address
|
||||||
from main.models import Award, Currency
|
from main.models import Award, Currency
|
||||||
from tag.models import TagCategory
|
|
||||||
from review.models import Review
|
from review.models import Review
|
||||||
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
||||||
TranslatedFieldsMixin, BaseAttributes, GalleryModelMixin,
|
TranslatedFieldsMixin, BaseAttributes, GalleryModelMixin,
|
||||||
IntermediateGalleryModelMixin)
|
IntermediateGalleryModelMixin, HasTagsMixin)
|
||||||
|
|
||||||
|
|
||||||
# todo: establishment type&subtypes check
|
# todo: establishment type&subtypes check
|
||||||
|
|
@ -320,7 +319,7 @@ class EstablishmentQuerySet(models.QuerySet):
|
||||||
return self.exclude(address__city__country__in=countries)
|
return self.exclude(address__city__country__in=countries)
|
||||||
|
|
||||||
|
|
||||||
class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin, HasTagsMixin):
|
||||||
"""Establishment model."""
|
"""Establishment model."""
|
||||||
|
|
||||||
# todo: delete image URL fields after moving on gallery
|
# todo: delete image URL fields after moving on gallery
|
||||||
|
|
@ -418,9 +417,9 @@ class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, Translat
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def visible_tags(self):
|
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',
|
.exclude(category__index_name__in=['guide', 'collection', 'purchased_item',
|
||||||
'business_tag', 'business_tags_de'])
|
'business_tag', 'business_tags_de'])\
|
||||||
|
|
||||||
# todo: recalculate toque_number
|
# todo: recalculate toque_number
|
||||||
def recalculate_toque_number(self):
|
def recalculate_toque_number(self):
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
|
|
||||||
from rating.models import Rating, ViewCount
|
from rating.models import Rating, ViewCount
|
||||||
from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin,
|
from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin, HasTagsMixin,
|
||||||
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin)
|
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin)
|
||||||
from utils.querysets import TranslationQuerysetMixin
|
from utils.querysets import TranslationQuerysetMixin
|
||||||
from django.conf import settings
|
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."""
|
"""News model."""
|
||||||
|
|
||||||
STR_FIELD_NAME = 'title'
|
STR_FIELD_NAME = 'title'
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class NewsBaseSerializer(ProjectModelSerializer):
|
||||||
title_translated = TranslatedField()
|
title_translated = TranslatedField()
|
||||||
subtitle_translated = TranslatedField()
|
subtitle_translated = TranslatedField()
|
||||||
news_type = NewsTypeSerializer(read_only=True)
|
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)
|
in_favorites = serializers.BooleanField(allow_null=True)
|
||||||
view_counter = serializers.IntegerField(read_only=True)
|
view_counter = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from django.db.models import Case, When
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
|
||||||
from utils.models import (BaseAttributes, ProjectBaseMixin,
|
from utils.models import (BaseAttributes, ProjectBaseMixin, HasTagsMixin,
|
||||||
TranslatedFieldsMixin, TJSONField,
|
TranslatedFieldsMixin, TJSONField,
|
||||||
GalleryModelMixin, IntermediateGalleryModelMixin)
|
GalleryModelMixin, IntermediateGalleryModelMixin)
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ class ProductQuerySet(models.QuerySet):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes):
|
class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes, HasTagsMixin):
|
||||||
"""Product models."""
|
"""Product models."""
|
||||||
|
|
||||||
EARLIEST_VINTAGE_YEAR = 1700
|
EARLIEST_VINTAGE_YEAR = 1700
|
||||||
|
|
@ -256,8 +256,8 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def related_tags(self):
|
def related_tags(self):
|
||||||
return self.tags.exclude(category__index_name__in=['sugar-content', 'wine-color', 'bottles-produced',
|
return super().visible_tags.exclude(category__index_name__in=['sugar-content', 'wine-color',
|
||||||
'serial-number', 'grape-variety']).prefetch_related('category')
|
'bottles-produced','serial-number', 'grape-variety'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def display_name(self):
|
def display_name(self):
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,13 @@ class NewsDocument(Document):
|
||||||
'value': fields.KeywordField()
|
'value': fields.KeywordField()
|
||||||
},
|
},
|
||||||
multi=True)
|
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:
|
class Django:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,14 @@ class ProductDocument(Document):
|
||||||
},
|
},
|
||||||
multi=True
|
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 = fields.TextField(attr='display_name', analyzer='english')
|
||||||
name_ru = fields.TextField(attr='display_name', analyzer='russian')
|
name_ru = fields.TextField(attr='display_name', analyzer='russian')
|
||||||
name_fr = fields.TextField(attr='display_name', analyzer='french')
|
name_fr = fields.TextField(attr='display_name', analyzer='french')
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ class NewsDocumentSerializer(DocumentSerializer):
|
||||||
title_translated = serializers.SerializerMethodField(allow_null=True)
|
title_translated = serializers.SerializerMethodField(allow_null=True)
|
||||||
subtitle_translated = serializers.SerializerMethodField(allow_null=True)
|
subtitle_translated = serializers.SerializerMethodField(allow_null=True)
|
||||||
news_type = NewsTypeSerializer()
|
news_type = NewsTypeSerializer()
|
||||||
tags = TagsDocumentSerializer(many=True)
|
tags = TagsDocumentSerializer(many=True, source='visible_tags')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -214,7 +214,7 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
|
||||||
class ProductDocumentSerializer(DocumentSerializer):
|
class ProductDocumentSerializer(DocumentSerializer):
|
||||||
"""Product document serializer"""
|
"""Product document serializer"""
|
||||||
|
|
||||||
tags = TagsDocumentSerializer(many=True)
|
tags = TagsDocumentSerializer(many=True, source='related_tags')
|
||||||
subtypes = ProductSubtypeDocumentSerializer(many=True, allow_null=True)
|
subtypes = ProductSubtypeDocumentSerializer(many=True, allow_null=True)
|
||||||
wine_region = WineRegionDocumentSerializer(allow_null=True)
|
wine_region = WineRegionDocumentSerializer(allow_null=True)
|
||||||
wine_colors = TagDocumentSerializer(many=True)
|
wine_colors = TagDocumentSerializer(many=True)
|
||||||
|
|
|
||||||
|
|
@ -418,4 +418,17 @@ class IntermediateGalleryModelMixin(models.Model):
|
||||||
return self.image.title if self.image.title else self.id
|
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()
|
timezone.datetime.now().date().isoformat()
|
||||||
Loading…
Reference in New Issue
Block a user