workaround problem witch search (collision with migdal)
[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         notification.message_id = send_fcm_push(notification.title, notification.body, wl_base + notification.image.url)
22         if commit:
23             notification.save()