Merge branch 'maigrate-carousel' into develop
This commit is contained in:
commit
4be8582e7c
48
apps/main/migrations/0024_auto_20191031_1439.py
Normal file
48
apps/main/migrations/0024_auto_20191031_1439.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Generated by Django 2.2.4 on 2019-10-31 14:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0023_merge_20191028_0725'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='active',
|
||||
field=models.BooleanField(default=False, verbose_name='old active'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='attachment_suffix_url',
|
||||
field=models.TextField(blank=True, default=None, null=True, verbose_name='old attachment_suffix_url'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='description',
|
||||
field=models.CharField(blank=True, default=None, max_length=255, null=True, verbose_name='old description'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='link',
|
||||
field=models.CharField(blank=True, default=None, max_length=255, null=True, verbose_name='old link'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='link_title',
|
||||
field=models.CharField(blank=True, default=None, max_length=255, null=True, verbose_name='old link_title'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='old_id',
|
||||
field=models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='old id'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='title',
|
||||
field=models.CharField(blank=True, default=None, max_length=255, null=True, verbose_name='old title'),
|
||||
),
|
||||
]
|
||||
18
apps/main/migrations/0025_carousel_is_parse.py
Normal file
18
apps/main/migrations/0025_carousel_is_parse.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2019-10-31 15:30
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0024_auto_20191031_1439'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='carousel',
|
||||
name='is_parse',
|
||||
field=models.BooleanField(default=False, verbose_name='is parse'),
|
||||
),
|
||||
]
|
||||
24
apps/main/migrations/0026_auto_20191101_0500.py
Normal file
24
apps/main/migrations/0026_auto_20191101_0500.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-01 05:00
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0025_carousel_is_parse'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='carousel',
|
||||
name='content_type',
|
||||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='carousel',
|
||||
name='object_id',
|
||||
field=models.PositiveIntegerField(blank=True, default=None, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -130,7 +130,6 @@ class SiteSettingsQuerySet(models.QuerySet):
|
|||
|
||||
|
||||
class SiteSettings(ProjectBaseMixin):
|
||||
|
||||
subdomain = models.CharField(max_length=255, db_index=True, unique=True,
|
||||
verbose_name=_('Subdomain'))
|
||||
country = models.OneToOneField(Country, on_delete=models.PROTECT,
|
||||
|
|
@ -282,10 +281,19 @@ class CarouselQuerySet(models.QuerySet):
|
|||
|
||||
class Carousel(models.Model):
|
||||
"""Carousel model."""
|
||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True, default=None)
|
||||
object_id = models.PositiveIntegerField(blank=True, null=True, default=None)
|
||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||
|
||||
old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
|
||||
title = models.CharField(_('old title'), max_length=255, blank=True, null=True, default=None)
|
||||
link = models.CharField(_('old link'), max_length=255, blank=True, null=True, default=None)
|
||||
attachment_suffix_url = models.TextField(_('old attachment_suffix_url'), blank=True, null=True, default=None)
|
||||
description = models.CharField(_('old description'), max_length=255, blank=True, null=True, default=None)
|
||||
link_title = models.CharField(_('old link_title'), max_length=255, blank=True, null=True, default=None)
|
||||
active = models.BooleanField(_('old active'), default=False)
|
||||
is_parse = models.BooleanField(_('is parse'), default=False)
|
||||
|
||||
objects = CarouselQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ card = {
|
|||
"facebook_page_url": "facebook_page_url",
|
||||
"instagram_page_url": "instagram_page_url",
|
||||
"contact_email": "contact_email",
|
||||
"config": ("config", "django.db.models.JSONField") #TODO в качесте ключа использовать country_code_2 из legacy - ?
|
||||
"config": ("config", "django.db.models.JSONField")
|
||||
# TODO в качесте ключа использовать country_code_2 из legacy - ?
|
||||
},
|
||||
# "relations": {
|
||||
# # Как работать c отношение OneToOneField
|
||||
|
|
@ -133,7 +134,7 @@ card = {
|
|||
"vintage_year": "year",
|
||||
}
|
||||
},
|
||||
#TODO вопрос с content_type
|
||||
# TODO вопрос с content_type
|
||||
"relations": {
|
||||
"AwardTypes": [(
|
||||
("award_type", None),
|
||||
|
|
@ -143,4 +144,4 @@ card = {
|
|||
}
|
||||
}
|
||||
|
||||
used_apps = ("locations", )
|
||||
used_apps = ("locations",)
|
||||
|
|
|
|||
19
apps/main/transfer_data.py
Normal file
19
apps/main/transfer_data.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from pprint import pprint
|
||||
|
||||
from transfer.models import CarouselElements
|
||||
from transfer.serializers.carousel import CarouselSerializer
|
||||
|
||||
|
||||
def transfer_carousel():
|
||||
queryset = CarouselElements.objects.all()
|
||||
|
||||
serialized_data = CarouselSerializer(data=list(queryset.values()), many=True)
|
||||
if serialized_data.is_valid():
|
||||
serialized_data.save()
|
||||
else:
|
||||
pprint(f'Carousel serializer errors: {serialized_data.errors}')
|
||||
|
||||
|
||||
data_types = {
|
||||
'whirligig': [transfer_carousel]
|
||||
}
|
||||
|
|
@ -21,7 +21,8 @@ class Command(BaseCommand):
|
|||
'overlook',
|
||||
'tmp',
|
||||
'menu',
|
||||
'location_establishment'
|
||||
'location_establishment',
|
||||
'whirligig',
|
||||
]
|
||||
|
||||
LONG_DATA_TYPES = [
|
||||
|
|
|
|||
|
|
@ -938,3 +938,25 @@ class KeyValueMetadatumKeyValueMetadatumEstablishments(MigrateMixin):
|
|||
# class Meta:
|
||||
# managed = False
|
||||
# db_table = 'wine_types'
|
||||
|
||||
class CarouselElements(MigrateMixin):
|
||||
using = 'legacy'
|
||||
|
||||
title = models.CharField(max_length=255, blank=True, null=True)
|
||||
link = models.CharField(max_length=255, blank=True, null=True)
|
||||
home_page_id = models.IntegerField(blank=True, null=True)
|
||||
created_at = models.DateTimeField()
|
||||
updated_at = models.DateTimeField()
|
||||
attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
|
||||
attachment_content_type = models.CharField(max_length=255, blank=True, null=True)
|
||||
attachment_file_size = models.IntegerField(blank=True, null=True)
|
||||
attachment_updated_at = models.DateTimeField(blank=True, null=True)
|
||||
attachment_suffix_url = models.TextField(blank=True, null=True)
|
||||
geometries = models.CharField(max_length=1024, blank=True, null=True)
|
||||
active = models.IntegerField(blank=True, null=True)
|
||||
description = models.CharField(max_length=255, blank=True, null=True)
|
||||
link_title = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'carousel_elements'
|
||||
|
|
|
|||
59
apps/transfer/serializers/carousel.py
Normal file
59
apps/transfer/serializers/carousel.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
from rest_framework import serializers
|
||||
|
||||
from establishment.models import Establishment
|
||||
from main.models import Carousel
|
||||
from news.models import News
|
||||
|
||||
|
||||
def get_obj_data(model, slug):
|
||||
try:
|
||||
obj = model.objects.get(slug=slug)
|
||||
except model.DoesNotExist:
|
||||
return None, None
|
||||
else:
|
||||
content_type = ContentType.objects.get_for_model(obj)
|
||||
return obj.id, content_type.id
|
||||
|
||||
|
||||
class CarouselSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
title = serializers.CharField(allow_null=True, allow_blank=True)
|
||||
link = serializers.CharField(allow_null=True)
|
||||
link_title = serializers.CharField(allow_null=True, allow_blank=True)
|
||||
description = serializers.CharField(allow_null=True, allow_blank=True)
|
||||
attachment_suffix_url = serializers.CharField(allow_null=True)
|
||||
active = serializers.IntegerField()
|
||||
|
||||
def create(self, validated_data):
|
||||
object_id, content_type_id = self.get_content_type(validated_data)
|
||||
validated_data.update({
|
||||
'active': bool(int(validated_data['active'])),
|
||||
'content_type_id': content_type_id,
|
||||
'object_id': object_id,
|
||||
'is_parse': bool(object_id),
|
||||
})
|
||||
obj = Carousel.objects.create(**validated_data)
|
||||
return obj
|
||||
|
||||
@staticmethod
|
||||
def get_content_type(data):
|
||||
link = data['link']
|
||||
if not link:
|
||||
return None
|
||||
|
||||
obj_data = None, None
|
||||
site = 'gaultmillau.com'
|
||||
if site in link:
|
||||
data = link.split('/')
|
||||
|
||||
try:
|
||||
_type = data[3]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
if _type in ('news', 'pages'):
|
||||
obj_data = get_obj_data(News, data[4])
|
||||
elif _type == 'restaurant':
|
||||
obj_data = get_obj_data(Establishment, data[4])
|
||||
return obj_data
|
||||
Loading…
Reference in New Issue
Block a user