aboutsummaryrefslogtreecommitdiffstats
path: root/rrs/admin.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2018-04-18 16:30:00 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2018-05-04 23:57:53 +1200
commit50f7c7036a4872f84a34dc30ce4bcebb6cc7ac66 (patch)
tree8f203842ca6cf4009b07515002072226b44120a3 /rrs/admin.py
parente071ebab294778a9197811b921ec458a61be7e7d (diff)
downloadopenembedded-core-contrib-50f7c7036a4872f84a34dc30ce4bcebb6cc7ac66.tar.gz
rrs: admin: validate that email address fields are set
If automated emails are enabled, we need to ensure that the other email fields are populated, so validate that. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'rrs/admin.py')
-rw-r--r--rrs/admin.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/rrs/admin.py b/rrs/admin.py
index 682a5a6c04..8176b8ad95 100644
--- a/rrs/admin.py
+++ b/rrs/admin.py
@@ -8,6 +8,7 @@ from django.utils.functional import curry
from django.contrib import admin
from django.contrib.admin import DateFieldListFilter
+from django import forms
from django.forms.models import BaseInlineFormSet
from django.core.exceptions import ValidationError
@@ -72,8 +73,33 @@ class MaintenancePlanLayerBranchInline(admin.StackedInline):
min_num = 1
extra = 0
+class MaintenancePlanAdminForm(forms.ModelForm):
+ model = MaintenancePlan
+
+ def clean_email_to(self):
+ val = self.cleaned_data['email_to']
+ if self.cleaned_data['email_enabled']:
+ if not val:
+ raise ValidationError('To email address must be specified if emails are enabled')
+ return val
+
+ def clean_email_from(self):
+ val = self.cleaned_data['email_from']
+ if self.cleaned_data['email_enabled']:
+ if not val:
+ raise ValidationError('From email address must be specified if emails are enabled')
+ return val
+
+ def clean_email_subject(self):
+ val = self.cleaned_data['email_subject']
+ if self.cleaned_data['email_enabled']:
+ if not val:
+ raise ValidationError('Email subject must be specified if emails are enabled')
+ return val
+
class MaintenancePlanAdmin(admin.ModelAdmin):
model = MaintenancePlan
+ form = MaintenancePlanAdminForm
inlines = [
MaintenancePlanLayerBranchInline,
]