Project

General

Profile

« Previous | Next » 

Revision 8759c981

Added by Serghei Mihai over 9 years ago

api: subscriptions management endpoint (#10794)

View differences:

corbo/forms.py
class AnnounceForm(forms.ModelForm):
transport_channel = forms.MultipleChoiceField(required=False,
choices=channel_choices,
widget=forms.CheckboxSelectMultiple())
class Meta:
model = Announce
......
}
fields = '__all__'
def __init__(self, *args, **kwargs):
super(AnnounceForm, self).__init__(*args, **kwargs)
self.fields['transport_channel'].initial = [b.channel for \
b in self.instance.broadcast_set.all()]
def clean_transport_channel(self):
channels = self.cleaned_data['transport_channel']
limit = 160
if 'sms' in channels and \
len(self.cleaned_data['text']) > limit:
raise forms.ValidationError(_('Announce content exceeds %s chars'
' and cannot be sent by SMS' % limit))
return channels
def save(self, *args, **kwargs):
instance = super(AnnounceForm, self).save(*args, **kwargs)
if instance:
print "CD: %s" % self.cleaned_data
channels = self.cleaned_data['transport_channel']
for channel in channels:
Broadcast.objects.get_or_create(announce=instance,
channel=channel)
self.instance.broadcast_set.exclude(announce=instance,
channel__in=channels).delete()
Broadcast.objects.get_or_create(announce=instance)
return instance
class CategoryForm(forms.ModelForm):
class Meta:
fields = ('name', )

Also available in: Unified diff