announce content length check if sms channel prefered

This commit is contained in:
Serghei Mihai 2015-01-28 00:10:10 +01:00
parent 46bbe5fe03
commit 1e3b89c6e5
2 changed files with 11 additions and 2 deletions

View File

@ -23,9 +23,19 @@ class AnnounceForm(forms.ModelForm):
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 = 130
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,

View File

@ -34,8 +34,7 @@ class AnnounceEditView(UpdateView):
form_class = AnnounceForm
def get_success_url(self):
return self.request.META['HTTP_REFERER'] or \
reverse('manage') + '?' + urlencode({'category': self.object.category.id})
return reverse('manage') + '?' + urlencode({'category': self.object.category.id})
edit_announce = AnnounceEditView.as_view()