diff --git a/program/serializers.py b/program/serializers.py index f1eda9b491b326c0ef4734a231846b14b27b695e..4b3ebba48d5b2b00434070916fcac75320f98dda 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -33,8 +33,6 @@ from program.models import ( CBA, Category, FundingCategory, - Host, - HostLink, Image, Language, License, @@ -42,6 +40,8 @@ from program.models import ( MusicFocus, Note, NoteLink, + Profile, + ProfileLink, RadioSettings, RRule, Schedule, @@ -118,7 +118,7 @@ class UserSerializer(serializers.ModelSerializer): permissions = serializers.SerializerMethodField() cba = CBASerializer(required=False) host_ids = serializers.PrimaryKeyRelatedField( - many=True, queryset=Host.objects.all(), required=False, source="hosts" + many=True, queryset=Profile.objects.all(), required=False, source="hosts" ) class Meta: @@ -265,12 +265,12 @@ class LicenseSerializer(serializers.ModelSerializer): ) -class HostLinkSerializer(serializers.ModelSerializer): +class ProfileLinkSerializer(serializers.ModelSerializer): type_id = serializers.PrimaryKeyRelatedField(queryset=LinkType.objects.all(), source="type") class Meta: fields = ("type_id", "url") - model = HostLink + model = ProfileLink class PPOIField(serializers.CharField): @@ -360,26 +360,26 @@ class ImageRenderSerializer(serializers.Serializer): height = serializers.IntegerField(required=False, min_value=1) -class HostSerializer(serializers.ModelSerializer): +class ProfileSerializer(serializers.ModelSerializer): image_id = serializers.PrimaryKeyRelatedField( allow_null=True, queryset=Image.objects.all(), required=False, source="image", - help_text="`Image` id of the host.", + help_text="`Image` id of the profile.", ) - links = HostLinkSerializer( - many=True, required=False, help_text="Array of `HostLink` objects. Can be empty." + links = ProfileLinkSerializer( + many=True, required=False, help_text="Array of `Link` objects. Can be empty." ) owner_ids = serializers.PrimaryKeyRelatedField( many=True, queryset=User.objects.all(), source="owners", - help_text="`User` id(s) identifying this host.", + help_text="User ID(s) that own this profile.", ) class Meta: - model = Host + model = Profile read_only_fields = ( "created_at", "created_by", @@ -399,7 +399,7 @@ class HostSerializer(serializers.ModelSerializer): def create(self, validated_data): """ - Create and return a new Host instance, given the validated data. + Create and return a new Profile instance, given the validated data. """ # optional nested objects @@ -411,21 +411,21 @@ class HostSerializer(serializers.ModelSerializer): # optional foreign key validated_data["image"] = validated_data.pop("image", None) - host = Host.objects.create( + profile = Profile.objects.create( created_by=self.context.get("request").user.username, **validated_data ) for link_data in links_data: - HostLink.objects.create(host=host, **link_data) + ProfileLink.objects.create(host=profile, **link_data) - host.owners.set(owners) + profile.owners.set(owners) - host.save() + profile.save() - return host + return profile def update(self, instance, validated_data): - """Update and return an existing Host instance, given the validated data.""" + """Update and return an existing Profile instance, given the validated data.""" user = self.context.get("request").user user_is_owner = user in instance.owners.all() @@ -535,9 +535,9 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): ) host_ids = serializers.PrimaryKeyRelatedField( many=True, - queryset=Host.objects.all(), + queryset=Profile.objects.all(), source="hosts", - help_text="`Host` IDs of this show.", + help_text="`Profile` IDs that host this show.", ) image_id = serializers.PrimaryKeyRelatedField( allow_null=True, @@ -552,7 +552,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): source="language", help_text="`Language` IDs of this show.", ) - links = HostLinkSerializer(many=True, required=False, help_text="Array of `Link` objects.") + links = ProfileLinkSerializer(many=True, required=False, help_text="Array of `Link` objects.") logo_id = serializers.PrimaryKeyRelatedField( allow_null=True, queryset=Image.objects.all(), @@ -1014,10 +1014,10 @@ tags_json_schema = {"type": "array", "items": {"type": "string"}} class NoteSerializer(serializers.ModelSerializer): contributor_ids = serializers.PrimaryKeyRelatedField( many=True, - queryset=Host.objects.all(), + queryset=Profile.objects.all(), required=False, source="contributors", - help_text="`Host` IDs that contributed to an episode.", + help_text="`Profile` IDs that contributed to this episode.", ) image_id = serializers.PrimaryKeyRelatedField( queryset=Image.objects.all(), @@ -1219,35 +1219,35 @@ class RadioSettingsSerializer(serializers.ModelSerializer): return float(values[0]), float(values[1]) aspect_ratios = { - "host.image": get_aspect_ratio(obj.host_image_aspect_ratio), "note.image": get_aspect_ratio(obj.note_image_aspect_ratio), + "profile.image": get_aspect_ratio(obj.profile_image_aspect_ratio), "show.image": get_aspect_ratio(obj.show_image_aspect_ratio), "show.logo": get_aspect_ratio(obj.show_logo_aspect_ratio), } return { - "host.image": { + "note.image": { "frame": { - "aspect_ratio": aspect_ratios["host.image"], - "shape": obj.host_image_shape, + "aspect_ratio": aspect_ratios["note.image"], + "shape": obj.profile_image_shape, } }, - "note.image": { + "profile.image": { "frame": { - "aspect_ratio": aspect_ratios["note.image"], - "shape": obj.host_image_shape, + "aspect_ratio": aspect_ratios["profile.image"], + "shape": obj.profile_image_shape, } }, "show.image": { "frame": { "aspect_ratio": aspect_ratios["show.image"], - "shape": obj.host_image_shape, + "shape": obj.profile_image_shape, } }, "show.logo": { "frame": { "aspect_ratio": aspect_ratios["show.logo"], - "shape": obj.host_image_shape, + "shape": obj.profile_image_shape, } }, }