diff --git a/openstack_dashboard/dashboards/project/images/images/forms.py b/openstack_dashboard/dashboards/project/images/images/forms.py index b80396b..dbf2006 100644 --- a/openstack_dashboard/dashboards/project/images/images/forms.py +++ b/openstack_dashboard/dashboards/project/images/images/forms.py @@ -60,8 +60,7 @@ class CreateImageForm(forms.SelfHandlingForm): 'data-source-url': _('Image Location'), 'ng-model': 'copyFrom', 'ng-change': - 'selectImageFormat(copyFrom)'}), - required=False) + 'selectImageFormat(copyFrom)'})) image_file = forms.FileField(label=_("Image File"), help_text=_("A local image to upload."), widget=forms.FileInput(attrs={ @@ -71,8 +70,7 @@ class CreateImageForm(forms.SelfHandlingForm): 'ng-model': 'imageFile', 'ng-change': 'selectImageFormat(imageFile.name)', - 'image-file-on-change': None}), - required=False) + 'image-file-on-change': None})) disk_format = forms.ChoiceField(label=_('Format'), choices=[], widget=forms.Select(attrs={ @@ -132,16 +130,19 @@ class CreateImageForm(forms.SelfHandlingForm): # The image_file key can be missing based on particular upload # conditions. Code defensively for it here... image_file = data.get('image_file', None) - image_url = data.get('copy_from', None) + copy_from = data.get('copy_from', None) - if not image_url and not image_file: - raise ValidationError( - _("A image or external image location must be specified.")) - elif image_url and image_file: + if image_file and copy_from: raise ValidationError( _("Can not specify both image and external image location.")) - else: - return data + elif image_file or copy_from: + # Since only one of the image_file and copy_from are considered, + # discard errors for the field that is not considered. Since such + # field should only be None, the main error we want to discard + # is the "required" error. + self._errors.pop('image_file' if copy_from else 'copy_form', None) + + return data def handle(self, request, data): # Glance does not really do anything with container_format at the