Commit ddba4aeba18e9e39030a6c4bc999ea8108137ffb

Authored by Rohan Rangray
1 parent 088cf219df
Exists in master

Realtime notifications when card is added to the deck

Showing 3 changed files with 21 additions and 7 deletions Side-by-side Diff

flashcards/migrations/0014_auto_20150601_1315.py View file @ ddba4ae
  1 +# -*- coding: utf-8 -*-
  2 +from __future__ import unicode_literals
  3 +
  4 +from django.db import models, migrations
  5 +
  6 +
  7 +class Migration(migrations.Migration):
  8 +
  9 + dependencies = [
  10 + ('flashcards', '0013_auto_20150601_0513'),
  11 + ]
  12 +
  13 + operations = [
  14 + migrations.AlterField(
  15 + model_name='userflashcard',
  16 + name='next_review',
  17 + field=models.DateTimeField(null=True),
  18 + ),
  19 + ]
flashcards/models.py View file @ ddba4ae
... ... @@ -181,7 +181,7 @@
181 181 mask = MaskField(null=True, blank=True, default=None, help_text="The user-specific mask on the card")
182 182 pulled = DateTimeField(auto_now_add=True, help_text="When the user pulled the card")
183 183 flashcard = ForeignKey('Flashcard')
184   - next_review = DateTimeField(null=True, default=now())
  184 + next_review = DateTimeField(null=True)
185 185 last_interval = IntegerField(default=1)
186 186 last_response_factor = FloatField(default=2.5)
187 187  
flashcards/notifications.py View file @ ddba4ae
1 1 import serializers
2 2 from rest_framework.renderers import JSONRenderer
3   -from django.core.exceptions import PermissionDenied
4 3 from ws4redis.publisher import RedisPublisher
5 4 from ws4redis.redis_store import RedisMessage, SELF
6 5  
7 6  
8   -def authenticate_subscribe(request, channels):
9   - if not request.user.is_authenticated():
10   - raise PermissionDenied('Not allowed to subscribe nor to publish on the Websocket!')
11   -
12   -
13 7 def notify_score_change(flashcard):
14 8 redis_publisher = RedisPublisher(facility='feed/%d' % flashcard.section_id, broadcast=True)
15 9 ws_message = JSONRenderer().render(
... ... @@ -26,6 +20,7 @@
26 20 )
27 21 message = RedisMessage(ws_message)
28 22 redis_publisher.publish_message(message)
  23 + notify_pull(flashcard)
29 24  
30 25  
31 26 def notify_pull(flashcard):