Commit 76e11ca9 authored by Luko van der Maas's avatar Luko van der Maas
Browse files

added model fields for the click action of a pushnotification message

parent 0d026aaf
......@@ -34,21 +34,22 @@ class DeviceAdmin(admin.ModelAdmin):
@admin.register(models.Message)
class MessageAdmin(TranslatedModelAdmin):
"""Manage normal messages"""
list_display = ('title', 'body', 'category', 'sent', 'success', 'failure')
list_display = ('title', 'body', 'category', 'url',
'sent', 'success', 'failure')
filter_horizontal = ('users',)
list_filter = ('sent', 'category')
def get_fields(self, request, obj=None):
if obj and obj.sent:
return ('users', 'title_nl', 'title_en', 'body_nl', 'body_en',
'category', 'success', 'failure')
'url', 'category', 'success', 'failure')
return ('users', 'title_nl', 'title_en', 'body_nl', 'body_en',
'category')
'url', 'category')
def get_readonly_fields(self, request, obj=None):
if obj and obj.sent:
return ('users', 'title_nl', 'title_en', 'body_nl', 'body_en',
'category', 'success', 'failure')
'url', 'category', 'success', 'failure')
return super().get_readonly_fields(request, obj)
def change_view(self, request, object_id, form_url='', **kwargs):
......@@ -69,12 +70,12 @@ class ScheduledMessageAdmin(TranslatedModelAdmin):
def get_fields(self, request, obj=None):
if obj and obj.sent:
return ('users', 'title_nl', 'title_en', 'body_nl', 'body_en',
'category', 'success', 'failure', 'time', 'task_id')
'url', 'category', 'success', 'failure', 'time', 'task_id')
return ('users', 'title_nl', 'title_en', 'body_nl', 'body_en',
'category', 'time', 'task_id')
'url', 'category', 'time', 'task_id')
def get_readonly_fields(self, request, obj=None):
if obj and obj.sent:
return ('users', 'title_nl', 'title_en', 'body_nl', 'body_en',
'category', 'success', 'failure', 'time', 'task_id')
'url', 'category', 'success', 'failure', 'time', 'task_id')
return 'task_id',
# Generated by Django 2.0.6 on 2018-07-11 17:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pushnotifications', '0008_scheduledmessage'),
]
operations = [
migrations.AddField(
model_name='message',
name='url',
field=models.CharField(max_length=256, null=True, verbose_name='url'),
),
]
......@@ -89,6 +89,11 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
models.TextField,
verbose_name=_('body')
)
url = models.CharField(
verbose_name=_('url'),
max_length=256,
null=True
)
category = models.ForeignKey(
Category,
on_delete=models.CASCADE,
......@@ -135,15 +140,17 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
any_reg_ids = True
if self.url is not None:
kwargs['click_action'] = self.url
result = FCMNotification(
api_key=settings.PUSH_NOTIFICATIONS_API_KEY
).notify_multiple_devices(
registration_ids=reg_ids,
message_title=self.title,
message_body=str(self.body),
color='#062272',
color='#E62272',
sound='default',
click_action='https://thalia.nu/pizzas/',
**kwargs
)
......
Supports Markdown
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