diff --git a/flashcards/management/commands/notifyusers.py b/flashcards/management/commands/notifyusers.py index db83efc..da47572 100644 --- a/flashcards/management/commands/notifyusers.py +++ b/flashcards/management/commands/notifyusers.py @@ -11,7 +11,7 @@ class Command(BaseCommand): notify_list = UserFlashcard.objects.filter( next_review__lte=Now() ).exclude( - user__registration_token=None, + user__registration_id=None, user__last_notified__range=(now()-timedelta(days=1), now()) ).values_list('user').distinct().all() diff --git a/flashcards/migrations/0017_auto_20150601_2001.py b/flashcards/migrations/0017_auto_20150601_2001.py new file mode 100644 index 0000000..2812c01 --- /dev/null +++ b/flashcards/migrations/0017_auto_20150601_2001.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', '0016_user_last_notified'), + ] + + operations = [ + migrations.RenameField( + model_name='user', + old_name='registration_token', + new_name='registration_id', + ), + ] diff --git a/flashcards/models.py b/flashcards/models.py index e9b8028..29a7676 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -71,7 +71,7 @@ class User(AbstractUser, SimpleEmailConfirmationUserMixin): REQUIRED_FIELDS = [] sections = ManyToManyField('Section', help_text="The sections which the user is enrolled in") confirmed_email = BooleanField(default=False) - registration_token = CharField(null=True, default=None, max_length=4096) + registration_id = CharField(null=True, default=None, max_length=4096) last_notified = DateTimeField(null=True, default=None) @property @@ -92,14 +92,14 @@ class User(AbstractUser, SimpleEmailConfirmationUserMixin): def notify(self): gcm = GCM(GCM_API_KEY) gcm.plaintext_request( - registration_id=self.registration_token, + registration_id=self.registration_id, data="You have flashcards to study!" ) self.last_notified = now() self.save() - def set_registration_token(self, token): - self.registration_token = token + def set_registration_id(self, token): + self.registration_id = token self.save() def is_in_section(self, section): diff --git a/flashcards/serializers.py b/flashcards/serializers.py index 2de42e2..0dba597 100644 --- a/flashcards/serializers.py +++ b/flashcards/serializers.py @@ -296,4 +296,4 @@ class QuizAnswerRequestSerializer(ModelSerializer): class SubscribeViewSerializer(Serializer): - registration_token = CharField(allow_blank=False, allow_null=False) + registration_id = CharField(allow_blank=False, allow_null=False) diff --git a/flashcards/views.py b/flashcards/views.py index 6401896..e969f2a 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -243,7 +243,7 @@ def subscribe(request, format=None): """ serializer = SubscribeViewSerializer(data=request.data) serializer.is_valid(raise_exception=True) - request.user.set_registration_token(serializer.validated_data['registration_token']) + request.user.set_registration_id(serializer.validated_data['registration_id']) return Response(status=HTTP_204_NO_CONTENT)