International news
This commit is contained in:
parent
90fad60fc6
commit
153ccd7bd9
|
|
@ -86,6 +86,10 @@ class NewsQuerySet(TranslationQuerysetMixin):
|
|||
"""Returns news with tag 'cook' qs."""
|
||||
return self.filter(tags__value=News.RECIPES_TAG_VALUE)
|
||||
|
||||
def international_news(self):
|
||||
"""Returns only international news qs."""
|
||||
return self.filter(tags__value=News.INTERNATIONAL_TAG_VALUE)
|
||||
|
||||
def published(self):
|
||||
"""Return only published news"""
|
||||
now = timezone.now()
|
||||
|
|
@ -151,6 +155,7 @@ class News(BaseAttributes, TranslatedFieldsMixin):
|
|||
(PUBLISHED_EXCLUSIVE, _('Published exclusive')),
|
||||
)
|
||||
|
||||
INTERNATIONAL_TAG_VALUE = 'international'
|
||||
RECIPES_TAG_VALUE = 'cook'
|
||||
|
||||
old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class NewsMixinView:
|
|||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.NewsBaseSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
"""Override get_queryset method."""
|
||||
qs = models.News.objects.published() \
|
||||
.with_base_related() \
|
||||
|
|
@ -27,7 +27,10 @@ class NewsMixinView:
|
|||
|
||||
country_code = self.request.country_code
|
||||
if country_code:
|
||||
qs = qs.by_country_code(country_code)
|
||||
if kwargs.get('international_preferred') and country_code in settings.INTERNATIONAL_COUNTRY_CODES:
|
||||
qs = qs.international_news()
|
||||
else:
|
||||
qs = qs.by_country_code(country_code)
|
||||
return qs
|
||||
|
||||
|
||||
|
|
@ -37,6 +40,10 @@ class NewsListView(NewsMixinView, generics.ListAPIView):
|
|||
serializer_class = serializers.NewsListSerializer
|
||||
filter_class = filters.NewsListFilterSet
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
kwargs.update({'international_preferred': True})
|
||||
return super().get_queryset(*args, **kwargs)
|
||||
|
||||
|
||||
class NewsDetailView(NewsMixinView, generics.RetrieveAPIView):
|
||||
"""News detail view."""
|
||||
|
|
|
|||
|
|
@ -493,3 +493,4 @@ FALLBACK_LOCALE = 'en-GB'
|
|||
CAROUSEL_ITEMS = [230, 231, 232]
|
||||
ESTABLISHMENT_CHOSEN_TAGS = ['gastronomic', 'en_vogue', 'terrace', 'streetfood', 'business', 'bar_cocktail', 'brunch', 'pop']
|
||||
NEWS_CHOSEN_TAGS = ['eat', 'drink', 'cook', 'style', 'international', 'event', 'partnership']
|
||||
INTERNATIONAL_COUNTRY_CODES = ['www', 'main', 'next']
|
||||
Loading…
Reference in New Issue
Block a user