Skip to content

Commit

Permalink
fix(3630): Migration des souscriptions par e-mail.
Browse files Browse the repository at this point in the history
Closes #3630
  • Loading branch information
GerardPaligot committed Jun 10, 2016
1 parent bc63d2b commit dc4b733
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ Il faudra supprimer en SQL:

S'il y a une erreur pour `article_article_subcategory` et `DROP TABLE tutorial_tutorial_subcategory;` c'est que les tables ont déjà été supprimées précédement (ZEP-25).

Actions à faire pour mettre en prod la version 18.2
===================================================

Notifications
-------------

Lancez la commande `python manage.py migrate_email_subscription` pour migrer tous les sujets suivis par e-mail vers
les nouveaux modèles de souscriptions.

---

**Notes auxquelles penser lors de l'édition de ce fichier (à laisser en bas) :**
Expand Down
24 changes: 24 additions & 0 deletions zds/notification/management/commands/migrate_email_subscription.py
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()

0 comments on commit dc4b733

Please sign in to comment.