Settings

All the settings of drf-sendables have default values, which can be overriden. This is done by defining a SENDABLES dict in your Django project’s settings file. Then, for each entity you want to configure, use its name as the key, and, as the value, a dict with any of the keys mentioned below. For example:

SENDABLES = {
    "message": {
        "PARTICIPANT_KEY_NAME": "username",
        "PARTICIPANT_KEY_TYPE": "rest_framework.serializers.CharField",
    },
    "notice": {
        "GET_VALID_ITEMS": "sendables.core.policies.select.get_valid_items_strict",
    },
}

Note

Settings described having an object / dotted path type, can either take an object (class/function) as a value, or a string containing a dotted import path to an object.

Note

Every time you change settings related to the database, you should then generate and run database migrations.

Presented here are the settings for each entity, along with their type, default value, and description:

Sendables

SEND_SERIALIZER_CLASS
Type: object / dotted path

Serializer for creating and dispatching sendables to recipients.

ALLOW_SEND_TO_SELF
Type: bool / object / dotted path
Default: False

Whether a user is considered a valid recipient of their own sendables. Can be a bool, or a callable accepting a single request argument.

SENT_FIELD_NAMES
Type: list[str]
Default: ["content"]

The fields of sendable model/serializer to be used during sending. They must be present on the used sendable model, and on the sendable detail serializer with source="sendable.field_name".

PARTICIPANT_KEY_NAME
Type: str
Default: "id"

Name of field uniquely identifying users, used for recipient selection during sending, and sender serializer representation.

PARTICIPANT_KEY_TYPE
Type: object / dotted path
Default: "rest_framework.serializers.IntegerField"

Serializer field type of field uniquely identifying users, used for recipient selection during sending, and sender serializer representation.

GET_VALID_RECIPIENTS

Method of choosing valid recipients during sending. Takes 3 arguments: 1) The request object, 2) a list of strings containing values of a field (e.g. id) that uniquely identifies users that the client requested to use as recipients, and 3) the “send” action’s serializer instance. Should return a QuerySet of users deemed as valid recipients.

SENDABLE_CLASS
Type: object / dotted path

The sendable Django model class to be used.

SENDABLE_KEY_NAME
Type: str
Default: "id"

Name of field uniquely identifying sendables, used for sendable selection during sending, and URL argument naming.

SENDABLE_KEY_TYPE
Type: object / dotted path
Default: "rest_framework.serializers.IntegerField"

Serializer field type of field uniquely identifying sendables, used for sendable selection during sending, and URL argument typing.

GET_VALID_ITEMS
Type: object / dotted path

Method of choosing valid items (sendables/received sendables) during selecting. Takes 5 arguments: 1) The request object, 2) a list of strings containing values of a field (e.g. id) that uniquely identifies items that the client requested to select, 3) the “select” action’s serializer instance, 4) the item’s model class, and 5) a string indicating the user’s relation to the items ("sender"/"recipient"). It can also take an is_removed=False argument, in the case of selecting sent sendables for deletion. Should return a QuerySet of items deemed as validly selected.

LIST_SERIALIZER_CLASS
Type: object / dotted path

Serializer to represent received sendables during list view.

DETAIL_SERIALIZER_CLASS
Type: object / dotted path

Serializer to represent a received sendable during detail view.

SORT_RECEIVED_KEY
Type: object / dotted path

Sorting key for received sendables. Function that gets passed as key to sorted() during received sendable list view. Takes a ReceivedSendable object as argument.

SORT_SENT_KEY
Type: object / dotted path

Sorting key for recipient-sendable associations. Function that gets passed as key to sorted() during sent sendable list view. Takes a RecipientSendableAssociation object as argument.

FILTER_SENDABLES
Type: object / dotted path

Function to filter listed sendables, using the respective URL query parameters. A list-type view’s specific setting overrides this. Takes 3 arguments: 1) The request object, 2) a QuerySet of Sendable objects, and 3) a dict of the entity settings. Should return the filtered sendables QuerySet.

FILTER_RECIPIENTS
Type: object / dotted path

Function to filter listed sendables by their recipients, using the respective URL query parameters. Takes 3 arguments: 1) The request object, 2) a QuerySet of User objects, and 3) a dict of the entity settings. Should return the filtered users QuerySet.

