Commit 200f24ab authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch '636-add-deeplinking-functionality-to-push-notifications' into 'master'

Add deeplinking functionality to push notifications

Closes #636

See merge request !802
parents 12cd7c7d 1343e111
......@@ -301,6 +301,9 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
registration_reminder.category = Category.objects.get(
key='event')
registration_reminder.time = registration_reminder_time
registration_reminder.url = reverse("events:event",
args=[self.id])
registration_reminder.save()
self.registration_reminder = registration_reminder
self.registration_reminder.users.set(
......
......@@ -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', '0010_rename_partner_category'),
]
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,6 +140,10 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
any_reg_ids = True
data = {}
if self.url is not None:
data['url'] = self.url
result = FCMNotification(
api_key=settings.PUSH_NOTIFICATIONS_API_KEY
).notify_multiple_devices(
......@@ -143,6 +152,7 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
message_body=str(self.body),
color='#E62272',
sound='default',
data_message=data,
**kwargs
)
......
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