news duplication info
This commit is contained in:
parent
c456e43f80
commit
0a25ec3e7c
37
apps/news/migrations/0043_auto_20191216_1920.py
Normal file
37
apps/news/migrations/0043_auto_20191216_1920.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-16 19:20
|
||||
|
||||
import django.contrib.postgres.fields.hstore
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
def fill_uuid(apps, schemaeditor):
|
||||
News = apps.get_model('news', 'News')
|
||||
for news in News.objects.all():
|
||||
news.duplication_uuid = uuid.uuid4()
|
||||
news.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('news', '0042_news_duplication_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='news',
|
||||
name='description_to_locale_is_active',
|
||||
field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, default=dict, help_text='{"en-GB": true, "fr-FR": false}', null=True, verbose_name='Is description for certain locale active'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='news',
|
||||
name='duplication_uuid',
|
||||
field=models.UUIDField(default=uuid.uuid4, verbose_name='Field to detect doubles'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='news',
|
||||
name='slugs',
|
||||
field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, default=dict, help_text='{"en-GB":"some slug"}', null=True, verbose_name='Slugs for current news obj'),
|
||||
),
|
||||
migrations.RunPython(fill_uuid, migrations.RunPython.noop),
|
||||
]
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
"""News app models."""
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes import fields as generic
|
||||
from django.contrib.postgres.fields import HStoreField
|
||||
from django.db import models
|
||||
from django.db.models import Case, When
|
||||
from django.utils import timezone
|
||||
|
|
@ -11,8 +15,6 @@ from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin, Has
|
|||
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin,
|
||||
FavoritesMixin)
|
||||
from utils.querysets import TranslationQuerysetMixin
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.fields import HStoreField
|
||||
|
||||
|
||||
class Agenda(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||
|
|
@ -177,11 +179,14 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
|||
description = TJSONField(blank=True, null=True, default=None,
|
||||
verbose_name=_('description'),
|
||||
help_text='{"en-GB":"some text"}')
|
||||
description_to_locale_is_active = HStoreField(null=True, default=dict, blank=True,
|
||||
verbose_name=_('Is description for certain locale active'),
|
||||
help_text='{"en-GB": true, "fr-FR": false}')
|
||||
start = models.DateTimeField(blank=True, null=True, default=None,
|
||||
verbose_name=_('Start'))
|
||||
end = models.DateTimeField(blank=True, null=True, default=None,
|
||||
verbose_name=_('End'))
|
||||
slugs = HStoreField(null=True, blank=True, default=None,
|
||||
slugs = HStoreField(null=True, blank=True, default=dict,
|
||||
verbose_name=_('Slugs for current news obj'),
|
||||
help_text='{"en-GB":"some slug"}')
|
||||
state = models.PositiveSmallIntegerField(default=WAITING, choices=STATE_CHOICES,
|
||||
|
|
@ -213,6 +218,8 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
|||
on_delete=models.SET_NULL, verbose_name=_('site settings'))
|
||||
duplication_date = models.DateTimeField(blank=True, null=True, default=None,
|
||||
verbose_name=_('Duplication datetime'))
|
||||
duplication_uuid = models.UUIDField(default=uuid.uuid4, editable=True, unique=False,
|
||||
verbose_name=_('Field to detect doubles'))
|
||||
objects = NewsQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
|
|
@ -233,6 +240,12 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
|||
self.duplication_date = timezone.now()
|
||||
self.save()
|
||||
|
||||
|
||||
@property
|
||||
def duplicates(self):
|
||||
"""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 is_publish(self):
|
||||
return self.state in self.PUBLISHED_STATES
|
||||
|
|
|
|||
|
|
@ -209,6 +209,20 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
class NewsBackOfficeDuplicationInfoSerializer(serializers.ModelSerializer):
|
||||
"""Duplication info for news detail."""
|
||||
|
||||
country = CountrySimpleSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = models.News
|
||||
fields = (
|
||||
'id',
|
||||
'duplication_date',
|
||||
'country',
|
||||
)
|
||||
|
||||
|
||||
class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
||||
NewsDetailSerializer):
|
||||
"""News detail serializer for back-office users."""
|
||||
|
|
@ -224,6 +238,7 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
|||
queryset=SiteSettings.objects.all())
|
||||
template_display = serializers.CharField(source='get_template_display',
|
||||
read_only=True)
|
||||
duplicates = NewsBackOfficeDuplicationInfoSerializer(many=True, allow_null=True, read_only=True)
|
||||
|
||||
class Meta(NewsBackOfficeBaseSerializer.Meta, NewsDetailSerializer.Meta):
|
||||
"""Meta class."""
|
||||
|
|
@ -237,6 +252,7 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
|||
'template',
|
||||
'template_display',
|
||||
'is_international',
|
||||
'duplicates',
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user