-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip management command for data migration
- Loading branch information
1 parent
aae5479
commit d2ce576
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
lacommunaute/documentation/management/commands/rearrange_category_forums.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
from lacommunaute.documentation.models import Category | ||
from lacommunaute.forum.models import Forum | ||
|
||
|
||
def create_categories_from_cat_forums(): | ||
transpositions = [] | ||
for category_forum in Forum.objects.filter(type=1, level=0): | ||
category = Category.objects.create( | ||
name=category_forum.name, | ||
short_description=category_forum.short_description, | ||
description=category_forum.description, | ||
image=category_forum.image, | ||
) | ||
transpositions.append((category_forum, category)) | ||
return transpositions | ||
|
||
|
||
def link_forums_to_categories(transpositions): | ||
for category_forum, category in transpositions: | ||
for forum in category_forum.get_descendants(): | ||
forum.category = category | ||
forum.parent = None | ||
forum.save() | ||
|
||
|
||
def add_redirections(transpositions): | ||
for category_forum, category in transpositions: | ||
Redirection.objects.create(old_path=category_forum.get_absolute_url(), new_path=category.get_absolute_url()) | ||
|
||
|
||
def delete_cat_forums(transpositions): | ||
Forum.objects.filter(id__in=[forum.id for forum, _ in transpositions]).delete() |