FILTER_FIELDS_SENDABLES
Default: {"content": FilterType.CONTAINS, "sent_on": FilterType.DATETIME, "sender__id": FilterType.EQUALS, "sender__username": FilterType.EQUALS}

Sendable fields to FilterType mapping, used for searching.

FILTER_FIELDS_RECIPIENTS
Default: {"id": FilterType.EQUALS, "username": FilterType.EQUALS}

User fields to FilterType mapping, used for searching.

AFTER_SEND_CALLBACKS
Type: list[object / dotted path]
Default: []

List of functions to be called after the sending of a sendable. They take 3 arguments: 1) The request object, 2) a dict of sent field names to their values (e.g. {"content": "hello"}), and 3) the valid recipients as a QuerySet of User objects.

DELETE_HANGING_SENDABLES
Type: bool
Default: True

Whether to delete database records not referenced by any other “alive” records. “Alive” here means not explicitly deleted by a user’s actions.

GET_RECEIVED_PREFETCH_FIELDS

Function to provide “prefetch related” fields for received sendable list. Takes 1 argument: the sendable model class. Should return the model fields as a list of strings.

PAGINATION_CLASS
Type: BasePagination / None
Default: None

Pagination class to be used in list views. A list-type view’s specific setting overrides this. Can be None for no pagination.

Given the following view names:

SEND
MARK_AS_READ
MARK_AS_UNREAD
DELETE
DELETE_SENT
LIST
LIST_READ
LIST_UNREAD
LIST_SENT
DETAIL
DETAIL_SENT

this kind of settings exist:

VIEW_NAME_PERMISSIONS
Type: list[object / dotted path]
Default: ["rest_framework.permissions.IsAuthenticated"]

For example, DELETE_PERMISSIONS. List of permission classes to be applied to the view indicated by view name.

Given the following list view names:

LIST
LIST_READ
LIST_UNREAD
LIST_SENT

these kind of settings exist:

LIST_VIEW_NAME_FILTER_SENDABLES
Type: object / dotted path / None
Default: None

For example, LIST_FILTER_SENDABLES. Function to filter listed sendables, using the respective URL query parameters, in the view indicated by list view name. If not None, overrides the generic setting. Takes 3 arguments: 1) The request object, 2) a QuerySet of Sendable objects, and 3) a dict of the entity settings. Should return the filtered sendables QuerySet.

LIST_VIEW_NAME_PAGINATION_CLASS
Type: BasePagination / None
Default: None

Pagination class to be used in the view indicated by list view name. If not None, overrides the generic setting.

Messages

Messages use all the settings that sendables do, plus some extra ones, while having different default values for some of the settings.

SEND_SERIALIZER_CLASS
Type: object / dotted path

Serializer for creating and dispatching messages to recipients.

SENDABLE_CLASS
Type: object / dotted path

The message Django model class to be used.

LIST_SERIALIZER_CLASS
Type: object / dotted path

Serializer to represent received messages during list view.

LIST_SENT_SERIALIZER_CLASS
Type: object / dotted path

Serializer to represent sent messages during list view.

DETAIL_SERIALIZER_CLASS
Type: object / dotted path

Serializer to represent received messages during detail view.

DETAIL_SENT_SERIALIZER_CLASS
Type: object / dotted path

Serializer to represent sent messages during detail view.

SENDER_FIELD_TYPE_LIST
Type: object / dotted path

Serializer/field to represent sender users during received message list view.

SENDER_FIELD_TYPE_DETAIL
Type: object / dotted path

Serializer/field to represent sender user during received message detail view.

RECIPIENT_FIELD_TYPE_LIST
Type: object / dotted path

Serializer/field to represent recipient users during sent message list view.

RECIPIENT_FIELD_TYPE_DETAIL
Type: object / dotted path

Serializer/field to represent recipient user during sent message detail view.

Notices

Notices use all the settings that sendables do, while having different default values for some of the settings.

SENDABLE_CLASS
Type: object / dotted path

The notice Django model class to be used.

SEND_PERMISSIONS
Type: list[object / dotted path]
Default: ["rest_framework.permissions.IsAdminUser"]

List of permission classes to be applied to the send notice view.