diff --git a/openbook_common/serializers.py b/openbook_common/serializers.py index 6c482585..25b2f205 100644 --- a/openbook_common/serializers.py +++ b/openbook_common/serializers.py @@ -10,7 +10,7 @@ from openbook_communities.validators import community_name_characters_validator, community_name_exists from openbook_follows.models import FollowRequest, Follow from openbook_hashtags.models import Hashtag -from openbook_posts.models import PostReaction, PostImage +from openbook_posts.models import PostReaction, PostImage, PostLink class CommonEmojiSerializer(serializers.ModelSerializer): @@ -65,6 +65,7 @@ class Meta: 'keyword_description' ) + class CommonPostReactionEmojiSerializer(serializers.ModelSerializer): class Meta: model = Emoji @@ -151,6 +152,15 @@ class Meta: ) +class CommonPostLinkSerializer(serializers.ModelSerializer): + class Meta: + model = PostLink + fields = ( + 'link', + 'has_preview' + ) + + class CommonCircleSerializer(serializers.ModelSerializer): class Meta: model = Circle diff --git a/openbook_posts/views/post/serializers.py b/openbook_posts/views/post/serializers.py index 5c05a877..fc7dc2d7 100644 --- a/openbook_posts/views/post/serializers.py +++ b/openbook_posts/views/post/serializers.py @@ -4,7 +4,8 @@ from openbook_auth.models import UserProfile, User from openbook_circles.models import Circle from openbook_common.models import Badge, Language -from openbook_common.serializers import CommonHashtagSerializer, CommonPublicUserSerializer +from openbook_common.serializers import CommonHashtagSerializer, CommonPublicUserSerializer, \ + CommonPostLinkSerializer from openbook_common.serializers_fields.post import PostCreatorField, PostReactionsEmojiCountField, ReactionField, \ CommentsCountField, CirclesField, PostIsMutedField, IsEncircledField from openbook_communities.models import CommunityMembership, Community @@ -129,15 +130,6 @@ class Meta: ) -class PostLinkSerializer(serializers.ModelSerializer): - class Meta: - model = PostLink - fields = ( - 'link', - 'has_preview' - ) - - class GetPostPostSerializer(serializers.ModelSerializer): creator = PostCreatorField(post_creator_serializer=CommonPublicUserSerializer, community_membership_serializer=CommunityMembershipSerializer) @@ -150,7 +142,7 @@ class GetPostPostSerializer(serializers.ModelSerializer): language = PostLanguageSerializer() is_encircled = IsEncircledField() hashtags = CommonHashtagSerializer(many=True) - links = PostLinkSerializer(many=True) + links = CommonPostLinkSerializer(many=True) class Meta: model = Post @@ -192,6 +184,7 @@ class EditPostSerializer(serializers.Serializer): class AuthenticatedUserEditPostSerializer(serializers.ModelSerializer): language = PostLanguageSerializer() hashtags = CommonHashtagSerializer(many=True) + links = CommonPostLinkSerializer(many=True) class Meta: model = Post @@ -201,7 +194,8 @@ class Meta: 'text', 'language', 'is_edited', - 'hashtags' + 'hashtags', + 'links' ) diff --git a/openbook_posts/views/posts/serializers.py b/openbook_posts/views/posts/serializers.py index 52622ba5..714f454a 100644 --- a/openbook_posts/views/posts/serializers.py +++ b/openbook_posts/views/posts/serializers.py @@ -5,7 +5,7 @@ from openbook_circles.models import Circle from openbook_circles.validators import circle_id_exists from openbook_common.models import Emoji, Badge -from openbook_common.serializers import CommonHashtagSerializer, CommonPublicUserSerializer +from openbook_common.serializers import CommonHashtagSerializer, CommonPublicUserSerializer, CommonPostLinkSerializer from openbook_common.serializers_fields.post import ReactionField, CommentsCountField, PostReactionsEmojiCountField, \ CirclesField, PostCreatorField, PostIsMutedField, IsEncircledField from openbook_common.serializers_fields.request import RestrictedImageFileSizeField, RestrictedFileSizeField @@ -13,7 +13,7 @@ from openbook_communities.models import Community, CommunityMembership from openbook_communities.serializers_fields import CommunityMembershipsField from openbook_lists.validators import list_id_exists -from openbook_posts.models import PostImage, Post, PostReaction, TopPost, TrendingPost, PostLink +from openbook_posts.models import PostImage, Post, PostReaction, TopPost, TrendingPost from openbook_posts.validators import post_text_validators @@ -183,15 +183,6 @@ class Meta: ) -class PostLinkSerializer(serializers.ModelSerializer): - class Meta: - model = PostLink - fields = ( - 'link', - 'has_preview' - ) - - class PostImageSerializer(serializers.ModelSerializer): image = serializers.ImageField(read_only=True, required=False, allow_empty_file=True) @@ -216,7 +207,7 @@ class AuthenticatedUserPostSerializer(serializers.ModelSerializer): language = PostLanguageSerializer() is_encircled = IsEncircledField() hashtags = CommonHashtagSerializer(many=True) - links = PostLinkSerializer(many=True) + links = CommonPostLinkSerializer(many=True) class Meta: model = Post @@ -277,7 +268,7 @@ class UnauthenticatedUserPostSerializer(serializers.ModelSerializer): comments_count = CommentsCountField() language = PostLanguageSerializer() hashtags = CommonHashtagSerializer(many=True) - links = PostLinkSerializer(many=True) + links = CommonPostLinkSerializer(many=True) class Meta: model = Post