From 93f1f9db041efd0644749d19b42d378a7caed1c7 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Tue, 28 Aug 2018 11:59:24 +0200 Subject: [PATCH] Working version of comments migration. --- .../management/commands/migrate_comments.py | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/opentech/apply/activity/management/commands/migrate_comments.py b/opentech/apply/activity/management/commands/migrate_comments.py index ce714883d..59bfd12b1 100644 --- a/opentech/apply/activity/management/commands/migrate_comments.py +++ b/opentech/apply/activity/management/commands/migrate_comments.py @@ -30,18 +30,22 @@ class Command(BaseCommand): def process(self, id): comment = self.data[id] - activity = Activity.objects.create( - timestamp=datetime.fromtimestamp(int(comment['created']), timezone.utc), - user=self.get_user(comment['uid']), - submission=self.get_submission(comment['nid']), - message=self.get_message(comment['subject'], comment['comment_body']['safe_value']), - ) - try: - activity.save() - self.stdout.write(f"Processed \"{comment['subject']}\" ({comment['cid']})") - except IntegrityError: - self.stdout.write(f"Skipped \"{comment['subject']}\" ({comment['cid']}) due to IntegrityError") + activity = Activity.objects.create( + timestamp=datetime.fromtimestamp(int(comment['created']), timezone.utc), + user=self.get_user(comment['uid']), + submission=self.get_submission(comment['nid']), + message=self.get_message(comment['subject'], comment['comment_body']['value']), + type='comment', + visibility='internal', + ) + try: + activity.save() + self.stdout.write(f"Processed \"{comment['subject']}\" ({comment['cid']})") + except IntegrityError: + self.stdout.write(f"Skipped \"{comment['subject']}\" ({comment['cid']}) due to IntegrityError") + pass + except ValueError: pass def get_user(self, uid): @@ -52,8 +56,8 @@ class Command(BaseCommand): return None def get_message(self, comment_subject, comment_body): - message = f"<p>{comment_subject}</p>{comment_body}" - return self.nl2br(message) + message = f"{comment_subject} – {comment_body}" + return message def get_submission(self, nid): try: -- GitLab