Posts Api

class api.posts.permissions.IsImageRelatedToCommentPermission[source]

Bases: BasePermission

Check if is image of comment related to requested user

has_object_permission(request: Request, view: View, obj: Any) bool[source]

Return True if permission is granted, False otherwise.

class api.posts.permissions.IsOwnerOrReadOnly[source]

Bases: BasePermission

Custom permission to only allow owners of an object to edit it. All users can read.

has_object_permission(request: Request, view: View, obj: Any) bool[source]

Return True if permission is granted, False otherwise.

owner_attributes: List[str] = ['author', 'post.author']
exception api.posts.exceptions.AlreadyAddedToFavoritesAPIException(detail=None, code=None)[source]

Bases: APIException

Already 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: APIException

Already 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: APIException

Selected 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: APIException

Comment limit exception

default_code = 'comment_image_limit'
default_detail = 'Comment has limit on images. You can add maximum 7'
status_code = 400
exception api.posts.exceptions.PostUnavailableForCommentingAPIException(detail=None, code=None)[source]

Bases: APIException

Selected categories for post are don’t exist or unavailable

default_code = 'post_unavailable_for_commenting'
default_detail = 'Post is unavailable for commenting'
status_code = 400
exception api.posts.exceptions.TooManyCategoriesExceptionAPIException(detail=None, code=None)[source]

Bases: APIException

Post 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: APIException

Post 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: APIException

User 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: APIException

User 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: ModelSerializer

Serializer 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: ModelSerializer

Serializer for create comment

class api.posts.serializers.CommentSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Serializer 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.'}
validate(attrs: Dict[str, Any]) Dict[str, Any][source]
class api.posts.serializers.FavoriteSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

to_representation(instance)[source]

Object instance -> Dict of primitive datatypes.

class api.posts.serializers.MediaSerializer(*args, **kwargs)[source]

Bases: Serializer

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.'}
validate(data: Dict[str, Any])[source]
class api.posts.serializers.PostMediaContentSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Test post media serializer

clip_validators = [<apps.posts.validators.VideoResolutionValidator object>, <apps.posts.validators.VideoDurationValidator object>]
content_type: str
default_error_messages = {'unsupported_extension': 'Unsupported extension format.'}
get_type_of_content(file) str[source]
image_validators = [<apps.posts.validators.FileSizeValidator object>, <apps.posts.validators.ImageResolutionValidator object>]
validate(data: Dict[str, Any]) Dict[str, Any][source]
validate_original(value) Dict[str, Any][source]
video_validators = [<apps.posts.validators.FileSizeValidator object>]
class api.posts.serializers.PostMediaSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

class api.posts.serializers.PostNotificationSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Post notification serializer

static get_preview(obj: Post) str | None[source]
class api.posts.serializers.PostSerializer(*args, **kwargs)[source]

Bases: ModelSerializer, MediaSerializer

tags: SlugRelatedField
to_internal_value(data)[source]

Dict of native values <- Dict of primitive datatypes.

to_representation(instance)[source]

Object instance -> Dict of primitive datatypes.

update(instance, validated_data)[source]
class api.posts.serializers.UpdateCommentSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Serializer for update comment

update(instance: Comment, validated_data: Dict[str, Any]) Comment[source]
class api.posts.serializers.WebhookPostSerializer(*args, **kwargs)[source]

Bases: Serializer

Webhook post serializer

static formatted_path(value: str)[source]
validate_upload_preview_path(value: str)[source]
validate_upload_video_path(value: str)[source]
class api.posts.pagination.SearchPagination[source]

Bases: LimitOffsetPagination

A 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: ListAPIView

Base 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'>]
post(request, *args, **kwargs)[source]
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(request, pk, *args, **kwargs)[source]
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

delete(request, *args, **kwargs)[source]
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
create(request, *args, **kwargs)[source]
description = None
detail = None
get_post_object() Post[source]
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']
list(request: Request, *args: Any, **kwargs: Any) Response[source]
name = None
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
remove(request, *args, **kwargs)[source]
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

following(request, *args, **kwargs)[source]
for_you(request, *args, **kwargs)[source]
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']
list(request, *args, **kwargs)[source]
name = None
pagination_class

alias of SearchPagination

perform_destroy(instance: Post) None[source]
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

perform_create(serializer)[source]
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: GenericAPIView

Like post api view

model_name = 'Like'
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
post(request, *args, **kwargs)[source]

Post method

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'>]
post(request, *args, **kwargs)[source]
queryset = NotDeletedQuerySet
serializer_class = None
service_class

alias of PostService

subtag = 'like'
tags = ['Posts']
class api.posts.views.UpdateDeleteCommentAPIView(**kwargs)[source]

Bases: RetrieveUpdateDestroyAPIView

perform_destroy(instance: Comment) None[source]
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: GenericAPIView

Upload 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: BasePostListAPIView

List 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: BasePostListAPIView

List 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: BasePostListAPIView

List 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: GenericAPIView

Process webhook api view

permission_classes = [<class 'rest_framework.permissions.AllowAny'>]
post(request, *args, **kwargs)[source]
queryset = QuerySet
serializer_class

alias of WebhookPostSerializer

service_class

alias of PostService

class api.posts.filters.ElasticsearchFilter[source]

Bases: BaseFilterBackend

Filter for performing search using Elasticsearch. Executes search on multiple fields with different weights.

construct_query(search_param)[source]

Constructs a combined Elasticsearch query from various parts.

Parameters:

search_param – The search parameter entered by the user.

Returns:

A combined Elasticsearch query.

filter_queryset(request, queryset, view)[source]

Filters a QuerySet based on the search parameters in the request.

Parameters:
  • request – HTTP request object.

  • queryset – Initial QuerySet.

  • view – The view that calls this method.

Returns:

Updated QuerySet.

class api.posts.filters.FollowingPostsFilter(field_name=None, lookup_expr=None, *, label=None, method=None, distinct=False, exclude=False, **kwargs)[source]

Bases: BooleanFilter

A filter for selecting posts whose authors are in the list to which the user is subscribed.

filter(qs, value)[source]
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>}