Filtering search results.
[wolnelektury.git] / src / push / forms.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django import forms
5 from django.contrib.sites.models import Site
6
7 from push.models import Notification
8 from push.utils import send_fcm_push
9
10
11 class NotificationForm(forms.ModelForm):
12
13     class Meta:
14         model = Notification
15         exclude = ('timestamp', 'message_id')
16
17     def save(self, commit=True):
18         notification = super(NotificationForm, self).save(commit=commit)
19         wl_base = 'https://' + Site.objects.get_current().domain
20         if notification.image:
21             image_url = wl_base + notification.image.url
22         else:
23             image_url = None
24         notification.message_id = send_fcm_push(notification.title, notification.body, image_url)
25         if commit:
26             notification.save()