From e4337cef1d258db1eff216bf7314cf1612224d10 Mon Sep 17 00:00:00 2001 From: Bruno Tikami Date: Fri, 19 Feb 2016 11:00:35 -0200 Subject: [PATCH] ADDED: to validate if either a valid user or a valid email is provided when saving instances --- helpdesk/forms.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index b766ceb6..75367e19 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -540,6 +540,16 @@ class TicketCCForm(forms.ModelForm): model = TicketCC exclude = ('ticket',) + def clean(self): + + cleaned_data = super(TicketCCForm, self).clean() + + user = cleaned_data.get('user', None) + email = cleaned_data.get('email', '') + + if user is None and len(email) == 0: + raise forms.ValidationError(_('When you add somebody on Cc, you must provided either an User or a valid email.')) + class TicketDependencyForm(forms.ModelForm): class Meta: model = TicketDependency