base models and funcs
This commit is contained in:
parent
449bf0f28c
commit
287578eb9e
|
|
@ -10,7 +10,6 @@ field[1] - название поля в таблице legacy
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
card = {
|
card = {
|
||||||
"EstablishmentType": {
|
"EstablishmentType": {
|
||||||
"data_type": "dictionaries",
|
"data_type": "dictionaries",
|
||||||
|
|
@ -24,54 +23,54 @@ card = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Establishment": {
|
"Establishment": {
|
||||||
"data_type": "dictionaries",
|
"data_type": "dictionaries",
|
||||||
"dependencies": ("Address", "Collection", "EstablishmentType"),
|
"dependencies": ("Address", "Collection", "EstablishmentType"),
|
||||||
# нету аналогов для establishment_type, establishment_subtypes, schedule, comments, tags
|
# нету аналогов для establishment_type, establishment_subtypes, schedule, comments, tags
|
||||||
"fields": {
|
"fields": {
|
||||||
"Establishments": {
|
"Establishments": {
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"slug": "slug",
|
"slug": "slug",
|
||||||
"is_publish": ("state", "django.db.models.BooleanField")
|
"is_publish": ("state", "django.db.models.BooleanField")
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"EstablishmentInfos": {
|
"EstablishmentInfos": {
|
||||||
"key": "establishment",
|
"key": "establishment",
|
||||||
"fields": {
|
"fields": {
|
||||||
"website": "website",
|
"website": "website",
|
||||||
"facebook": "facebook",
|
"facebook": "facebook",
|
||||||
"twitter": "twitter",
|
"twitter": "twitter",
|
||||||
"lafourchette": "lafourchette",
|
"lafourchette": "lafourchette",
|
||||||
"booking": "booking_url"
|
"booking": "booking_url"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
# как работать с GenericRelation - ?
|
|
||||||
# как работать с ManyToManyField - ? "EstablishmentSubType", "schedule"
|
|
||||||
"relations": {
|
|
||||||
"Locations": [
|
|
||||||
(("location", None),
|
|
||||||
("Address", "address", None, None)),
|
|
||||||
],
|
|
||||||
"Establishments": [#TODO правильно ли заполнена связь с EstablishmentType - ?
|
|
||||||
(("type", "type"),
|
|
||||||
("EstablishmentType", "establishment_type", "id", "django.db.models.PositiveIntegerField"))
|
|
||||||
]
|
|
||||||
# # "establishment_subtypes": "EstablishmentSubType",
|
|
||||||
# "collections": "Collection",
|
|
||||||
# # TODO: нашел schedules в legacy
|
|
||||||
# # "schedule": "Timetable",
|
|
||||||
# "award": "Award",
|
|
||||||
# # "tags": "MetaDataContent",
|
|
||||||
# "reviews": "Review",
|
|
||||||
# # "comments": "Comment",
|
|
||||||
# # "favorites": "Favorites" # В legacy этой таблицы не было
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
# как работать с GenericRelation - ?
|
||||||
|
# как работать с ManyToManyField - ? "EstablishmentSubType", "schedule"
|
||||||
|
"relations": {
|
||||||
|
"Locations": [
|
||||||
|
(("location", None),
|
||||||
|
("Address", "address", None, None)),
|
||||||
|
],
|
||||||
|
"Establishments": [ # TODO правильно ли заполнена связь с EstablishmentType - ?
|
||||||
|
(("type", "type"),
|
||||||
|
("EstablishmentType", "establishment_type", "id", "django.db.models.PositiveIntegerField"))
|
||||||
|
]
|
||||||
|
# # "establishment_subtypes": "EstablishmentSubType",
|
||||||
|
# "collections": "Collection",
|
||||||
|
# # TODO: нашел schedules в legacy
|
||||||
|
# # "schedule": "Timetable",
|
||||||
|
# "award": "Award",
|
||||||
|
# # "tags": "MetaDataContent",
|
||||||
|
# "reviews": "Review",
|
||||||
|
# # "comments": "Comment",
|
||||||
|
# # "favorites": "Favorites" # В legacy этой таблицы не было
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
"Menu": {
|
"Menu": {
|
||||||
"data_type": "objects",
|
"data_type": "objects",
|
||||||
"dependencies": ("Establishment", ),
|
"dependencies": ("Establishment",),
|
||||||
"fields": {
|
"fields": {
|
||||||
"Menus": {
|
"Menus": {
|
||||||
"category": ("name", "django.db.models.TJSONField")
|
"category": ("name", "django.db.models.TJSONField")
|
||||||
|
|
@ -86,12 +85,12 @@ card = {
|
||||||
},
|
},
|
||||||
"ContactPhone": {
|
"ContactPhone": {
|
||||||
"data_type": "objects",
|
"data_type": "objects",
|
||||||
"dependencies": ("Establishment", ),
|
"dependencies": ("Establishment",),
|
||||||
"fields": {
|
"fields": {
|
||||||
"Establishments": {
|
"Establishments": {
|
||||||
"phone": "phone"
|
"phone": "phone"
|
||||||
},
|
},
|
||||||
"relations": { #TODO правильно ли заполнена связь с Establishment - ?
|
"relations": { # TODO правильно ли заполнена связь с Establishment - ?
|
||||||
"Establishments": [
|
"Establishments": [
|
||||||
(("id", "id"),
|
(("id", "id"),
|
||||||
("Establishment", "establishment", "id", "django.db.models.PositiveIntegerField"))
|
("Establishment", "establishment", "id", "django.db.models.PositiveIntegerField"))
|
||||||
|
|
@ -102,7 +101,7 @@ card = {
|
||||||
|
|
||||||
"ContactEmail": {
|
"ContactEmail": {
|
||||||
"data_type": "objects",
|
"data_type": "objects",
|
||||||
"dependencies": ("Establishment", ),
|
"dependencies": ("Establishment",),
|
||||||
"fields": {
|
"fields": {
|
||||||
"EstablishmentInfos": {
|
"EstablishmentInfos": {
|
||||||
"email": "email"
|
"email": "email"
|
||||||
|
|
@ -117,5 +116,4 @@ card = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
used_apps = ("review", "location", "collection", "main", "timetable", "favorites", "comment",)
|
||||||
used_apps = ("review", "location", "collection", "main", "timetable", "favorites", "comment", )
|
|
||||||
|
|
|
||||||
18
apps/establishment/transfer_data.py
Normal file
18
apps/establishment/transfer_data.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from transfer.serializers.establishment import EstablishmentSerializer
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_establishment():
|
||||||
|
result = []
|
||||||
|
|
||||||
|
serialized_data = EstablishmentSerializer(data=result, many=True)
|
||||||
|
if serialized_data.is_valid():
|
||||||
|
serialized_data.save()
|
||||||
|
else:
|
||||||
|
pprint(f"Establishment serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
data_types = {
|
||||||
|
"establishment": [transfer_establishment]
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,8 @@ class Command(BaseCommand):
|
||||||
'subscriber',
|
'subscriber',
|
||||||
'recipe',
|
'recipe',
|
||||||
'partner',
|
'partner',
|
||||||
'gallery'
|
'gallery',
|
||||||
|
'establishment',
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
26
apps/transfer/serializers/establishment.py
Normal file
26
apps/transfer/serializers/establishment.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from establishment.models import Establishment
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Establishment
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
pass
|
||||||
|
# data.update({
|
||||||
|
# 'state': self.get_state(data),
|
||||||
|
# 'template': self.get_template(data),
|
||||||
|
# 'title': self.get_title(data),
|
||||||
|
# 'description': self.get_description(data),
|
||||||
|
# })
|
||||||
|
# data.pop('body')
|
||||||
|
# data.pop('locale')
|
||||||
|
# return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
pass
|
||||||
|
# return News.objects.create(**validated_data)
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from news.models import News
|
from news.models import News
|
||||||
from utils.legacy_parser import parse_legacy_content
|
from utils.legacy_parser import parse_legacy_news_content
|
||||||
|
|
||||||
|
|
||||||
class NewsSerializer(serializers.ModelSerializer):
|
class NewsSerializer(serializers.ModelSerializer):
|
||||||
|
|
@ -66,5 +66,5 @@ class NewsSerializer(serializers.ModelSerializer):
|
||||||
def get_description(data):
|
def get_description(data):
|
||||||
content = None
|
content = None
|
||||||
if data['body']:
|
if data['body']:
|
||||||
content = parse_legacy_content(data['body'])
|
content = parse_legacy_news_content(data['body'])
|
||||||
return {data['locale']: content}
|
return {data['locale']: content}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def parse_legacy_content(legacy_content):
|
def parse_legacy_news_content(legacy_content):
|
||||||
clear_str = '!ruby/hash:ActiveSupport::HashWithIndifferentAccess'
|
clear_str = '!ruby/hash:ActiveSupport::HashWithIndifferentAccess'
|
||||||
content_dict = yaml.safe_load(legacy_content.replace(clear_str, ''))
|
content_dict = yaml.safe_load(legacy_content.replace(clear_str, ''))
|
||||||
result = ''
|
result = ''
|
||||||
|
|
@ -10,3 +10,11 @@ def parse_legacy_content(legacy_content):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def parse_legacy_schedule_content(legacy_content):
|
||||||
|
clear_str = '!ruby/hash:ActiveSupport::HashWithIndifferentAccess'
|
||||||
|
content_dict = yaml.safe_load(legacy_content.replace(clear_str, ''))
|
||||||
|
result = ''
|
||||||
|
# TODO: вернуть валидные данные расписания для новой модели
|
||||||
|
return result
|
||||||
Loading…
Reference in New Issue
Block a user