def create_version_for_upload(addon, upload, channel): fileupload_exists = addon.fileupload_set.filter( created__gt=upload.created, version=upload.version).exists() version_exists = Version.unfiltered.filter( addon=addon, version=upload.version).exists() if (fileupload_exists or version_exists): log.info('Skipping Version creation for {upload_uuid} that would ' ' cause duplicate version'.format(upload_uuid=upload.uuid)) else: # Import loop. from olympia.devhub.utils import add_dynamic_theme_tag from olympia.devhub.views import auto_sign_version log.info('Creating version for {upload_uuid} that passed ' 'validation'.format(upload_uuid=upload.uuid)) # Note: if we somehow managed to get here with an invalid add-on, # parse_addon() will raise ValidationError and the task will fail # loudly in sentry. parsed_data = parse_addon(upload, addon, user=upload.user) version = Version.from_upload( upload, addon, [x[0] for x in amo.APPS_CHOICES], channel, parsed_data=parsed_data) # The add-on's status will be STATUS_NULL when its first version is # created because the version has no files when it gets added and it # gets flagged as invalid. We need to manually set the status. if (addon.status == amo.STATUS_NULL and channel == amo.RELEASE_CHANNEL_LISTED): addon.update(status=amo.STATUS_NOMINATED) auto_sign_version(version) add_dynamic_theme_tag(version)
def create_version_for_upload(addon, upload, channel): """Note this function is only used for API uploads.""" fileupload_exists = addon.fileupload_set.filter( created__gt=upload.created, version=upload.version).exists() version_exists = Version.unfiltered.filter( addon=addon, version=upload.version).exists() if (fileupload_exists or version_exists): log.info('Skipping Version creation for {upload_uuid} that would ' ' cause duplicate version'.format(upload_uuid=upload.uuid)) else: # Import loop. from olympia.devhub.utils import add_dynamic_theme_tag from olympia.devhub.views import auto_sign_version log.info('Creating version for {upload_uuid} that passed ' 'validation'.format(upload_uuid=upload.uuid)) # Note: if we somehow managed to get here with an invalid add-on, # parse_addon() will raise ValidationError and the task will fail # loudly in sentry. parsed_data = parse_addon(upload, addon, user=upload.user) version = Version.from_upload( upload, addon, [x[0] for x in amo.APPS_CHOICES], channel, parsed_data=parsed_data) # The add-on's status will be STATUS_NULL when its first version is # created because the version has no files when it gets added and it # gets flagged as invalid. We need to manually set the status. if (addon.status == amo.STATUS_NULL and channel == amo.RELEASE_CHANNEL_LISTED): addon.update(status=amo.STATUS_NOMINATED) auto_sign_version(version) add_dynamic_theme_tag(version)