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:
id (BigAutoField) – Primary key: ID
random_hash (CharField) – Random hash
article_id (IntegerField) – Article id
attachment_id (IntegerField) – Attachment id
mime_type (CharField) – Mime type
Relationship fields:
- Parameters:
user_chat (
ForeignKey
toUserChat
) – User chat (related name:attachments
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- article_id[source]
Type:
IntegerField
Article id
- attachment_id[source]
Type:
IntegerField
Attachment id
- clean()[source]
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clean_fields(exclude=None)[source]
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
- full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- 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:
- id[source]
Type:
BigAutoField
Primary key: ID
- refresh_from_db(using=None, fields=None)[source]
Reload field values from the database.
By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.
Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.
When accessing deferred fields of an instance, the deferred loading of the field will call this method.
- save(force_insert=False, force_update=False, using=None, update_fields=None)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]
Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.
- serializable_value(field_name)[source]
Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.
Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.
- user_chat[source]
Type:
ForeignKey
toUserChat
User chat (related name:
attachments
)
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
)- abulk_create(objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None)[source]
- aggregate(*args, **kwargs)[source]
Return a dictionary containing the calculations (aggregation) over the current queryset.
If args is present the expression is passed as a kwarg using the Aggregate object’s default alias.
- aiterator(chunk_size=2000)[source]
An asynchronous iterator over the results from applying this QuerySet to the database.
- alias(*args, **kwargs)[source]
Return a query set with added aliases for extra data or aggregations.
- annotate(*args, **kwargs)[source]
Return a query set in which the returned objects have been annotated with extra data or aggregations.
- bulk_create(objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None)[source]
Insert each of the instances into the database. Do not call save() on each of the instances, do not send any pre/post_save signals, and do not set the primary key attribute if it is an autoincrement field (except if features.can_return_rows_from_bulk_insert=True). Multi-table models are not supported.
- bulk_update(objs, fields, batch_size=None)[source]
Update the given fields in each of the given objects in the database.
- complex_filter(filter_obj)[source]
Return a new QuerySet instance with filter_obj added to the filters.
filter_obj can be a Q object or a dictionary of keyword lookup arguments.
This exists to support framework features such as ‘limit_choices_to’, and usually it will be more natural to use other methods.
- count()[source]
Perform a SELECT COUNT() and return the number of records as an integer.
If the QuerySet is already fully cached, return the length of the cached results set to avoid multiple SELECT COUNT(*) calls.
- create(**kwargs)[source]
Create a new object with the given kwargs, saving it to the database and returning the created object.
- dates(field_name, kind, order='ASC')[source]
Return a list of date objects representing all available dates for the given field_name, scoped to ‘kind’.
- datetimes(field_name, kind, order='ASC', tzinfo=None, is_dst=<object object>)[source]
Return a list of datetime objects representing all available datetimes for the given field_name, scoped to ‘kind’.
- deconstruct()[source]
Return a 5-tuple of the form (as_manager (True), manager_class, queryset_class, args, kwargs).
Raise a ValueError if the manager is dynamically generated.
- defer(*fields)[source]
Defer the loading of data for certain fields until they are accessed. Add the set of deferred fields to any existing set of deferred fields. The only exception to this is if None is passed in as the only parameter, in which case removal all deferrals.
- distinct(*field_names)[source]
Return a new QuerySet instance that will select only distinct results.
- exclude(*args, **kwargs)[source]
Return a new QuerySet instance with NOT (args) ANDed to the existing set.
- explain(*, format=None, **options)[source]
Runs an EXPLAIN on the SQL query this QuerySet would perform, and returns the results.
- extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)[source]
Add extra SQL fragments to the query.
- filter(*args, **kwargs)[source]
Return a new QuerySet instance with the args ANDed to the existing set.
- get(*args, **kwargs)[source]
Perform the query and return a single object matching the given keyword arguments.
- get_or_create(defaults=None, **kwargs)[source]
Look up an object with the given kwargs, creating one if necessary. Return a tuple of (object, created), where created is a boolean specifying whether an object was created.
- 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
- in_bulk(id_list=None, *, field_name='pk')[source]
Return a dictionary mapping each of the given IDs to the object with that ID. If id_list isn’t provided, evaluate the entire QuerySet.
- iterator(chunk_size=None)[source]
An iterator over the results from applying this QuerySet to the database. chunk_size must be provided for QuerySets that prefetch related objects. Otherwise, a default chunk_size of 2000 is supplied.
- latest(*fields)[source]
Return the latest object according to fields (if given) or by the model’s Meta.get_latest_by.
- only(*fields)[source]
Essentially, the opposite of defer(). Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated.
Return a new QuerySet instance that will prefetch the specified Many-To-One and Many-To-Many related objects when the QuerySet is evaluated.
When prefetch_related() is called more than once, append to the list of prefetch lookups. If prefetch_related(None) is called, clear the list.
- select_for_update(nowait=False, skip_locked=False, of=(), no_key=False)[source]
Return a new QuerySet instance that will select objects with a FOR UPDATE lock.
Return a new QuerySet instance that will select related objects.
If fields are specified, they must be ForeignKey fields and only those related objects are included in the selection.
If select_related(None) is called, clear the list.
- update(**kwargs)[source]
Update all elements in the current QuerySet, setting all the given fields to the appropriate values.
- update_or_create(defaults=None, **kwargs)[source]
Look up an object with the given kwargs, updating one with defaults if it exists, otherwise create a new one. Return a tuple (object, created), where created is a boolean specifying whether an object was created.
- class integreat_cms.cms.models.chat.chat_message.ChatMessage(*args, **kwargs)[source]
Bases:
AbstractBaseModel
A model for a message in the author chat
- Parameters:
id (BigAutoField) – Primary key: ID
text (TextField) – Content
sent_datetime (DateTimeField) – Sent date
Relationship fields:
- Parameters:
sender (
ForeignKey
toUser
) – Sender (related name:chat_messages
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- clean()[source]
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clean_fields(exclude=None)[source]
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
- full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- get_next_by_sent_datetime(*, field=<django.db.models.DateTimeField: sent_datetime>, is_next=True, **kwargs)[source]
Finds next instance based on
sent_datetime
. Seeget_next_by_FOO()
for more information.
- get_previous_by_sent_datetime(*, field=<django.db.models.DateTimeField: sent_datetime>, is_next=False, **kwargs)[source]
Finds previous instance based on
sent_datetime
. Seeget_previous_by_FOO()
for more information.
- 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:
- 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
- id[source]
Type:
BigAutoField
Primary key: ID
- objects = <django.db.models.Manager object>[source]
Django manager to access the ORM Use
ChatMessage.objects.all()
to fetch all objects.The default manager
- refresh_from_db(using=None, fields=None)[source]
Reload field values from the database.
By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.
Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.
When accessing deferred fields of an instance, the deferred loading of the field will call this method.
- save(force_insert=False, force_update=False, using=None, update_fields=None)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]
Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.
- sender[source]
Type:
ForeignKey
toUser
Sender (related name:
chat_messages
)
- sent_datetime[source]
Type:
DateTimeField
Sent date
- serializable_value(field_name)[source]
Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.
Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.
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:
id (BigAutoField) – Primary key: ID
device_id (CharField) – Device id
is_tester (BooleanField) – Is tester
Relationship fields:
- Parameters:
region (
ForeignKey
toRegion
) – Region (related name:abtester
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- clean()[source]
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clean_fields(exclude=None)[source]
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
- full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- 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:
- id[source]
Type:
BigAutoField
Primary key: ID
- is_tester[source]
Type:
BooleanField
Is tester
- refresh_from_db(using=None, fields=None)[source]
Reload field values from the database.
By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.
Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.
When accessing deferred fields of an instance, the deferred loading of the field will call this method.
- region[source]
Type:
ForeignKey
toRegion
Region (related name:
abtester
)
- save(force_insert=False, force_update=False, using=None, update_fields=None)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]
Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.
- serializable_value(field_name)[source]
Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.
Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.
- 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:
id (BigAutoField) – Primary key: ID
device_id (CharField) – Device id
zammad_id (IntegerField) – Zammad id
most_recent_hits (TextField) – Most recent hits
Relationship fields:
- Parameters:
region (
ForeignKey
toRegion
) – Region for Chat (related name:chats
)language (
ForeignKey
toLanguage
) – Language of chat app user (related name:chats
)
Reverse relationships:
- Parameters:
attachments (Reverse
ForeignKey
fromAttachmentMap
) – All attachments of this user chat (related name ofuser_chat
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- attachments[source]
Type: Reverse
ForeignKey
fromAttachmentMap
All attachments of this user chat (related name of
user_chat
)
- clean()[source]
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clean_fields(exclude=None)[source]
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
- full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- 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:
- id[source]
Type:
BigAutoField
Primary key: ID
- language[source]
Type:
ForeignKey
toLanguage
Language of chat app user (related name:
chats
)
- 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:
- record_hit() None [source]
Record the timestamp of accesses for ratelimiting purposes
- Return type:
None
- refresh_from_db(using=None, fields=None)[source]
Reload field values from the database.
By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.
Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.
When accessing deferred fields of an instance, the deferred loading of the field will call this method.
- region[source]
Type:
ForeignKey
toRegion
Region for Chat (related name:
chats
)
- save(force_insert=False, force_update=False, using=None, update_fields=None)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]
Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.
- serializable_value(field_name)[source]
Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.
Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.
- validate_unique(exclude=None)[source]
Check unique constraints on the model and raise ValidationError if any failed.
- zammad_id[source]
Type:
IntegerField
Zammad id
- class integreat_cms.cms.models.chat.user_chat.UserChatManager(*args, **kwargs)[source]
Bases:
Manager
custom manager providing function to get the current chat
- abulk_create(objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None)[source]
- aggregate(*args, **kwargs)[source]
Return a dictionary containing the calculations (aggregation) over the current queryset.
If args is present the expression is passed as a kwarg using the Aggregate object’s default alias.
- aiterator(chunk_size=2000)[source]
An asynchronous iterator over the results from applying this QuerySet to the database.
- alias(*args, **kwargs)[source]
Return a query set with added aliases for extra data or aggregations.
- annotate(*args, **kwargs)[source]
Return a query set in which the returned objects have been annotated with extra data or aggregations.
- bulk_create(objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None)[source]
Insert each of the instances into the database. Do not call save() on each of the instances, do not send any pre/post_save signals, and do not set the primary key attribute if it is an autoincrement field (except if features.can_return_rows_from_bulk_insert=True). Multi-table models are not supported.
- bulk_update(objs, fields, batch_size=None)[source]
Update the given fields in each of the given objects in the database.
- complex_filter(filter_obj)[source]
Return a new QuerySet instance with filter_obj added to the filters.
filter_obj can be a Q object or a dictionary of keyword lookup arguments.
This exists to support framework features such as ‘limit_choices_to’, and usually it will be more natural to use other methods.
- count()[source]
Perform a SELECT COUNT() and return the number of records as an integer.
If the QuerySet is already fully cached, return the length of the cached results set to avoid multiple SELECT COUNT(*) calls.
- create(**kwargs)[source]
Create a new object with the given kwargs, saving it to the database and returning the created object.
- current_chat(device_id: str, **kwargs: Any) UserChat [source]
Return only the newest (i.e. current) chat for a given device_id
- dates(field_name, kind, order='ASC')[source]
Return a list of date objects representing all available dates for the given field_name, scoped to ‘kind’.
- datetimes(field_name, kind, order='ASC', tzinfo=None, is_dst=<object object>)[source]
Return a list of datetime objects representing all available datetimes for the given field_name, scoped to ‘kind’.
- deconstruct()[source]
Return a 5-tuple of the form (as_manager (True), manager_class, queryset_class, args, kwargs).
Raise a ValueError if the manager is dynamically generated.
- defer(*fields)[source]
Defer the loading of data for certain fields until they are accessed. Add the set of deferred fields to any existing set of deferred fields. The only exception to this is if None is passed in as the only parameter, in which case removal all deferrals.
- distinct(*field_names)[source]
Return a new QuerySet instance that will select only distinct results.
- exclude(*args, **kwargs)[source]
Return a new QuerySet instance with NOT (args) ANDed to the existing set.
- explain(*, format=None, **options)[source]
Runs an EXPLAIN on the SQL query this QuerySet would perform, and returns the results.
- extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)[source]
Add extra SQL fragments to the query.
- filter(*args, **kwargs)[source]
Return a new QuerySet instance with the args ANDed to the existing set.
- get(*args, **kwargs)[source]
Perform the query and return a single object matching the given keyword arguments.
- get_or_create(defaults=None, **kwargs)[source]
Look up an object with the given kwargs, creating one if necessary. Return a tuple of (object, created), where created is a boolean specifying whether an object was created.
- get_queryset()[source]
Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.
- in_bulk(id_list=None, *, field_name='pk')[source]
Return a dictionary mapping each of the given IDs to the object with that ID. If id_list isn’t provided, evaluate the entire QuerySet.
- iterator(chunk_size=None)[source]
An iterator over the results from applying this QuerySet to the database. chunk_size must be provided for QuerySets that prefetch related objects. Otherwise, a default chunk_size of 2000 is supplied.
- latest(*fields)[source]
Return the latest object according to fields (if given) or by the model’s Meta.get_latest_by.
- only(*fields)[source]
Essentially, the opposite of defer(). Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated.
Return a new QuerySet instance that will prefetch the specified Many-To-One and Many-To-Many related objects when the QuerySet is evaluated.
When prefetch_related() is called more than once, append to the list of prefetch lookups. If prefetch_related(None) is called, clear the list.
- select_for_update(nowait=False, skip_locked=False, of=(), no_key=False)[source]
Return a new QuerySet instance that will select objects with a FOR UPDATE lock.
Return a new QuerySet instance that will select related objects.
If fields are specified, they must be ForeignKey fields and only those related objects are included in the selection.
If select_related(None) is called, clear the list.
- update(**kwargs)[source]
Update all elements in the current QuerySet, setting all the given fields to the appropriate values.
- update_or_create(defaults=None, **kwargs)[source]
Look up an object with the given kwargs, updating one with defaults if it exists, otherwise create a new one. Return a tuple (object, created), where created is a boolean specifying whether an object was created.