-
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.
- Loading branch information
1 parent
e8e479f
commit 20fc6bc
Showing
40 changed files
with
739 additions
and
421 deletions.
There are no files selected for viewing
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
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
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,8 @@ | ||
from django.db import models | ||
|
||
|
||
class Kind(models.TextChoices): | ||
PUBLIC_FORUM = "PUBLIC_FORUM", "Espace d'échange" | ||
PRIVATE_FORUM = "PRIVATE_FORUM", "Espace d'échange privé" | ||
NEWS = "NEWS", "Actualités" | ||
DOCUMENTATION = "DOCUMENTATION", "Documentation" |
77 changes: 77 additions & 0 deletions
77
lacommunaute/forum/management/commands/202306_forumpublic.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,77 @@ | ||
from typing import List | ||
|
||
from django.contrib.redirects.models import Redirect | ||
from django.contrib.sites.models import Site | ||
from django.core.management.base import BaseCommand | ||
from taggit.models import Tag | ||
|
||
from lacommunaute.forum.models import Forum | ||
from lacommunaute.forum_conversation.models import Topic | ||
|
||
|
||
public_forums_id_list = [2, 106, 69, 107, 50, 98] | ||
new_forum_name = "Espace d'échanges" | ||
site_id = 1 | ||
|
||
|
||
def create_tags(forum_id_list: List[int]) -> None: | ||
print("Création des nouveaux tags") | ||
return Tag.objects.bulk_create( | ||
[Tag(name=forum.name, slug=forum.slug) for forum in Forum.objects.filter(id__in=forum_id_list)] | ||
) | ||
|
||
|
||
def create_forum() -> Forum: | ||
print("Création du nouveau forum public") | ||
forum = Forum.objects.create(name=new_forum_name, type=Forum.FORUM_POST) | ||
forum.move_to(Forum.objects.get(tree_id=1, level=0), "left") | ||
return forum | ||
|
||
|
||
def update_topics(forum_id_list: List[int], new_forum: Forum) -> None: | ||
print("Mise à jour des topics") | ||
for forum in Forum.objects.filter(id__in=public_forums_id_list): | ||
for topic in Topic.objects.filter(forum=forum): | ||
topic.tags.add(forum.name) | ||
topic.forum = new_forum | ||
topic.save() | ||
|
||
|
||
def add_redirections(forum_id_list: List[int], site_id: int, new_forum: Forum) -> None: | ||
print("Ajout des redirections") | ||
site = Site.objects.get(id=site_id) | ||
Redirect.objects.bulk_create( | ||
[ | ||
Redirect( | ||
site=site, | ||
old_path=f"/forum/{forum.slug}-{forum.id}/{topic.slug}-{topic.id}", | ||
new_path=f"/forum/{new_forum.slug}-{new_forum.id}/{topic.slug}-{topic.id}", | ||
) | ||
for forum in Forum.objects.filter(id__in=forum_id_list) | ||
for topic in Topic.objects.filter(forum=forum) | ||
] | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "réorganisation des forums publics" | ||
|
||
def handle(self, *args, **options): | ||
# ajouter les nouveaux tags à partir des forums publics existants | ||
create_tags(public_forums_id_list) | ||
|
||
# ajouter le nouveau forum public | ||
forum = create_forum() | ||
|
||
# ajouter ces tags aux topics concernés | ||
# migrer les topics des forums publics existants vers le nouveau forum public | ||
update_topics(public_forums_id_list, forum) | ||
|
||
# ajouter les redirections des anciens forums publics vers le nouveau forum public | ||
add_redirections(public_forums_id_list, site_id, forum) | ||
|
||
# supprimer les forums publics existants | ||
print("Suppression des anciens forums publics") | ||
Forum.objects.filter(id__in=public_forums_id_list).delete() | ||
|
||
print("Terminé") |
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,50 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 08:37 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def add_kind_to_forums(apps, schema_editor): | ||
Forum = apps.get_model("forum", "Forum") | ||
Forum.objects.filter(is_newsfeed=True).update(kind="NEWS") | ||
Forum.objects.filter(is_newsfeed=False, is_private=True).update(kind="PRIVATE_FORUM") | ||
Forum.objects.filter(is_newsfeed=False, is_private=False, type=1).update(kind="DOCUMENTATION") | ||
|
||
|
||
def remove_kind_from_forums(apps, schema_editor): | ||
Forum = apps.get_model("forum", "Forum") | ||
Forum.objects.filter(kind="NEWS").update(is_newsfeed=True, is_private=False) | ||
Forum.objects.filter(kind="PRIVATE_FORUM").update(is_private=True, is_newsfeed=False) | ||
Forum.objects.filter(kind="DOCUMENTATION").update(is_private=False, is_newsfeed=False, type=1) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("forum", "0010_forum_is_newsfeed"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="forum", | ||
name="kind", | ||
field=models.CharField( | ||
choices=[ | ||
("PUBLIC_FORUM", "Espace d'échange"), | ||
("PRIVATE_FORUM", "Espace d'échange privé"), | ||
("NEWS", "Actualités"), | ||
("DOCUMENTATION", "Documentation"), | ||
], | ||
default="PUBLIC_FORUM", | ||
max_length=20, | ||
verbose_name="Type", | ||
), | ||
), | ||
migrations.RunPython(add_kind_to_forums, remove_kind_from_forums), | ||
migrations.RemoveField( | ||
model_name="forum", | ||
name="is_newsfeed", | ||
), | ||
migrations.RemoveField( | ||
model_name="forum", | ||
name="is_private", | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
lacommunaute/forum/migrations/0012_forum_short_description_alter_forum_kind.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,17 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 08:54 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("forum", "0011_forum_kind"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="forum", | ||
name="short_description", | ||
field=models.CharField(blank=True, max_length=160, null=True, verbose_name="Description courte (SEO)"), | ||
), | ||
] |
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
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
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
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
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
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
Oops, something went wrong.