base models and funcs
This commit is contained in:
parent
449bf0f28c
commit
287578eb9e
|
|
@ -10,7 +10,6 @@ field[1] - название поля в таблице legacy
|
|||
|
||||
"""
|
||||
|
||||
|
||||
card = {
|
||||
"EstablishmentType": {
|
||||
"data_type": "dictionaries",
|
||||
|
|
@ -24,54 +23,54 @@ card = {
|
|||
}
|
||||
},
|
||||
"Establishment": {
|
||||
"data_type": "dictionaries",
|
||||
"dependencies": ("Address", "Collection", "EstablishmentType"),
|
||||
# нету аналогов для establishment_type, establishment_subtypes, schedule, comments, tags
|
||||
"fields": {
|
||||
"Establishments": {
|
||||
"name": "name",
|
||||
"slug": "slug",
|
||||
"is_publish": ("state", "django.db.models.BooleanField")
|
||||
},
|
||||
"relations": {
|
||||
"EstablishmentInfos": {
|
||||
"key": "establishment",
|
||||
"fields": {
|
||||
"website": "website",
|
||||
"facebook": "facebook",
|
||||
"twitter": "twitter",
|
||||
"lafourchette": "lafourchette",
|
||||
"booking": "booking_url"
|
||||
}
|
||||
},
|
||||
"data_type": "dictionaries",
|
||||
"dependencies": ("Address", "Collection", "EstablishmentType"),
|
||||
# нету аналогов для establishment_type, establishment_subtypes, schedule, comments, tags
|
||||
"fields": {
|
||||
"Establishments": {
|
||||
"name": "name",
|
||||
"slug": "slug",
|
||||
"is_publish": ("state", "django.db.models.BooleanField")
|
||||
},
|
||||
"relations": {
|
||||
"EstablishmentInfos": {
|
||||
"key": "establishment",
|
||||
"fields": {
|
||||
"website": "website",
|
||||
"facebook": "facebook",
|
||||
"twitter": "twitter",
|
||||
"lafourchette": "lafourchette",
|
||||
"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": {
|
||||
"data_type": "objects",
|
||||
"dependencies": ("Establishment", ),
|
||||
"dependencies": ("Establishment",),
|
||||
"fields": {
|
||||
"Menus": {
|
||||
"category": ("name", "django.db.models.TJSONField")
|
||||
|
|
@ -86,12 +85,12 @@ card = {
|
|||
},
|
||||
"ContactPhone": {
|
||||
"data_type": "objects",
|
||||
"dependencies": ("Establishment", ),
|
||||
"dependencies": ("Establishment",),
|
||||
"fields": {
|
||||
"Establishments": {
|
||||
"phone": "phone"
|
||||
},
|
||||
"relations": { #TODO правильно ли заполнена связь с Establishment - ?
|
||||
"relations": { # TODO правильно ли заполнена связь с Establishment - ?
|
||||
"Establishments": [
|
||||
(("id", "id"),
|
||||
("Establishment", "establishment", "id", "django.db.models.PositiveIntegerField"))
|
||||
|
|
@ -102,7 +101,7 @@ card = {
|
|||
|
||||
"ContactEmail": {
|
||||
"data_type": "objects",
|
||||
"dependencies": ("Establishment", ),
|
||||
"dependencies": ("Establishment",),
|
||||
"fields": {
|
||||
"EstablishmentInfos": {
|
||||
"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',
|
||||
'recipe',
|
||||
'partner',
|
||||
'gallery'
|
||||
'gallery',
|
||||
'establishment',
|
||||
]
|
||||
|
||||
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 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):
|
||||
|
|
@ -66,5 +66,5 @@ class NewsSerializer(serializers.ModelSerializer):
|
|||
def get_description(data):
|
||||
content = None
|
||||
if data['body']:
|
||||
content = parse_legacy_content(data['body'])
|
||||
content = parse_legacy_news_content(data['body'])
|
||||
return {data['locale']: content}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import yaml
|
||||
|
||||
|
||||
def parse_legacy_content(legacy_content):
|
||||
def parse_legacy_news_content(legacy_content):
|
||||
clear_str = '!ruby/hash:ActiveSupport::HashWithIndifferentAccess'
|
||||
content_dict = yaml.safe_load(legacy_content.replace(clear_str, ''))
|
||||
result = ''
|
||||
|
|
@ -10,3 +10,11 @@ def parse_legacy_content(legacy_content):
|
|||
except KeyError:
|
||||
pass
|
||||
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