Posts Api¶
- class api.posts.permissions.IsImageRelatedToCommentPermission[source]¶
Bases:
BasePermissionCheck if is image of comment related to requested user
- class api.posts.permissions.IsOwnerOrReadOnly[source]¶
Bases:
BasePermissionCustom permission to only allow owners of an object to edit it. All users can read.
- exception api.posts.exceptions.AlreadyAddedToFavoritesAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionAlready has post in favorites
- default_code = 'post_already_added_to_favorites'¶
- default_detail = 'You already added to favorites this post'¶
- status_code = 400¶
- exception api.posts.exceptions.AlreadyLikedPostAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionAlready liked post
- default_code = 'post_already_liked'¶
- default_detail = 'You already liked this post'¶
- status_code = 400¶
- exception api.posts.exceptions.CategoriesDontExistAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionSelected categories for post are don’t exist or unavailable
- default_code = 'categories_dont_exist'¶
- default_detail = 'Selected categories for post are do not exist or unavailable'¶
- status_code = 400¶
- exception api.posts.exceptions.CommentLimitImageAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionComment limit exception
- default_code = 'comment_image_limit'¶
- default_detail = 'Comment has limit on images. You can add maximum 7'¶
- status_code = 400¶
Bases:
APIExceptionSelected categories for post are don’t exist or unavailable
- exception api.posts.exceptions.TooManyCategoriesExceptionAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionPost contains more categories than allowed by the limits.
- default_code = 'too_many_categories'¶
- default_detail = 'Post contains more categories than allowed by the limits.'¶
- status_code = 400¶
- exception api.posts.exceptions.TooManyLinkedMediaAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionPost contains more media than allowed by the limits.
- default_code = 'media_count'¶
- default_detail = 'Post contains more media than allowed by the limits'¶
- status_code = 400¶
- exception api.posts.exceptions.UserNotHasThisPostInFavoritesAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionUser not like this post
- default_code = 'post_in_not_in_favorites'¶
- default_detail = "You're don't have this post in favorites, you can't remove it from that"¶
- status_code = 400¶
- exception api.posts.exceptions.UserNotLikeThisPostAPIException(detail=None, code=None)[source]¶
Bases:
APIExceptionUser not like this post
- default_code = 'not_liked_post'¶
- default_detail = "You're not liked this post you can't unlike"¶
- status_code = 400¶
- class api.posts.serializers.CommentImageSerilizer(*args, **kwargs)[source]¶
Bases:
ModelSerializerSerializer for comment image serializer
- create(validated_data: Dict[str, Any]) CommentImage[source]¶
We have a bit of extra checking around this in order to provide descriptive messages when something goes wrong, but this method is essentially just:
return ExampleModel.objects.create(**validated_data)
If there are many to many fields present on the instance then they cannot be set until the model is instantiated, in which case the implementation is like so:
example_relationship = validated_data.pop(‘example_relationship’) instance = ExampleModel.objects.create(**validated_data) instance.example_relationship = example_relationship return instance
The default implementation also does not handle nested relationships. If you want to support writable nested relationships you’ll need to write an explicit .create() method.
- class api.posts.serializers.CommentListSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerSerializer for create comment
- class api.posts.serializers.CommentSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerSerializer for create comment
- static create(validated_data) Comment[source]¶
We have a bit of extra checking around this in order to provide descriptive messages when something goes wrong, but this method is essentially just:
return ExampleModel.objects.create(**validated_data)
If there are many to many fields present on the instance then they cannot be set until the model is instantiated, in which case the implementation is like so:
example_relationship = validated_data.pop(‘example_relationship’) instance = ExampleModel.objects.create(**validated_data) instance.example_relationship = example_relationship return instance
The default implementation also does not handle nested relationships. If you want to support writable nested relationships you’ll need to write an explicit .create() method.
- default_error_messages = {'cannot_be_empty': 'Comment cannot be empty. Please feel text or add image.'}¶
- class api.posts.serializers.PostContentsSerializer(*args, **kwargs)[source]¶
Bases:
Serializer- default_errors_messages = {'content_video_invalid': 'Unable to upload more than 1 video.', 'max_content_items': 'Content items cannot be bigger than 10 items.', 'mix_content_error': 'Unable to upload video and image together.'}¶
- class api.posts.serializers.PostMediaContentSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerTest post media serializer
- clip_validators = [<apps.posts.validators.VideoResolutionValidator object>, <apps.posts.validators.VideoDurationValidator object>]¶
- default_error_messages = {'unsupported_extension': 'Unsupported extension format.'}¶
- image_validators = [<apps.posts.validators.FileSizeValidator object>, <apps.posts.validators.ImageResolutionValidator object>]¶
- video_validators = [<apps.posts.validators.FileSizeValidator object>]¶
- class api.posts.serializers.PostNotificationSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerPost notification serializer
- class api.posts.serializers.PostSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializer,MediaSerializer- tags: SlugRelatedField¶
- class api.posts.serializers.UpdateCommentSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerSerializer for update comment
- class api.posts.serializers.WebhookPostSerializer(*args, **kwargs)[source]¶
Bases:
SerializerWebhook post serializer
- class api.posts.pagination.SearchPagination[source]¶
Bases:
LimitOffsetPaginationA custom pagination class that paginates Elasticsearch querysets. Uses custom offset and limit query parameters.
- get_count(queryset: QuerySet | Sequence) int[source]¶
Get the count of the queryset. If the queryset has a search_count attribute, use it as the count.
- Args:
queryset: The queryset to count.
- Returns:
The count of the queryset.
- paginate_queryset(queryset, request, view=None)[source]¶
Paginate a queryset if a search parameter is present in the request.
- Args:
queryset: The queryset to paginate. request: The HTTP request object. view: The view associated with the request.
- Returns:
The paginated queryset or the original queryset if search parameter is present.
- class api.posts.views.BasePostListAPIView(**kwargs)[source]¶
Bases:
ListAPIViewBase ListAPIView for Posts
- http_method_names = ['get']¶
- permission_classes = [<class 'rest_framework.permissions.AllowAny'>]¶
- serializer_class¶
alias of
PostSerializer
- tags = ['Posts']¶
- class api.posts.views.CommentImageAPIView(**kwargs)[source]¶
Bases:
GenericAPIView- model_name = 'Comment Image'¶
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>, <class 'api.posts.permissions.IsOwnerOrReadOnly'>]¶
- queryset = NotDeletedQuerySet¶
- serializer_class¶
alias of
CommentImageSerilizer
- service_class¶
alias of
CommentService
- subtag = 'comment'¶
- tags = ['Posts']¶
- class api.posts.views.CommentsPostAPIView(**kwargs)[source]¶
Bases:
GenericAPIView- get_queryset(pk)[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- queryset = NotDeletedQuerySet¶
- serializer_class¶
alias of
CommentListSerializer
- class api.posts.views.DeleteCommentImageAPIView(**kwargs)[source]¶
Bases:
GenericAPIView- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>, <class 'api.posts.permissions.IsImageRelatedToCommentPermission'>]¶
- queryset = NotDeletedCommentImageQuerySet¶
- service_class¶
alias of
CommentImageService
- subtag = 'comment'¶
- tags = ['Posts']¶
- class api.posts.views.FavoriteViewSet(**kwargs)[source]¶
Bases:
ListModelMixin,CustomGenericViewSet- basename = None¶
- description = None¶
- detail = None¶
- get_queryset() QuerySet[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- http_method_names = ['get', 'post', 'delete']¶
- name = None¶
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- serializer_class¶
alias of
FavoriteSerializer
- subtag = 'favorites'¶
- suffix = None¶
- tags = ['Posts']¶
- class api.posts.views.PostAPIViewSet(**kwargs)[source]¶
Bases:
CustomModelViewSet- basename = None¶
- description = None¶
- detail = None¶
- filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'api.posts.filters.ElasticsearchFilter'>]¶
- filterset_class¶
alias of
PostFilter
- get_queryset() QuerySet[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- http_method_names = ['get', 'post', 'put', 'patch', 'delete']¶
- name = None¶
- pagination_class¶
alias of
SearchPagination
- permission_classes = [<class 'api.posts.permissions.IsOwnerOrReadOnly'>]¶
- retrieve(request: Request, *args: Any, **kwargs: Any) Response[source]¶
Retrieve post and add view to post if user didn’t see this post before
- serializer_class¶
alias of
PostSerializer
- service_class¶
alias of
PostService
- suffix = None¶
- tags = ['Posts']¶
- class api.posts.views.PostCommentAPIView(**kwargs)[source]¶
Bases:
CreateAPIView- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- queryset = NotDeletedQuerySet¶
- serializer_class¶
alias of
CommentSerializer
- service_class¶
alias of
CommentService
- subtag = 'comment'¶
- tags = ['Posts']¶
- class api.posts.views.PostLikeAPIView(**kwargs)[source]¶
Bases:
GenericAPIViewLike post api view
- model_name = 'Like'¶
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- queryset = NotDeletedQuerySet¶
- serializer_class = None¶
- service_class¶
alias of
PostService
- subtag = 'like'¶
- tags = ['Posts']¶
- class api.posts.views.PostMediaViewSet(**kwargs)[source]¶
Bases:
ModelViewSet- basename = None¶
- description = None¶
- detail = None¶
- http_method_names = ['get', 'put', 'patch', 'delete']¶
- model_name = 'Media'¶
- name = None¶
- permission_classes = [<class 'api.posts.permissions.IsOwnerOrReadOnly'>]¶
- queryset = QuerySet¶
- serializer_class¶
alias of
PostMediaSerializer
- subtag = 'media'¶
- suffix = None¶
- tags = ['Posts']¶
- class api.posts.views.PostUnLikeAPIView(**kwargs)[source]¶
Bases:
GenericAPIView- get_serializer_class()[source]¶
Return the class to use for the serializer. Defaults to using self.serializer_class.
You may want to override this if you need to provide different serializations depending on the incoming request.
(Eg. admins get full serialization, others get basic serialization)
- model_name = 'Like'¶
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- queryset = NotDeletedQuerySet¶
- serializer_class = None¶
- service_class¶
alias of
PostService
- subtag = 'like'¶
- tags = ['Posts']¶
- class api.posts.views.UpdateDeleteCommentAPIView(**kwargs)[source]¶
Bases:
RetrieveUpdateDestroyAPIView- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>, <class 'api.posts.permissions.IsOwnerOrReadOnly'>]¶
- queryset = NotDeletedQuerySet¶
- serializer_class¶
alias of
UpdateCommentSerializer
- service_class¶
alias of
CommentService
- subtag = 'comment'¶
- tags = ['Posts']¶
- class api.posts.views.UploadPostAPIView(**kwargs)[source]¶
Bases:
GenericAPIViewUpload post api view
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- post(request: Request, *args: Any, **kwargs: Any) Response[source]¶
Upload media with createting post
- queryset = NotDeletedQuerySet¶
- serializer_class¶
alias of
PostContentsSerializer
- service_class¶
alias of
PostCreationService
- class api.posts.views.UsersLikedPostsListAPIView(**kwargs)[source]¶
Bases:
BasePostListAPIViewList of users liked posts
- get_queryset() QuerySet[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- class api.posts.views.UsersPostsListAPIView(**kwargs)[source]¶
Bases:
BasePostListAPIViewList of particular user posts
- get_queryset() QuerySet[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- class api.posts.views.UsersPrivatePostsListAPIView(**kwargs)[source]¶
Bases:
BasePostListAPIViewList of users private users posts
- get_queryset() QuerySet[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]¶
- class api.posts.views.WebhookPostMediaAPIView(**kwargs)[source]¶
Bases:
GenericAPIViewProcess webhook api view
- permission_classes = [<class 'rest_framework.permissions.AllowAny'>]¶
- queryset = QuerySet¶
- serializer_class¶
alias of
WebhookPostSerializer
- service_class¶
alias of
PostService
- class api.posts.filters.ElasticsearchFilter[source]¶
Bases:
BaseFilterBackendFilter for performing search using Elasticsearch. Executes search on multiple fields with different weights.
- class api.posts.filters.FollowingPostsFilter(field_name=None, lookup_expr=None, *, label=None, method=None, distinct=False, exclude=False, **kwargs)[source]¶
Bases:
BooleanFilterA filter for selecting posts whose authors are in the list to which the user is subscribed.
- class api.posts.filters.PostFilter(data=None, queryset=None, *, request=None, prefix=None)[source]¶
Bases:
FilterSet- base_filters = {'categories': <django_filters.filters.ModelMultipleChoiceFilter object>, 'following_posts': <api.posts.filters.FollowingPostsFilter object>, 'tags': <django_filters.filters.ModelMultipleChoiceFilter object>}¶
- declared_filters = {'categories': <django_filters.filters.ModelMultipleChoiceFilter object>, 'following_posts': <api.posts.filters.FollowingPostsFilter object>, 'tags': <django_filters.filters.ModelMultipleChoiceFilter object>}¶