chat.views#

Views for conversations, messages and other related entities.

Module Contents#

Classes#

ConversationViewSet

API endpoint that allows access to conversations.

ConversationMessagesViewSet

API endpoint that allows access to conversation messages.

BotListSerializer

Bot list representation.

BotsViewSet

API endpoint that allows access to the list of available bots.

LimitsViewSet

API endpoint that allows access to the chat limits.

class ConversationViewSet(**kwargs)#

Bases: rest_framework.mixins.CreateModelMixin, rest_framework.mixins.RetrieveModelMixin, rest_framework.mixins.ListModelMixin, rest_framework.viewsets.GenericViewSet

API endpoint that allows access to conversations.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class Meta#
read_only_fields = ['participants']#
queryset#
get_serializer_class()#

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)

Return type:

type

list(request, *args, **kwargs)#
Parameters:
  • request (rest_framework.request.Request) –

  • args (Any) –

  • kwargs (Any) –

Return type:

rest_framework.response.Response

retrieve(request, *args, **kwargs)#
Parameters:
  • request (rest_framework.request.Request) –

  • args (Any) –

  • kwargs (Any) –

Return type:

rest_framework.response.Response

perform_create(serializer, **kwargs)#
Parameters:
  • serializer (rest_framework.serializers.Serializer) –

  • kwargs (Any) –

Return type:

None

join(request, pk=None)#

Join a conversation.

Raises:
  • ValidationError – if some validation fails

  • PermissionDenied – if the user tries to join someone else’s conversation

Parameters:
  • request (rest_framework.request.Request) – the HTTP request

  • pk (Any | None) – not used

Returns:

the HTTP response

Return type:

rest_framework.response.Response

class ConversationMessagesViewSet(**kwargs)#

Bases: rest_framework.mixins.CreateModelMixin, rest_framework.mixins.ListModelMixin, rest_framework.viewsets.GenericViewSet

API endpoint that allows access to conversation messages.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

serializer_class#
parser_classes#
create(request, *args, **kwargs)#
Parameters:
  • request (rest_framework.request.Request) –

  • args (Any) –

  • kwargs (Any) –

Return type:

django.db.models.Model

_get_participant()#
Return type:

Participant | None

get_queryset()#

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)

Return type:

collections.abc.Iterable[Message]

class BotListSerializer(instance=None, data=empty, **kwargs)#

Bases: rest_framework.serializers.Serializer

Bot list representation.

When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.

results#
get_results(bots)#

Return the list of bots given in the argument.

Parameters:

bots (list[str]) – list of bots

Returns:

the same list (this is an identity function)

Return type:

list[str]

class BotsViewSet(**kwargs)#

Bases: rest_framework.views.APIView

API endpoint that allows access to the list of available bots.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

serializer_class#
action = 'list'#
get(request, *args, **kwargs)#

Return the list of bots.

Parameters:
  • request (rest_framework.request.Request) – ignored

  • args (Any) – ignored

  • kwargs (Any) – ignored

Returns:

a list of bot names

Return type:

rest_framework.response.Response

class LimitsViewSet(**kwargs)#

Bases: rest_framework.views.APIView

API endpoint that allows access to the chat limits.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

serializer_class#
action = 'list'#
get(request, *args, **kwargs)#

Return the chat limits.

Parameters:
  • request (rest_framework.request.Request) – ignored

  • args (Any) – ignored

  • kwargs (Any) – ignored

Returns:

a dictionary mapping file types to the maximum number of bytes

Return type:

rest_framework.response.Response