def clean_message(self): if akismet_is_valid(self.request, self.cleaned_data['message'], self.cleaned_data['email']): return self.cleaned_data['message'] else: raise forms.ValidationError('Spam attempt detected!')
def clean(self): cleaned_data = self.cleaned_data akismet_status = False if self.request.user.is_authenticated(): akismet_status = akismet_is_valid(self.request, cleaned_data.get('comment')) elif 'email' in cleaned_data and 'comment' in cleaned_data: akismet_status = akismet_is_valid(self.request, cleaned_data.get('comment'), cleaned_data.get('email'), cleaned_data.get('website')) # todo: The error is actually not displayed. # Note to self: the string "test" will FAIL the validation if not akismet_status: self._errors['comment'] = forms.ValidationError('Spam attempt detected!') if 'comment' in cleaned_data: del cleaned_data['comment'] return cleaned_data