fix news and paris establishments

This commit is contained in:
alex 2019-10-29 12:34:08 +03:00
parent e68e33859d
commit dc11fb055f
13 changed files with 89 additions and 2 deletions

View File

@ -0,0 +1,13 @@
from django.core.management.base import BaseCommand
from establishment.models import Establishment
class Command(BaseCommand):
help = 'Remove old establishments from new bd'
def handle(self, *args, **kwargs):
old_establishments = Establishment.objects.exclude(old_id__isnull=True)
count = old_establishments.count()
old_establishments.delete()
self.stdout.write(self.style.WARNING(f'Deleted {count} objects.'))

View File

@ -10,7 +10,9 @@ from transfer.serializers.plate import PlateSerializer
def transfer_establishment():
result = []
old_establishments = Establishments.objects.exclude(
old_establishments = Establishments.objects.filter(
location__city__name__icontains='paris',
).exclude(
Q(type='Wineyard') |
Q(location__timezone__isnull=True)
).prefetch_related(
@ -18,6 +20,7 @@ def transfer_establishment():
'schedules_set',
'descriptions_set',
)
for item in old_establishments:
data = {
'old_id': item.id,

View File

@ -28,6 +28,7 @@ class NewsAdmin(admin.ModelAdmin):
"""News admin."""
raw_id_fields = ('address',)
actions = [send_email_action]
raw_id_fields = ('news_type', 'address', 'country')
@admin.register(models.NewsGallery)

View File

View File

@ -0,0 +1,13 @@
from django.core.management.base import BaseCommand
from news.models import News
class Command(BaseCommand):
help = 'Remove all news from new bd'
def handle(self, *args, **kwargs):
old_news = News.objects.all()
count = old_news.count()
old_news.delete()
self.stdout.write(self.style.WARNING(f'Deleted {count} objects.'))

View File

@ -0,0 +1,13 @@
from django.core.management.base import BaseCommand
from news.models import News
class Command(BaseCommand):
help = 'Remove old news from new bd'
def handle(self, *args, **kwargs):
old_news = News.objects.exclude(old_id__isnull=True)
count = old_news.count()
old_news.delete()
self.stdout.write(self.style.WARNING(f'Deleted {count} objects.'))

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2019-10-29 08:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('news', '0029_merge_20191025_0906'),
]
operations = [
migrations.AddField(
model_name='news',
name='old_id',
field=models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='odl id'),
),
]

View File

@ -0,0 +1,14 @@
# Generated by Django 2.2.4 on 2019-10-29 08:58
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('news', '0030_news_old_id'),
('news', '0030_merge_20191028_0725'),
]
operations = [
]

View File

@ -126,6 +126,7 @@ class News(BaseAttributes, TranslatedFieldsMixin):
(PUBLISHED_EXCLUSIVE, _('Published exclusive')),
)
old_id = models.PositiveIntegerField(_('odl id'), blank=True, null=True, default=None)
news_type = models.ForeignKey(NewsType, on_delete=models.PROTECT,
verbose_name=_('news type'))
title = TJSONField(blank=True, null=True, default=None,

View File

@ -12,6 +12,7 @@ def transfer_news():
queryset = PageTexts.objects.filter(page__type="News").annotate(
news_type=Value(news_type.id, output_field=IntegerField()),
country_code=F('page__site__country_code_2'),
)
queryset = queryset.annotate(template=F('page__template'))

View File

@ -751,7 +751,7 @@ class Pages(MigrateMixin):
using = 'legacy'
root_title = models.CharField(max_length=255, blank=True, null=True)
site_id = models.IntegerField()
site = models.ForeignKey(Sites, models.DO_NOTHING, blank=True, null=True)
account_id = models.IntegerField(blank=True, null=True)
state = models.CharField(max_length=255, blank=True, null=True)
template = models.CharField(max_length=255, blank=True, null=True)

View File

@ -1,5 +1,6 @@
from rest_framework import serializers
from location.models import Country
from news.models import News
from utils.legacy_parser import parse_legacy_news_content
from utils.slug_generator import generate_unique_slug
@ -12,11 +13,13 @@ class NewsSerializer(serializers.ModelSerializer):
title = serializers.CharField()
template = serializers.CharField()
state = serializers.CharField()
country_code = serializers.CharField(allow_null=True)
created_at = serializers.DateTimeField(source='start', format='%m-%d-%Y %H:%M:%S')
class Meta:
model = News
fields = (
'old_id',
'created_at',
'state',
'template',
@ -25,6 +28,7 @@ class NewsSerializer(serializers.ModelSerializer):
'slug',
'news_type',
'locale',
'country_code',
)
def validate(self, data):
@ -34,7 +38,9 @@ class NewsSerializer(serializers.ModelSerializer):
'template': self.get_template(data),
'title': self.get_title(data),
'description': self.get_description(data),
'country': self.get_country(data),
})
data.pop('country_code')
data.pop('body')
data.pop('locale')
return data
@ -42,6 +48,10 @@ class NewsSerializer(serializers.ModelSerializer):
def create(self, validated_data):
return News.objects.create(**validated_data)
@staticmethod
def get_country(data):
return Country.objects.filter(code__iexact=data['country_code']).first()
@staticmethod
def get_template(data):
templates = {