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