示例#1
0
class MultipleArtifactContentSerializer(BaseContentSerializer):
    artifacts = fields.ContentArtifactsField(
        help_text=_("A dict mapping relative paths inside the Content to the corresponding"
                    "Artifact URLs. E.g.: {'relative/path': "
                    "'/artifacts/1/'"),
    )

    @transaction.atomic
    def create(self, validated_data):
        """
        Create the content and associate it with all its Artifacts.

        Args:
            validated_data (dict): Data to save to the database
        """
        artifacts = validated_data.pop('artifacts')
        content = self.Meta.model.objects.create(**validated_data)
        for relative_path, artifact in artifacts.items():
            models.ContentArtifact.objects.create(
                artifact=artifact,
                content=content,
                relative_path=relative_path,
            )
        return content

    class Meta:
        model = models.Content
        fields = BaseContentSerializer.Meta.fields + ('artifacts',)
示例#2
0
文件: content.py 项目: JayZ12138/pulp
class MultipleArtifactContentSerializer(BaseContentSerializer):
    _artifacts = fields.ContentArtifactsField(help_text=_(
        "A dict mapping relative paths inside the Content to the corresponding"
        "Artifact URLs. E.g.: {'relative/path': "
        "'/artifacts/1/'"), )

    class Meta:
        model = models.Content
        fields = base.MasterModelSerializer.Meta.fields + ('_artifacts', )
示例#3
0
class ContentSerializer(base.MasterModelSerializer):
    _href = base.DetailIdentityField()

    notes = base.GenericKeyValueRelatedField(
        help_text=_('A mapping of string keys to string values, for storing notes on this object.'),
        required=False
    )

    artifacts = fields.ContentArtifactsField(
        help_text=_("A dict mapping relative paths inside the Content to the corresponding"
                    "Artifact URLs. E.g.: {'relative/path': "
                    "'http://localhost/full_artifact_path'}"),
    )

    class Meta:
        model = models.Content
        fields = base.MasterModelSerializer.Meta.fields + ('notes', 'artifacts')