Commit fbcab5d2 authored by Gijs Hendriksen's avatar Gijs Hendriksen

Add sent time to push notification, in order to sort API results

parent fe7f37a7
...@@ -41,4 +41,4 @@ class MessageSerializer(ModelSerializer): ...@@ -41,4 +41,4 @@ class MessageSerializer(ModelSerializer):
class Meta: class Meta:
model = Message model = Message
fields = ('pk', 'title', 'body', 'url', 'category') fields = ('pk', 'title', 'body', 'url', 'category', 'time')
from django.utils.translation import get_language_from_request from django.utils.translation import get_language_from_request
from rest_framework import permissions, viewsets from rest_framework import permissions, viewsets, filters
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
...@@ -52,6 +52,8 @@ class DeviceViewSet(viewsets.ModelViewSet): ...@@ -52,6 +52,8 @@ class DeviceViewSet(viewsets.ModelViewSet):
class MessageViewSet(viewsets.ReadOnlyModelViewSet): class MessageViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = (permissions.IsAuthenticated,) permission_classes = (permissions.IsAuthenticated,)
queryset = Message.objects.all() queryset = Message.objects.all()
filter_backends = (filters.OrderingFilter,)
ordering_fields = ('time',)
serializer_class = MessageSerializer serializer_class = MessageSerializer
def get_queryset(self): def get_queryset(self):
......
This diff was suppressed by a .gitattributes entry.
...@@ -2,8 +2,8 @@ msgid "" ...@@ -2,8 +2,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-03-02 16:51+0100\n" "POT-Creation-Date: 2019-10-13 16:50+0200\n"
"PO-Revision-Date: 2019-03-02 16:52+0100\n" "PO-Revision-Date: 2019-10-13 16:51+0200\n"
"Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n" "Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: nl\n" "Language: nl\n"
...@@ -11,7 +11,7 @@ msgstr "" ...@@ -11,7 +11,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.2.1\n" "X-Generator: Poedit 1.8.7.1\n"
#: admin.py #: admin.py
msgid "Enable selected devices" msgid "Enable selected devices"
...@@ -90,6 +90,10 @@ msgstr "mislukt" ...@@ -90,6 +90,10 @@ msgstr "mislukt"
msgid "success" msgid "success"
msgstr "succesvol" msgstr "succesvol"
#: models.py
msgid "time"
msgstr "tijd"
#: templates/admin/pushnotifications/change_form.html #: templates/admin/pushnotifications/change_form.html
msgid "Send message" msgid "Send message"
msgstr "Verstuur bericht" msgstr "Verstuur bericht"
# Generated by Django 2.2.1 on 2019-10-13 14:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pushnotifications', '0014_fix_typo'),
]
operations = [
migrations.RemoveField(
model_name='scheduledmessage',
name='time',
),
migrations.AddField(
model_name='message',
name='time',
field=models.DateTimeField(blank=True, null=True, verbose_name='time'),
),
]
...@@ -3,6 +3,7 @@ import datetime ...@@ -3,6 +3,7 @@ import datetime
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.utils import timezone
from django.utils.translation import override from django.utils.translation import override
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from firebase_admin import messaging from firebase_admin import messaging
...@@ -126,6 +127,11 @@ class Message(models.Model, metaclass=ModelTranslateMeta): ...@@ -126,6 +127,11 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
blank=True, blank=True,
null=True, null=True,
) )
time = models.DateTimeField(
verbose_name=_('time'),
blank=True,
null=True,
)
def __str__(self): def __str__(self):
return '{}: {}'.format(self.title, self.body) return '{}: {}'.format(self.title, self.body)
...@@ -187,6 +193,7 @@ class Message(models.Model, metaclass=ModelTranslateMeta): ...@@ -187,6 +193,7 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
self.sent = True self.sent = True
self.success = success_total self.success = success_total
self.failure = failure_total self.failure = failure_total
self.time = timezone.now()
self.save() self.save()
return None return None
...@@ -204,5 +211,4 @@ class ScheduledMessage(Message, metaclass=ModelTranslateMeta): ...@@ -204,5 +211,4 @@ class ScheduledMessage(Message, metaclass=ModelTranslateMeta):
objects = ScheduledMessageManager() objects = ScheduledMessageManager()
scheduled = models.BooleanField(default=True) scheduled = models.BooleanField(default=True)
time = models.DateTimeField()
executed = models.DateTimeField(null=True) executed = models.DateTimeField(null=True)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment