Exchangeables

The following components can be used as parts of the system (most of them are already being used by default). The settings page describes which of the following can be used at what places, and what are the defaults. You can make your choices either among the ones listed here, or provide your own.

class sendables.core.models.Sendable(*args, **kwargs)[source]

Bases: ManagedModel, Model

content

TextField

is_removed

BooleanField

sent_on

DateTimeField

class sendables.core.models.ReceivedSendable(*args, **kwargs)[source]

Bases: ManagedModel, Model

Reference to some sendable, in a user’s inbox (their own “copy”).

is_read

BooleanField

recipient

ForeignKey

content_type

ForeignKey

object_id

PositiveIntegerField

sendable

GenericForeignKey

class sendables.core.models.RecipientSendableAssociation(*args, **kwargs)[source]

Bases: ManagedModel, Model

Connection between recipient and sendable sent to them (who a sendable was sent to).

recipient

ForeignKey

content_type

ForeignKey

object_id

PositiveIntegerField

sendable

GenericForeignKey

class sendables.messages.models.Message(*args, **kwargs)[source]

Bases: Sendable

sender

ForeignKey

content

TextField

is_removed

BooleanField

sent_on

DateTimeField

class sendables.notices.models.Notice(*args, **kwargs)[source]

Bases: Sendable

content

TextField

is_removed

BooleanField

sent_on

DateTimeField

class sendables.core.serializers.ReceivedSendableSerializer(*args, **kwargs)[source]

Bases: Serializer

id: IntegerField()

is_read: BooleanField()

content: CharField(source=’sendable.content’)

sent_on: DateTimeField(source=’sendable.sent_on’)

class sendables.core.serializers.ContainerSerializer(*args, **kwargs)[source]

Bases: Serializer

Contains a ListField of certain-typed items.

class sendables.core.serializers.SendSerializer(*args, **kwargs)[source]

Bases: ContainerSerializer

Creates and dispatches sendables to recipients.

get_fields() dict[str, Field][source]

Dynamically add any desired fields from the detail serializer.

save(**kwargs: Any) None[source]

Create new sendable data and invoke any post-send callbacks.

Store the following: 1. The sendable itself (content and anything else) 2. Per-recipient references (users’ inbox “copies”) 3. Sendable-recipient associations (“sent to who” info)

class sendables.messages.serializers.MessageListSerializer(*args, **kwargs)[source]

Bases: ReceivedMessageSerializer

id: IntegerField()

is_read: BooleanField()

content: CharField(source=’sendable.content’)

sent_on: DateTimeField(source=’sendable.sent_on’)

class sendables.messages.serializers.MessageDetailSerializer(*args, **kwargs)[source]

Bases: ReceivedMessageSerializer

id: IntegerField()

is_read: BooleanField()

content: CharField(source=’sendable.content’)

sent_on: DateTimeField(source=’sendable.sent_on’)

class sendables.messages.serializers.MessageSentSerializer(*args, **kwargs)[source]

Bases: Serializer

id: IntegerField(source=’sendable.id’)

content: CharField(source=’sendable.content’)

sent_on: DateTimeField(source=’sendable.sent_on’)

class sendables.messages.serializers.SendMessageSerializer(*args, **kwargs)[source]

Bases: SendSerializer

save(**kwargs: Any) None[source]

Create new sendable data and invoke any post-send callbacks.

Store the following: 1. The sendable itself (content and anything else) 2. Per-recipient references (users’ inbox “copies”) 3. Sendable-recipient associations (“sent to who” info)

class sendables.messages.serializers.ParticipantSerializer(*args, **kwargs)[source]

Bases: Serializer

class sendables.core.types.FilterType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Search filter type, applied against model fields.

sendables.core.policies.filter.filter_sendables(request: Request, sendables: QuerySet, entity_settings: Settings) QuerySet[source]

Filter given sendables, using their respective URL query parameters.

Parameters:
  • request – The request object

  • sendables – The sendables QuerySet to be filtered

  • entity_settings – The Settings object for current entity

Returns:

The filtered sendables QuerySet

sendables.core.policies.filter.filter_recipients(request: Request, users: QuerySet, entity_settings: Settings) QuerySet[source]

