Chat

This package contains all models for the author and user chats

Attachment Map

class integreat_cms.cms.models.chat.attachment_map.AttachmentMap(*args, **kwargs)[source]

Bases: AbstractBaseModel

A model for a mapping a random hash to a Zammad attachment ID

Parameters:

Relationship fields:

Parameters:

user_chat (ForeignKey to UserChat) – User chat (related name: attachments)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <AttachmentMap: AttachmentMap object (id)>. It is used for logging.

Returns:

The canonical string representation of the attachment map

Return type:

str

integreat_cms.cms.models.chat.attachment_map.generate_random_hash() str[source]

Generate a random hash. Produces output of length 64.

Returns:

The generated random hash

Return type:

str

Chat Message

class integreat_cms.cms.models.chat.chat_message.ChatHistoryManager(*args, **kwargs)[source]

Bases: Manager

Custom manager for returning the chat history of the last x days (as configured in AUTHOR_CHAT_HISTORY_DAYS)

get_queryset() QuerySet[source]

Custom queryset with applied filters to return the chat messages of the last x days

Returns:

The QuerySet of the most recent chat history

Return type:

QuerySet

class integreat_cms.cms.models.chat.chat_message.ChatMessage(*args, **kwargs)[source]

Bases: AbstractBaseModel

A model for a message in the author chat

Parameters:

Relationship fields:

Parameters:

sender (ForeignKey to User) – Sender (related name: chat_messages)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <ChatMessage: ChatMessage object (id)>. It is used for logging.

Returns:

The canonical string representation of the chat message

Return type:

str

history = <integreat_cms.cms.models.chat.chat_message.ChatHistoryManager object>[source]

Django manager to access the ORM Use ChatMessage.objects.all() to fetch all objects.

A manager for the most recent chat history

objects = <django.db.models.Manager object>[source]

Django manager to access the ORM Use ChatMessage.objects.all() to fetch all objects.

The default manager

User Chat

class integreat_cms.cms.models.chat.user_chat.ABTester(*args, **kwargs)[source]

Bases: AbstractBaseModel

A helper model for keeping track of A/B testers for the chat feature

Parameters:

Relationship fields:

Parameters:

region (ForeignKey to Region) – Region (related name: abtester)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <ABTester: ABTester object (id)>. It is used for logging.

Returns:

The canonical string representation of the ab tester

Return type:

str

class integreat_cms.cms.models.chat.user_chat.UserChat(*args, **kwargs)[source]

Bases: AbstractBaseModel

A model for a user (app) chat, mapping a device ID to a Zammad ticket ID

Parameters:

Relationship fields:

Parameters:

Reverse relationships:

Parameters:

attachments (Reverse ForeignKey from AttachmentMap) – All attachments of this user chat (related name of user_chat)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <UserChat: UserChat object (id)>. It is used for logging.

Returns:

The canonical string representation of the user chat

Return type:

str

ratelimit_exceeded() bool[source]

Decide if the rate limit for this chat has been exceeded

Returns:

if the rate limit has been exceeded

Return type:

bool

record_hit() None[source]

Record the timestamp of accesses for ratelimiting purposes

Return type:

None

class integreat_cms.cms.models.chat.user_chat.UserChatManager(*args, **kwargs)[source]

Bases: Manager

custom manager providing function to get the current chat

current_chat(device_id: str, **kwargs: Any) UserChat[source]

Return only the newest (i.e. current) chat for a given device_id

Parameters:
  • device_id (str) – the device id for which we want the current chat

  • **kwargs (Any) – The supplied kwargs

Returns:

the current chat for the given device_id

Return type:

UserChat