mgrate topic descriptions and shout views
This commit is contained in:
parent
bc52d34b29
commit
01a974e974
|
@ -18,7 +18,8 @@ def migrate(entry):
|
|||
# 'createdAt': date_parse(entry['createdAt']),
|
||||
'title': entry['title'].lower(),
|
||||
'children': [],
|
||||
'community' : Community.default_community.slug
|
||||
'community' : Community.default_community.slug,
|
||||
'body' : entry.get('description')
|
||||
}
|
||||
try:
|
||||
with local_session() as session:
|
||||
|
|
|
@ -3,7 +3,7 @@ import frontmatter
|
|||
import json
|
||||
import sqlite3
|
||||
import sqlalchemy
|
||||
from orm import Shout, Comment, Topic, ShoutTopic, ShoutRating, User
|
||||
from orm import Shout, Comment, Topic, ShoutTopic, ShoutRating, ShoutViewByDay, User
|
||||
from bs4 import BeautifulSoup
|
||||
from migration.html2text import html2text
|
||||
from migration.tables.comments import migrate as migrateComment
|
||||
|
@ -75,7 +75,6 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
|||
'community': Community.default_community.id,
|
||||
'authors': [],
|
||||
'topics': [],
|
||||
'views': entry.get('views', 0),
|
||||
'rating': entry.get('rating', 0),
|
||||
'ratings': [],
|
||||
'createdAt': entry.get('createdAt', '2016-03-05 22:22:00.350000')
|
||||
|
@ -181,7 +180,6 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
|||
shout_dict['deletedBy'] = entry.get('deletedBy', '0')
|
||||
|
||||
del shout_dict['topics'] # FIXME: AttributeError: 'str' object has no attribute '_sa_instance_state'
|
||||
del shout_dict['views'] # FIXME: TypeError: 'views' is an invalid keyword argument for Shout
|
||||
del shout_dict['rating'] # FIXME: TypeError: 'rating' is an invalid keyword argument for Shout
|
||||
del shout_dict['ratings']
|
||||
|
||||
|
@ -201,13 +199,14 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
|||
|
||||
shout_dict['authors'] = [ user, ]
|
||||
try:
|
||||
with local_session() as session:
|
||||
s = Shout.create(**shout_dict)
|
||||
if s:
|
||||
|
||||
# shout ratings
|
||||
shout_dict['ratings'] = []
|
||||
for shout_rating_old in entry.get('ratings',[]):
|
||||
rater = session.query(User).filter(User.old_id == shout_rating_old['createdBy']).first()
|
||||
with local_session() as session:
|
||||
rater = session.query(User).\
|
||||
filter(User.old_id == shout_rating_old['createdBy']).first()
|
||||
if rater:
|
||||
shout_rating_dict = {
|
||||
'value': shout_rating_old['value'],
|
||||
|
@ -219,11 +218,19 @@ def migrate(entry, users_by_oid, topics_by_oid):
|
|||
try: shout_rating = ShoutRating.create(**shout_rating_dict)
|
||||
except sqlalchemy.exc.IntegrityError: pass
|
||||
shout_dict['ratings'].append(shout_rating_dict)
|
||||
|
||||
# shout topics
|
||||
shout_dict['topics'] = []
|
||||
for topic in r['topics']:
|
||||
ShoutTopic.create(**{ 'shout': s.slug, 'topic': topic['slug'] })
|
||||
shout_dict['topics'].append(topic['slug'])
|
||||
|
||||
views = entry.get('views', 1)
|
||||
ShoutViewByDay.create(
|
||||
shout = s.slug,
|
||||
value = views
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
|
|
|
@ -25,7 +25,8 @@ def migrate(entry):
|
|||
# 'createdAt': ts,
|
||||
'title': entry['title'].lower(),
|
||||
'children': [],
|
||||
'community' : Community.default_community.slug
|
||||
'community' : Community.default_community.slug,
|
||||
'body' : entry.get('description')
|
||||
}
|
||||
try:
|
||||
with local_session() as session:
|
||||
|
|
Loading…
Reference in New Issue
Block a user