Filter given recipients, using their respective URL query parameters.

Parameters:
  • request – The request object

  • users – The users QuerySet to be filtered

  • entity_settings – The Settings object for current entity

Returns:

The filtered users QuerySet

sendables.core.policies.list.get_received_prefetch_fields(sendable_class: type[ManagedModel]) list[str][source]

Provide “prefetch related” fields for received sendable list.

Pick sendable (the sendable record reference), and if there is a sender field on sendable pick that relation as well.

Parameters:

sendable_class – The sendable model class

Returns:

The chosen “prefetch related” fields

sendables.core.policies.list.sort_received_key(received_sendable: ReceivedSendable) tuple[bool, float][source]

Get sorting key for received sendables.

Utilized to sort received sendables. Sort first by “is read” ascending, then by “sent on” descending.

Parameters:

received_sendable – The received sendable

Returns:

The comparison tuple

sendables.core.policies.list.sort_sent_key(association: RecipientSendableAssociation) float[source]

Get sorting key for recipient-sendable associations.

Utilized to sort sent sendables. Sort by “sent on” descending.

Parameters:

association – The recipient-sendable association

Returns:

The comparison value

sendables.core.policies.select.get_valid_items_lenient(request: Request, requested_keys: list[str], select_serializer: SelectSerializer, item_type: type[ManagedModel], user_role: str, **removal_filters: bool) QuerySet[source]

Lenient method of choosing valid items (database records), out of a group of requested keys.

Pick existent keys that belong to current user and quitely ignore the rest.

Parameters:
  • request – The request object

  • requested_keys – Requested items’ identifying keys

  • select_serializer – The “select” action’s serializer

  • item_type – Requested items’ model class

  • user_role – Current user’s relation to the items

  • removal_filters – Possible “is removed” filters

Returns:

A QuerySet of eligible items

sendables.core.policies.select.get_valid_items_strict(request: Request, requested_keys: list[str], select_serializer: SelectSerializer, item_type: type[ManagedModel], user_role: str, **removal_filters: bool) QuerySet[source]

Strict method of choosing valid items (database records), out of a group of requested keys.

If given any values other than existent keys belonging to current user, respond with an error.

Parameters:
  • request – The request object

  • requested_keys – Requested items’ identifying keys

  • select_serializer – The “select” action’s serializer

  • item_type – Requested items’ model class

  • user_role – Current user’s relation to the items

  • removal_filters – Possible “is removed” filters

Returns:

A QuerySet of eligible items

Raises:

ValidationError – On any invalid items found

sendables.core.policies.send.get_valid_recipients_lenient(request: Request, requested_recipient_keys: list[str], send_serializer: SendSerializer, *args: Any, **kwargs: Any) QuerySet[source]

Lenient method of choosing valid recipients, out of a group of requested keys.

Pick existent keys, possibly exclude current user, and quitely ignore the rest.

Parameters:
  • request – The request object

  • requested_recipient_keys – Requested recipients’ identifying keys

  • send_serializer – The “send” action’s serializer

Returns:

A QuerySet of eligible recipients

sendables.core.policies.send.get_valid_recipients_strict(request: Request, requested_recipient_keys: list[str], send_serializer: SendSerializer, *args: Any, **kwargs: Any) QuerySet[source]

Strict method of choosing valid recipients, out of a group of requested keys.

If given any non-existent keys, or possibly current user, respond with an error.

Parameters:
  • request – The request object

  • requested_recipient_keys – Requested recipients’ identifying keys

  • send_serializer – The “send” action’s serializer

Returns:

A QuerySet of eligible recipients

Raises:

ValidationError – On any invalid recipients found

sendables.core.urls.sendables_path(route: str, entity_name: str = 'sendable') URLResolver[source]

Generate and return the URL patterns for a sendable entity type.

Use settings, generate URL pattern names, and choose URL argument types, based on given entity_name. Pass that name to all of the views. Make a non-abstract version of the sendable model that is used with those settings.

Parameters:
  • route – The URL path pattern

  • entity_name – The name of the sendable entity type

Returns:

The URL patterns