news active logic depended on activated descriptions
This commit is contained in:
parent
f0585b3ebc
commit
b469770ff0
|
|
@ -248,6 +248,11 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
|||
"""Duplicates for this news item excluding same country code labeled"""
|
||||
return News.objects.filter(duplication_uuid=self.duplication_uuid).exclude(country=self.country)
|
||||
|
||||
@property
|
||||
def has_any_desc_active(self):
|
||||
"""Detects whether news item has any active description"""
|
||||
return any(list(map(lambda v: v.lower() == 'true', self.locale_to_description_is_active.values())))
|
||||
|
||||
@property
|
||||
def is_publish(self):
|
||||
return self.state in self.PUBLISHED_STATES
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ class NewsListView(NewsMixinView, generics.ListAPIView):
|
|||
'international_preferred': True,
|
||||
'locale': locale,
|
||||
})
|
||||
return super().get_queryset(*args, **kwargs)
|
||||
return super().get_queryset(*args, **kwargs)\
|
||||
.filter(locale_to_description_is_active__values__contains=['True'])
|
||||
|
||||
|
||||
class NewsDetailView(NewsMixinView, generics.RetrieveAPIView):
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from django.conf import settings
|
|||
from django_elasticsearch_dsl import Document, Index, fields
|
||||
from search_indexes.utils import OBJECT_FIELD_PROPERTIES
|
||||
from news import models
|
||||
from json import dumps
|
||||
|
||||
|
||||
NewsIndex = Index(settings.ELASTICSEARCH_INDEX_NAMES.get(__name__, 'news'))
|
||||
|
|
@ -17,7 +18,7 @@ class NewsDocument(Document):
|
|||
'name': fields.KeywordField()})
|
||||
title = fields.ObjectField(attr='title_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
slugs = fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES)
|
||||
slugs = fields.KeywordField()
|
||||
backoffice_title = fields.TextField(analyzer='english')
|
||||
subtitle = fields.ObjectField(attr='subtitle_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
|
|
@ -47,7 +48,7 @@ class NewsDocument(Document):
|
|||
start = fields.DateField(attr='start')
|
||||
|
||||
def prepare_slugs(self, instance):
|
||||
return {locale: instance.slugs.get(locale) for locale in OBJECT_FIELD_PROPERTIES}
|
||||
return dumps(instance.slugs or {})
|
||||
|
||||
class Django:
|
||||
|
||||
|
|
@ -58,6 +59,7 @@ class NewsDocument(Document):
|
|||
'state',
|
||||
'is_highlighted',
|
||||
'template',
|
||||
'has_any_desc_active',
|
||||
)
|
||||
related_models = [models.NewsType]
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from news.serializers import NewsTypeSerializer
|
|||
from search_indexes.documents import EstablishmentDocument, NewsDocument
|
||||
from search_indexes.documents.product import ProductDocument
|
||||
from search_indexes.utils import get_translated_value
|
||||
from json import loads
|
||||
|
||||
|
||||
class TagsDocumentSerializer(serializers.Serializer):
|
||||
|
|
@ -243,7 +244,7 @@ class NewsDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
|
||||
@staticmethod
|
||||
def get_slug(obj):
|
||||
return get_translated_value(obj.slugs)
|
||||
return get_translated_value(loads(obj.slugs))
|
||||
|
||||
@staticmethod
|
||||
def get_title_translated(obj):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user