Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Expose pulp3_repository_version on pulp2content if it is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
ipanova committed Apr 28, 2020
1 parent aa1b970 commit 24a4133
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/6580.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose pulp3_repository_version on pulp2content if it is available.
27 changes: 25 additions & 2 deletions pulp_2to3_migration/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Pulp2ContentSerializer(ModelSerializer):
A serializer for the Pulp2Content model
"""
pulp_href = IdentityField(
view_name='migration-plans-detail'
view_name='pulp2content-detail'
)
pulp2_id = serializers.CharField(max_length=255)
pulp2_content_type_id = serializers.CharField(max_length=255)
Expand All @@ -140,10 +140,33 @@ class Pulp2ContentSerializer(ModelSerializer):
required=False, allow_null=True, queryset=Pulp2Content.objects.all()
)

pulp3_repository_version = serializers.SerializerMethodField(read_only=True)

@swagger_serializer_method(serializer_or_field=serializers.CharField)
def get_pulp3_repository_version(self, obj):
"""
Get pulp3_repository_version href from pulp2repo if available
"""
pulp2_repo = obj.pulp2_repo
if pulp2_repo and pulp2_repo.is_migrated:
pulp3_repo_href = get_pulp_href(pulp2_repo.pulp3_repository)
pulp3_repo_version = pulp2_repo.pulp3_repository_version
return f"{pulp3_repo_href}versions/{pulp3_repo_version.number}/"

def to_representation(self, instance):
"""
Do not serialize pulp3_repository_version if it is null.
"""
result = super(Pulp2ContentSerializer, self).to_representation(instance)
if not result.get('pulp3_repository_version'):
del result['pulp3_repository_version']
return result

class Meta:
fields = ModelSerializer.Meta.fields + ('pulp2_id', 'pulp2_content_type_id',
'pulp2_last_updated', 'pulp2_storage_path',
'downloaded', 'pulp3_content')
'downloaded', 'pulp3_content',
'pulp3_repository_version')
model = Pulp2Content


Expand Down

0 comments on commit 24a4133

Please sign in to comment.