Better handle notification template patches for notification_type

This makes it so patches don't require the notification_type to be present
This commit is contained in:
Akita Noek
2016-06-27 09:40:39 -04:00
parent 9494db583d
commit 2b323fc24e
2 changed files with 15 additions and 4 deletions

View File

@@ -2435,9 +2435,16 @@ class NotificationTemplateSerializer(BaseSerializer):
def validate(self, attrs):
from awx.api.views import NotificationTemplateDetail
if 'notification_type' not in attrs:
notification_type = None
if 'notification_type' in attrs:
notification_type = attrs['notification_type']
elif self.instance:
notification_type = self.instance.notification_type
if not notification_type:
raise serializers.ValidationError('Missing required fields for Notification Configuration: notification_type')
notification_class = NotificationTemplate.CLASS_FOR_NOTIFICATION_TYPE[attrs['notification_type']]
notification_class = NotificationTemplate.CLASS_FOR_NOTIFICATION_TYPE[notification_type]
missing_fields = []
incorrect_type_fields = []
error_list = []