Commit 7ac46127a21a39e4069f99d85e05908eee37ebab
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