Added temporary stub for international news logic (hardcoded news id's)

This commit is contained in:
Semyon Yekhmenin 2019-10-24 12:21:59 +00:00 committed by d.kuzmenko
parent 8c5d59e6bf
commit 2b9c9d14ef
5 changed files with 30 additions and 6 deletions

View File

@ -14,15 +14,25 @@ from utils.permissions import IsCountryAdmin, IsContentPageManager
class NewsMixinView:
"""News mixin."""
permission_classes = (permissions.AllowAny, )
permission_classes = (permissions.AllowAny,)
serializer_class = serializers.NewsBaseSerializer
def get_queryset(self, *args, **kwargs):
from django.conf import settings
"""Override get_queryset method."""
qs = models.News.objects.published().with_base_related()\
qs = models.News.objects.published().with_base_related() \
.order_by('-is_highlighted', '-created')
if self.request.country_code:
qs = qs.by_country_code(self.request.country_code)
return qs
country_code = self.request.country_code
if country_code and country_code != 'www' and country_code != 'main':
return qs.by_country_code(self.request.country_code)
else:
if settings.HARDCODED_INTERNATIONAL_NEWS_IDS:
# Temporary stub for international news logic
# (по договорённости с заказчиком на демонстрации 4 ноября здесь будет 6 фиксированных новостей)
# TODO replace this stub with actual logic
return models.News.objects.filter(id__in=settings.HARDCODED_INTERNATIONAL_NEWS_IDS)
else:
return qs
class NewsListView(NewsMixinView, generics.ListAPIView):

View File

@ -471,4 +471,4 @@ STATICFILES_DIRS = (
# MEDIA
MEDIA_LOCATION = 'media'
MEDIA_LOCATION = 'media'

View File

@ -34,3 +34,7 @@ sentry_sdk.init(
dsn="https://35d9bb789677410ab84a822831c6314f@sentry.io/1729093",
integrations=[DjangoIntegration()]
)
# TMP ( TODO remove it later)
# Временный хардкод для демонстрации 4 ноября, потом удалить!
HARDCODED_INTERNATIONAL_NEWS_IDS = [8, 9, 10, 11, 15, 17]

View File

@ -88,3 +88,8 @@ ELASTICSEARCH_INDEX_NAMES = {
TESTING = sys.argv[1:2] == ['test']
if TESTING:
ELASTICSEARCH_INDEX_NAMES = {}
# TMP ( TODO remove it later)
# Временный хардкод для демонстрации 4 ноября, потом удалить!
HARDCODED_INTERNATIONAL_NEWS_IDS = [8, 9, 10, 11, 15, 17]

View File

@ -26,3 +26,8 @@ ELASTICSEARCH_INDEX_NAMES = {
# 'search_indexes.documents.news': 'stage_news', #temporarily disabled
'search_indexes.documents.establishment': 'stage_establishment',
}
# TMP ( TODO remove it later)
# Временный хардкод для демонстрации 4 ноября, потом удалить!
HARDCODED_INTERNATIONAL_NEWS_IDS = [8, 9, 10, 11, 15, 17]