Skip to content

Commit

Permalink
Add full update to scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevan Holdaway committed Feb 21, 2018
1 parent b281e6e commit 379c95b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions quipucords/api/scan/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ def create(self, validated_data):

return scan

@transaction.atomic
def update(self, instance, validated_data):
"""Update a scan."""
# If we ever add optional fields to Scan, we need to
# add logic here to clear them on full update even if they are
# not supplied.
self.check_for_existing_name(
name=validated_data.get('name'),
scan_id=instance.id)

instance.scan_type = validated_data.pop('scan_type', None)
instance.sources = validated_data.pop('sources', None)
options = validated_data.pop('options', None)
if options:
options = ScanOptions.objects.create(**options)
else:
options = ScanOptions()
instance.options = options
instance.save()

return instance

@staticmethod
def validate_sources(sources):
"""Make sure the source is present."""
Expand Down

0 comments on commit 379c95b

Please sign in to comment.