From 7ac46127a21a39e4069f99d85e05908eee37ebab Mon Sep 17 00:00:00 2001 From: Laura Hawkins Date: Wed, 20 May 2015 13:50:27 -0700 Subject: [PATCH] working on notifying when adding to a deck --- flashcards/models.py | 1 + flashcards/notifications.py | 15 +++++++++++++++ flashcards/views.py | 4 ++-- scripts/run_local.sh | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/flashcards/models.py b/flashcards/models.py index 4d0a090..8257c20 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -77,6 +77,7 @@ class User(AbstractUser, SimpleEmailConfirmationUserMixin): user_card.save() import flashcards.notifications flashcards.notifications.notify_score_change(flashcard) + flashcards.notifications.deck_card_score_change(flashcard) def unpull(self, flashcard): if not self.is_in_section(flashcard.section): diff --git a/flashcards/notifications.py b/flashcards/notifications.py index f998b35..322e7dd 100644 --- a/flashcards/notifications.py +++ b/flashcards/notifications.py @@ -2,6 +2,7 @@ import serializers from rest_framework.renderers import JSONRenderer from ws4redis.publisher import RedisPublisher from ws4redis.redis_store import RedisMessage +from ws4redis.redis_store import SELF def notify_score_change(flashcard): @@ -18,3 +19,17 @@ def notify_new_card(flashcard): {'event_type': 'new_card', 'flashcard': serializers.FlashcardSerializer(flashcard).data}) message = RedisMessage(ws_message) redis_publisher.publish_message(message) + +# def tell all clients the score changed + # you added a card + # +def deck_card_score_change(flashcard): + redis_publisher = RedisPublisher(facility='deck/%d' % flashcard.section_id, users=[SELF]) + ws_message = JSONRenderer().render( + {'event_type': 'pull_card', 'flashcard': serializers.FlashcardSerializer(flashcard).data}) + message = RedisMessage(ws_message) + redis_publisher.publish_message(message) + + + +# def hiding stuff \ No newline at end of file diff --git a/flashcards/views.py b/flashcards/views.py index bf9a6c4..24652a1 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -306,8 +306,8 @@ class FlashcardViewSet(GenericViewSet, CreateModelMixin, RetrieveModelMixin): --- view_mocker: flashcards.api.mock_no_params """ - flashcard = self.get_object() - user.unpull(flashcard) + + request.user.pull(self.get_object()) return Response(status=HTTP_204_NO_CONTENT) diff --git a/scripts/run_local.sh b/scripts/run_local.sh index 8818cf4..34201c8 100755 --- a/scripts/run_local.sh +++ b/scripts/run_local.sh @@ -11,4 +11,4 @@ elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then source venv/Scripts/activate fi -python manage.py runserver 127.0.0.1:8080 +python manage.py runserver 192.168.189.130:8080 -- 1.9.1