X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d679452e8cede72656beb1e14b48a1b3e82e79c0..e17ba704033aba068a935c1beb42d1f306e6a114:/src/push/forms.py?ds=sidebyside diff --git a/src/push/forms.py b/src/push/forms.py new file mode 100644 index 000000000..b49096db1 --- /dev/null +++ b/src/push/forms.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from django import forms +from django.contrib.sites.models import Site + +from push.models import Notification +from push.utils import send_fcm_push + + +class NotificationForm(forms.ModelForm): + + class Meta: + model = Notification + exclude = ('timestamp', 'message_id') + + def save(self, commit=True): + notification = super(NotificationForm, self).save(commit=commit) + wl_base = u'https://' + Site.objects.get_current().domain + notification.message_id = send_fcm_push(notification.title, notification.body, wl_base + notification.image.url) + if commit: + notification.save()