Commit 7ac46127a21a39e4069f99d85e05908eee37ebab

Authored by Laura Hawkins
1 parent 3b2a69dc87
Exists in master

working on notifying when adding to a deck

Showing 4 changed files with 19 additions and 3 deletions Side-by-side Diff

flashcards/models.py View file @ 7ac4612
... ... @@ -77,6 +77,7 @@
77 77 user_card.save()
78 78 import flashcards.notifications
79 79 flashcards.notifications.notify_score_change(flashcard)
  80 + flashcards.notifications.deck_card_score_change(flashcard)
80 81  
81 82 def unpull(self, flashcard):
82 83 if not self.is_in_section(flashcard.section):
flashcards/notifications.py View file @ 7ac4612
... ... @@ -2,6 +2,7 @@
2 2 from rest_framework.renderers import JSONRenderer
3 3 from ws4redis.publisher import RedisPublisher
4 4 from ws4redis.redis_store import RedisMessage
  5 +from ws4redis.redis_store import SELF
5 6  
6 7  
7 8 def notify_score_change(flashcard):
... ... @@ -18,4 +19,18 @@
18 19 {'event_type': 'new_card', 'flashcard': serializers.FlashcardSerializer(flashcard).data})
19 20 message = RedisMessage(ws_message)
20 21 redis_publisher.publish_message(message)
  22 +
  23 +# def tell all clients the score changed
  24 + # you added a card
  25 + #
  26 +def deck_card_score_change(flashcard):
  27 + redis_publisher = RedisPublisher(facility='deck/%d' % flashcard.section_id, users=[SELF])
  28 + ws_message = JSONRenderer().render(
  29 + {'event_type': 'pull_card', 'flashcard': serializers.FlashcardSerializer(flashcard).data})
  30 + message = RedisMessage(ws_message)
  31 + redis_publisher.publish_message(message)
  32 +
  33 +
  34 +
  35 +# def hiding stuff
flashcards/views.py View file @ 7ac4612
... ... @@ -306,8 +306,8 @@
306 306 ---
307 307 view_mocker: flashcards.api.mock_no_params
308 308 """
309   - flashcard = self.get_object()
310   - user.unpull(flashcard)
  309 +
  310 + request.user.pull(self.get_object())
311 311 return Response(status=HTTP_204_NO_CONTENT)
312 312  
313 313  
scripts/run_local.sh View file @ 7ac4612
... ... @@ -11,5 +11,5 @@
11 11 source venv/Scripts/activate
12 12 fi
13 13  
14   -python manage.py runserver 127.0.0.1:8080
  14 +python manage.py runserver 192.168.189.130:8080