Projet

Général

Profil

« Précédent | Suivant » 

Révision 1e3b89c6

Ajouté par Serghei Mihai (congés, retour 15/05) il y a plus de 9 ans

announce content length check if sms channel prefered

Voir les différences:

corbo/forms.py
23 23
        self.fields['transport_channel'].initial = [b.channel for \
24 24
                                                    b in self.instance.broadcast_set.all()]
25 25

  
26
    def clean_transport_channel(self):
27
        channels = self.cleaned_data['transport_channel']
28
        limit = 130
29
        if 'sms' in channels and \
30
           len(self.cleaned_data['text']) > limit:
31
            raise forms.ValidationError(_('Announce content exceeds %s chars'
32
                                          ' and cannot be sent by SMS' % limit))
33
        return channels
34

  
26 35
    def save(self, *args, **kwargs):
27 36
        instance = super(AnnounceForm, self).save(*args, **kwargs)
28 37
        if instance:
38
            print "CD: %s" % self.cleaned_data
29 39
            channels = self.cleaned_data['transport_channel']
30 40
            for channel in channels:
31 41
                Broadcast.objects.get_or_create(announce=instance,
corbo/views.py
34 34
    form_class = AnnounceForm
35 35

  
36 36
    def get_success_url(self):
37
        return self.request.META['HTTP_REFERER'] or \
38
            reverse('manage') + '?' + urlencode({'category': self.object.category.id})
37
        return reverse('manage') + '?' + urlencode({'category': self.object.category.id})
39 38

  
40 39
edit_announce = AnnounceEditView.as_view()
41 40

  

Formats disponibles : Unified diff