Skip to content

Commit

Permalink
associate Topics with Document when migrating Forum
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Oct 10, 2024
1 parent 505b250 commit fdfdf6a
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from lacommunaute.documentation.models import Category, Document, DocumentRating
from lacommunaute.forum.models import Forum, ForumRating
from lacommunaute.forum_conversation.models import Topic


def create_categories_from_catforums():
Expand Down Expand Up @@ -68,6 +69,20 @@ def migrate_ratings(document_transpo_dict):
ForumRating.objects.all().delete()


def migrate_topics(document_transpo_dict):
main_forum = Forum.objects.get_main_forum()

for forum, document in document_transpo_dict.items():
topics = Topic.objects.filter(forum=forum)
sys.stdout.write(f"*** {len(topics)} topics to migrate from {forum} ({forum.id}) to {main_forum}\n")

for topic in topics:
topic.document = document
topic.forum = main_forum
topic.save()
forum.save()


def del_forums(category_transpo_dict, document_transpo_dict):
forums_to_delete = list(category_transpo_dict.keys()) + list(document_transpo_dict.keys())
return Forum.objects.filter(pk__in=[forum.pk for forum in forums_to_delete]).delete()
Expand All @@ -88,7 +103,10 @@ def handle(self, *args, **options):
migrate_ratings(document_transpo_dict)
sys.stdout.write("Ratings migrated\n")

## TODO next : Topics and Stats
migrate_topics(document_transpo_dict)
sys.stdout.write("Topics migrated\n")

## TODO next : Stats

deleted_forums = del_forums(category_transpo_dict, document_transpo_dict)
sys.stdout.write(f"{deleted_forums} forums deleted\n")
Expand Down

0 comments on commit fdfdf6a

Please sign in to comment.