remove shout id
This commit is contained in:
@@ -6,7 +6,7 @@ from orm import Shout, Comment, CommentRating, User
|
||||
from orm.base import local_session
|
||||
from migration.html2text import html2text
|
||||
|
||||
def migrate(entry):
|
||||
def migrate(entry, shouts_by_oid):
|
||||
'''
|
||||
{
|
||||
"_id": "hdtwS8fSyFLxXCgSC",
|
||||
@@ -40,15 +40,19 @@ def migrate(entry):
|
||||
views: Int
|
||||
}
|
||||
'''
|
||||
|
||||
shout_old_id = entry['contentItem']
|
||||
if not shout_old_id in shouts_by_oid:
|
||||
return
|
||||
shout = shouts_by_oid[shout_old_id]
|
||||
|
||||
with local_session() as session:
|
||||
shout = session.query(Shout).filter(Shout.old_id == entry['contentItem']).first()
|
||||
if not shout: shout = session.query(Shout).first()
|
||||
author = session.query(User).filter(User.old_id == entry['createdBy']).first()
|
||||
comment_dict = {
|
||||
'author': author.id if author else 0,
|
||||
'createdAt': date_parse(entry['createdAt']),
|
||||
'body': html2text(entry['body']),
|
||||
'shout': shout.id
|
||||
'shout': shout["slug"]
|
||||
}
|
||||
if entry.get('deleted'):
|
||||
comment_dict['deletedAt'] = date_parse(entry['updatedAt'])
|
||||
@@ -86,7 +90,9 @@ def migrate_2stage(entry, id_map):
|
||||
if not old_reply_to:
|
||||
return
|
||||
old_id = entry['_id']
|
||||
id = id_map.get(old_id)
|
||||
if not old_id in id_map:
|
||||
return
|
||||
id = id_map[old_id]
|
||||
with local_session() as session:
|
||||
comment = session.query(Comment).filter(Comment.id == id).first()
|
||||
reply_to = id_map.get(old_reply_to)
|
||||
|
@@ -133,7 +133,6 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
||||
body_html = str(BeautifulSoup(body_orig, features="html.parser"))
|
||||
r['body'] = body_html # html2text(body_html)
|
||||
body = r.get('body', '')
|
||||
r['old_id'] = entry.get('_id')
|
||||
|
||||
# get author data
|
||||
userdata = {}
|
||||
@@ -212,8 +211,8 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
||||
if rater:
|
||||
shout_rating_dict = {
|
||||
'value': shout_rating_old['value'],
|
||||
'rater_id': rater.id,
|
||||
'shout_id': s.id
|
||||
'rater': rater.id,
|
||||
'shout': s.slug
|
||||
}
|
||||
cts = shout_rating_old.get('createdAt')
|
||||
if cts: shout_rating_dict['rater_id'] = date_parse(cts)
|
||||
@@ -221,14 +220,14 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
||||
except sqlalchemy.exc.IntegrityError: pass
|
||||
shout_dict['ratings'].append(shout_rating_dict)
|
||||
# shout topics
|
||||
shout_dict['id'] = s.id
|
||||
shout_dict['topics'] = []
|
||||
for topic in r['topics']:
|
||||
ShoutTopic.create(**{ 'shout': s.id, 'topic': topic['slug'] })
|
||||
ShoutTopic.create(**{ 'shout': s.slug, 'topic': topic['slug'] })
|
||||
shout_dict['topics'].append(topic['slug'])
|
||||
except Exception as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
if not shout_dict['body']: r['body'] = 'body moved'
|
||||
raise e
|
||||
shout_dict['old_id'] = entry.get('_id')
|
||||
return shout_dict # for json
|
||||
|
Reference in New Issue
Block a user