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."""
|
"""News app models."""
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes import fields as generic
|
from django.contrib.contenttypes import fields as generic
|
||||||
|
from django.contrib.postgres.fields import HStoreField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Case, When
|
from django.db.models import Case, When
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
@ -11,8 +15,6 @@ from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin, Has
|
||||||
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin,
|
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin,
|
||||||
FavoritesMixin)
|
FavoritesMixin)
|
||||||
from utils.querysets import TranslationQuerysetMixin
|
from utils.querysets import TranslationQuerysetMixin
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.postgres.fields import HStoreField
|
|
||||||
|
|
||||||
|
|
||||||
class Agenda(ProjectBaseMixin, TranslatedFieldsMixin):
|
class Agenda(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
|
|
@ -177,11 +179,14 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
||||||
description = TJSONField(blank=True, null=True, default=None,
|
description = TJSONField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('description'),
|
verbose_name=_('description'),
|
||||||
help_text='{"en-GB":"some text"}')
|
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,
|
start = models.DateTimeField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('Start'))
|
verbose_name=_('Start'))
|
||||||
end = models.DateTimeField(blank=True, null=True, default=None,
|
end = models.DateTimeField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('End'))
|
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'),
|
verbose_name=_('Slugs for current news obj'),
|
||||||
help_text='{"en-GB":"some slug"}')
|
help_text='{"en-GB":"some slug"}')
|
||||||
state = models.PositiveSmallIntegerField(default=WAITING, choices=STATE_CHOICES,
|
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'))
|
on_delete=models.SET_NULL, verbose_name=_('site settings'))
|
||||||
duplication_date = models.DateTimeField(blank=True, null=True, default=None,
|
duplication_date = models.DateTimeField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('Duplication datetime'))
|
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()
|
objects = NewsQuerySet.as_manager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -233,6 +240,12 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
||||||
self.duplication_date = timezone.now()
|
self.duplication_date = timezone.now()
|
||||||
self.save()
|
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
|
@property
|
||||||
def is_publish(self):
|
def is_publish(self):
|
||||||
return self.state in self.PUBLISHED_STATES
|
return self.state in self.PUBLISHED_STATES
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,20 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
||||||
return super().update(instance, validated_data)
|
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,
|
class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
||||||
NewsDetailSerializer):
|
NewsDetailSerializer):
|
||||||
"""News detail serializer for back-office users."""
|
"""News detail serializer for back-office users."""
|
||||||
|
|
@ -224,6 +238,7 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
||||||
queryset=SiteSettings.objects.all())
|
queryset=SiteSettings.objects.all())
|
||||||
template_display = serializers.CharField(source='get_template_display',
|
template_display = serializers.CharField(source='get_template_display',
|
||||||
read_only=True)
|
read_only=True)
|
||||||
|
duplicates = NewsBackOfficeDuplicationInfoSerializer(many=True, allow_null=True, read_only=True)
|
||||||
|
|
||||||
class Meta(NewsBackOfficeBaseSerializer.Meta, NewsDetailSerializer.Meta):
|
class Meta(NewsBackOfficeBaseSerializer.Meta, NewsDetailSerializer.Meta):
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -237,6 +252,7 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
||||||
'template',
|
'template',
|
||||||
'template_display',
|
'template_display',
|
||||||
'is_international',
|
'is_international',
|
||||||
|
'duplicates',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user