-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(3630): Migration des souscriptions par e-mail.
Closes #3630
- Loading branch information
1 parent
bc63d2b
commit dc4b733
Showing
2 changed files
with
33 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
zds/notification/management/commands/migrate_email_subscription.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,24 @@ | ||
# coding: utf-8 | ||
from django.core.management import BaseCommand | ||
|
||
from zds.member.models import Profile | ||
from zds.notification.models import TopicFollowed, TopicAnswerSubscription | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Migrate old email subscriptions to new models.' | ||
|
||
def handle(self, *args, **options): | ||
for profile in Profile.objects.all(): | ||
self.stdout.write(u'Starting migration for {}'.format(profile.user.username)) | ||
|
||
# Get alls topic followed by the user. | ||
topics_followed = TopicFollowed.objects \ | ||
.filter(user=profile.user, email=True) \ | ||
.values("topic").distinct().all() | ||
|
||
# And update email attribute in the TopicAnswerSubscription model. | ||
for topic in topics_followed: | ||
active = TopicAnswerSubscription.objects.get_or_create_active(user=profile.user, content_object=topic) | ||
active.email = True | ||
active.save() |