From ddba4aeba18e9e39030a6c4bc999ea8108137ffb Mon Sep 17 00:00:00 2001 From: Rohan Rangray Date: Mon, 1 Jun 2015 13:15:42 -0700 Subject: [PATCH] Realtime notifications when card is added to the deck --- flashcards/migrations/0014_auto_20150601_1315.py | 19 +++++++++++++++++++ flashcards/models.py | 2 +- flashcards/notifications.py | 7 +------ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 flashcards/migrations/0014_auto_20150601_1315.py diff --git a/flashcards/migrations/0014_auto_20150601_1315.py b/flashcards/migrations/0014_auto_20150601_1315.py new file mode 100644 index 0000000..cd68a53 --- /dev/null +++ b/flashcards/migrations/0014_auto_20150601_1315.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('flashcards', '0013_auto_20150601_0513'), + ] + + operations = [ + migrations.AlterField( + model_name='userflashcard', + name='next_review', + field=models.DateTimeField(null=True), + ), + ] diff --git a/flashcards/models.py b/flashcards/models.py index 63a7602..fbeb5f2 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -181,7 +181,7 @@ class UserFlashcard(Model): mask = MaskField(null=True, blank=True, default=None, help_text="The user-specific mask on the card") pulled = DateTimeField(auto_now_add=True, help_text="When the user pulled the card") flashcard = ForeignKey('Flashcard') - next_review = DateTimeField(null=True, default=now()) + next_review = DateTimeField(null=True) last_interval = IntegerField(default=1) last_response_factor = FloatField(default=2.5) diff --git a/flashcards/notifications.py b/flashcards/notifications.py index a1bb959..862e26b 100644 --- a/flashcards/notifications.py +++ b/flashcards/notifications.py @@ -1,15 +1,9 @@ import serializers from rest_framework.renderers import JSONRenderer -from django.core.exceptions import PermissionDenied from ws4redis.publisher import RedisPublisher from ws4redis.redis_store import RedisMessage, SELF -def authenticate_subscribe(request, channels): - if not request.user.is_authenticated(): - raise PermissionDenied('Not allowed to subscribe nor to publish on the Websocket!') - - def notify_score_change(flashcard): redis_publisher = RedisPublisher(facility='feed/%d' % flashcard.section_id, broadcast=True) ws_message = JSONRenderer().render( @@ -26,6 +20,7 @@ def notify_new_card(flashcard): ) message = RedisMessage(ws_message) redis_publisher.publish_message(message) + notify_pull(flashcard) def notify_pull(flashcard): -- 1.9.1