From 148b7e62d21d370011b87b073ee6e6ba30d55349 Mon Sep 17 00:00:00 2001 From: Rohan Rangray Date: Mon, 1 Jun 2015 13:38:16 -0700 Subject: [PATCH] Attempted fix for /deck/ notifications. --- flashcards/models.py | 2 +- flashcards/notifications.py | 5 ++--- flashcards/views.py | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flashcards/models.py b/flashcards/models.py index fbeb5f2..486116d 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -110,7 +110,7 @@ class User(AbstractUser, SimpleEmailConfirmationUserMixin): import flashcards.notifications flashcards.notifications.notify_score_change(flashcard) - flashcards.notifications.notify_pull(flashcard) + flashcards.notifications.notify_pull(flashcard, self) def unpull(self, flashcard): if not self.is_in_section(flashcard.section): diff --git a/flashcards/notifications.py b/flashcards/notifications.py index 862e26b..3573515 100644 --- a/flashcards/notifications.py +++ b/flashcards/notifications.py @@ -20,11 +20,10 @@ def notify_new_card(flashcard): ) message = RedisMessage(ws_message) redis_publisher.publish_message(message) - notify_pull(flashcard) -def notify_pull(flashcard): - redis_publisher = RedisPublisher(facility='deck/%d' % flashcard.section_id, users=[SELF]) +def notify_pull(flashcard, user): + redis_publisher = RedisPublisher(facility='deck/%d' % flashcard.section_id, users=[user]) ws_message = JSONRenderer().render( {'event_type': 'pull_card', 'flashcard': serializers.FlashcardSerializer(flashcard).data} ) diff --git a/flashcards/views.py b/flashcards/views.py index 0cb6876..630178e 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -6,7 +6,7 @@ from flashcards.api import StandardResultsSetPagination, IsEnrolledInAssociatedS IsAuthenticatedAndConfirmed from flashcards.models import Section, User, Flashcard, FlashcardHide, UserFlashcardQuiz, \ FlashcardAlreadyPulledException, FlashcardNotInDeckException -from flashcards.notifications import notify_new_card +from flashcards.notifications import notify_new_card, notify_pull from flashcards.serializers import SectionSerializer, UserUpdateSerializer, RegistrationSerializer, UserSerializer, \ PasswordResetSerializer, PasswordResetRequestSerializer, EmailPasswordSerializer, FlashcardSerializer, \ FlashcardUpdateSerializer, QuizRequestSerializer, QuizResponseSerializer, \ @@ -317,6 +317,7 @@ class FlashcardViewSet(GenericViewSet, CreateModelMixin, RetrieveModelMixin): flashcard = Flashcard.objects.create(**data) self.perform_create(flashcard) notify_new_card(flashcard) + notify_pull(flashcard, request.user) headers = self.get_success_headers(data) request.user.pull(flashcard) response_data = FlashcardSerializer(flashcard).data -- 1.9.1