forked from bogdal/django-gcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
37 lines (24 loc) · 962 Bytes
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django import forms
from django.utils.translation import ugettext_lazy as _
from .models import get_device_model
class RegisterDeviceForm(forms.ModelForm):
class Meta:
model = get_device_model()
fields = ('dev_id', 'reg_id', 'name',)
def save(self, commit=True):
self.instance.is_active = True
return super(RegisterDeviceForm, self).save(commit)
class UnregisterDeviceForm(forms.ModelForm):
class Meta:
model = get_device_model()
fields = ('dev_id',)
def clean(self):
if not self.instance.pk:
raise forms.ValidationError(
"Device '%s' does not exist" % self.cleaned_data['dev_id'])
return self.cleaned_data
def save(self, commit=True):
self.instance.mark_inactive()
return super(UnregisterDeviceForm, self).save(commit)
class MessageForm(forms.Form):
message = forms.CharField(label=_('Message'), required=True)