Models

Models for the dasf-broker-django app.

Models:

BrokerMessage(*args, **kwargs)

A message sent to the broker.

BrokerTopic(*args, **kwargs)

A topic for producing and consuming requests via websocket

ResponseTopic(*args, **kwargs)

A topic that accepts responses for messages.

Classes:

BrokerTopicManager(*args, **kwargs)

A manager for broker topics.

BrokerTopicQuerySet([model, query, using, hints])

A queryset for broker topics.

class dasf_broker.models.BrokerMessage(*args, **kwargs)

Bases: Model

A message sent to the broker.

Parameters:
  • id (BigAutoField) – Primary key: ID

  • message_id (UUIDField) – Message id. Message ID

  • context (IntegerField) – Context. Message context for messages from a producer.

  • content (JSONField) – Content. The content of the message.

  • date_created (DateTimeField) – Date created. The date and time when the message has been created

Relationship fields:

Parameters:
  • topic (ForeignKey to BrokerTopic) – Topic. The topic the message was published for. (related name: brokermessage)

  • user (ForeignKey to User) – User. The user who produced the message. (related name: brokermessage)

  • delivered_to (ManyToManyField to User) – Delivered to. To whom has this message been delivered already? (related name: brokermessage_set_delivered)

Reverse relationships:

Parameters:

responsetopic (Reverse ManyToManyField from ResponseTopic) – All response topics of this broker message (related name of source_messages)

Miscellaneous:

DoesNotExist

MultipleObjectsReturned

Model Fields:

content

Type: JSONField

context

Type: IntegerField

date_created

Type: DateTimeField

id

Type: BigAutoField

message_id

Type: UUIDField

topic

Type: ForeignKey to BrokerTopic

user

Type: ForeignKey to User

Attributes:

delivered_to

Type: ManyToManyField to User

delivered_to_all

Test if the message has been delivered to all consumers.

is_response

Is this message a response to a DASF request?

objects

responsetopic_set

Type: Reverse ManyToManyField from ResponseTopic

topic_id

Internal field, use topic instead.

user_id

Internal field, use user instead.

Methods:

get_next_by_date_created(*[, field, is_next])

Finds next instance based on date_created.

get_previous_by_date_created(*[, field, is_next])

Finds previous instance based on date_created.

send()

Send the message via the websocket.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

content

Type: JSONField

Content. The content of the message.

A wrapper for a deferred-loading field. When the value is read from this

context

Type: IntegerField

Context. Message context for messages from a producer.

A wrapper for a deferred-loading field. When the value is read from this

date_created

Type: DateTimeField

Date created. The date and time when the message has been created

A wrapper for a deferred-loading field. When the value is read from this

delivered_to

Type: ManyToManyField to User

Delivered to. To whom has this message been delivered already? (related name: brokermessage_set_delivered)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

property delivered_to_all: bool

Test if the message has been delivered to all consumers.

get_next_by_date_created(*, field=<django.db.models.DateTimeField: date_created>, is_next=True, **kwargs)

Finds next instance based on date_created. See get_next_by_FOO() for more information.

get_previous_by_date_created(*, field=<django.db.models.DateTimeField: date_created>, is_next=False, **kwargs)

Finds previous instance based on date_created. See get_previous_by_FOO() for more information.

id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

property is_response: bool

Is this message a response to a DASF request?

message_id

Type: UUIDField

Message id. Message ID

A wrapper for a deferred-loading field. When the value is read from this

objects = <django.db.models.Manager object>
responsetopic_set

Type: Reverse ManyToManyField from ResponseTopic

All response topics of this broker message (related name of source_messages)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

send()

Send the message via the websocket.

topic

Type: ForeignKey to BrokerTopic

Topic. The topic the message was published for. (related name: brokermessage)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
topic_id

Internal field, use topic instead.

user

Type: ForeignKey to User

User. The user who produced the message. (related name: brokermessage)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
user_id

Internal field, use user instead.

class dasf_broker.models.BrokerTopic(*args, **kwargs)

Bases: Model

A topic for producing and consuming requests via websocket

Parameters:
  • id (BigAutoField) – Primary key: ID

  • slug (SlugField) – Slug. Unique identifier for the topic.

  • is_public (BooleanField) – Is public. Can everyone publish data to this topic?

  • date_created (DateTimeField) – Date created. The date and time when the message has been created

  • last_ping (DateTimeField) – Last ping. When has the topic last been pinged?

  • last_pong (DateTimeField) – Last pong. When has the topic last replyed on a ping?

  • supports_dasf (BooleanField) – Supports dasf. Does this topic support the DASF messaging protocoll?

  • store_messages (CharField) – Store messages. Should messages be stored?

  • garbage_collect_on (DateTimeField) – Garbage collect on. Specify a time when this topic should be removed from the database.

  • api_info (JSONField) –

    Api info

    metadata field to allow additional attributes for topics.

Reverse relationships:

Parameters:

Miscellaneous:

DoesNotExist

MultipleObjectsReturned

Classes:

StoreMessageChoices(value)

Choices for storing messages.

Model Fields:

api_info

Type: JSONField

date_created

Type: DateTimeField

garbage_collect_on

Type: DateTimeField

id

Type: BigAutoField

is_public

Type: BooleanField

last_ping

Type: DateTimeField

last_pong

Type: DateTimeField

slug

Type: SlugField

store_messages

Type: CharField

supports_dasf

Type: BooleanField

Attributes:

availability

Get the online/offline status for the topic.

brokermessage_set

Type: Reverse ForeignKey from BrokerMessage

consumers

effective_store_messages

Get the store message rule for this topic.

is_response_topic

Is this topic a responsetopic?

objects

producers

responsetopic

Type: Reverse OneToOneField from ResponseTopic

responsetopics

Type: Reverse ForeignKey from ResponseTopic

status_viewers

Methods:

build_websocket_url(request[, route])

create_and_send_message(user, content)

Create and send a message for the user

get_next_by_date_created(*[, field, is_next])

Finds next instance based on date_created.

get_outstanding_messages([user])

Get the messages that still need to be send.

get_previous_by_date_created(*[, field, is_next])

Finds previous instance based on date_created.

get_store_messages_display(*[, field])

Shows the label of the store_messages.

get_websocket_url(request)

Get the websocket url for this topic.

ping()

Create a ping message and send it to the consumer.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

class StoreMessageChoices(value)

Bases: TextChoices

Choices for storing messages.

Attributes:

CACHE

CACHEALL

DISABLED

STORE

CACHE = 'cache'
CACHEALL = 'cacheall'
DISABLED = 'disabled'
STORE = 'store'
api_info

Type: JSONField

Api info

availability

Get the online/offline status for the topic.

This value can be True, False or None:

None

The status is unknown. This occurs when the last ping was more than two minutes ago or the topic has never, been pinged.

False

The was no pong yet or the last pong was before the last ping and the last ping was less than two minutes ago.

True

The topic is online, i.e. we received a pong after the last ping

brokermessage_set

Type: Reverse ForeignKey from BrokerMessage

All broker messages of this broker topic (related name of topic)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

classmethod build_websocket_url(request, route: str | None = None) str
property consumers: models.QuerySet[User]
create_and_send_message(user: User, content: Dict)

Create and send a message for the user

date_created

Type: DateTimeField

Date created. The date and time when the message has been created

A wrapper for a deferred-loading field. When the value is read from this

property effective_store_messages: StoreMessageChoices

Get the store message rule for this topic.

garbage_collect_on

Type: DateTimeField

Garbage collect on. Specify a time when this topic should be removed from the database.

A wrapper for a deferred-loading field. When the value is read from this

get_next_by_date_created(*, field=<django.db.models.DateTimeField: date_created>, is_next=True, **kwargs)

Finds next instance based on date_created. See get_next_by_FOO() for more information.

get_outstanding_messages(user: User | None = None) models.QuerySet[BrokerMessage]

Get the messages that still need to be send.

Parameters:

user (Optional[User]) – The user for whom to send the messages. If None, the messages will be returned that have not yet been acknowledged at all.

Returns:

A QuerySet of messages

Return type:

models.QuerySet[BrokerMessage]

get_previous_by_date_created(*, field=<django.db.models.DateTimeField: date_created>, is_next=False, **kwargs)

Finds previous instance based on date_created. See get_previous_by_FOO() for more information.

get_store_messages_display(*, field=<django.db.models.CharField: store_messages>)

Shows the label of the store_messages. See get_FOO_display() for more information.

get_websocket_url(request) str

Get the websocket url for this topic.

id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

is_public

Type: BooleanField

Is public. Can everyone publish data to this topic?

A wrapper for a deferred-loading field. When the value is read from this

property is_response_topic: bool

Is this topic a responsetopic?

last_ping

Type: DateTimeField

Last ping. When has the topic last been pinged?

A wrapper for a deferred-loading field. When the value is read from this

last_pong

Type: DateTimeField

Last pong. When has the topic last replyed on a ping?

A wrapper for a deferred-loading field. When the value is read from this

objects = <dasf_broker.models.BrokerTopicManager object>
ping()

Create a ping message and send it to the consumer.

property producers: models.QuerySet[User]
responsetopic

Type: Reverse OneToOneField from ResponseTopic

The response topic of this broker topic (related name of brokertopic_ptr)

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')
responsetopics

Type: Reverse ForeignKey from ResponseTopic

All responsetopics of this broker topic (related name of is_response_for)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

slug

Type: SlugField

Slug. Unique identifier for the topic.

A wrapper for a deferred-loading field. When the value is read from this

property status_viewers: models.QuerySet[User]
store_messages

Type: CharField

Store messages. Should messages be stored?

Choices:

  • None

  • disabled

  • cache

  • cacheall

  • store

A wrapper for a deferred-loading field. When the value is read from this

supports_dasf

Type: BooleanField

Supports dasf. Does this topic support the DASF messaging protocoll?

A wrapper for a deferred-loading field. When the value is read from this

class dasf_broker.models.BrokerTopicManager(*args, **kwargs)

Bases: ManagerFromBrokerTopicQuerySet

A manager for broker topics.

class dasf_broker.models.BrokerTopicQuerySet(model=None, query=None, using=None, hints=None)

Bases: QuerySet

A queryset for broker topics.

Methods:

filter_offline(*args)

Query all online broker topics.

filter_online(*args, **kwargs)

Query all online broker topics.

filter_unknown_availability(*args)

Query all topics where the availability is unknown.

filter_offline(*args)

Query all online broker topics.

filter_online(*args, **kwargs)

Query all online broker topics.

filter_unknown_availability(*args)

Query all topics where the availability is unknown.

class dasf_broker.models.ResponseTopic(*args, **kwargs)

Bases: BrokerTopic

A topic that accepts responses for messages.

Parameters:
  • id (BigAutoField) – Primary key: ID

  • slug (SlugField) – Slug. Unique identifier for the topic.

  • is_public (BooleanField) – Is public. Can everyone publish data to this topic?

  • date_created (DateTimeField) – Date created. The date and time when the message has been created

  • last_ping (DateTimeField) – Last ping. When has the topic last been pinged?

  • last_pong (DateTimeField) – Last pong. When has the topic last replyed on a ping?

  • supports_dasf (BooleanField) – Supports dasf. Does this topic support the DASF messaging protocoll?

  • store_messages (CharField) – Store messages. Should messages be stored?

  • garbage_collect_on (DateTimeField) – Garbage collect on. Specify a time when this topic should be removed from the database.

  • api_info (JSONField) –

    Api info

    metadata field to allow additional attributes for topics.

Relationship fields:

Parameters:

Reverse relationships:

Parameters:

Miscellaneous:

DoesNotExist

MultipleObjectsReturned

Model Fields:

brokertopic_ptr

Type: OneToOneField to BrokerTopic

is_response_for

Type: ForeignKey to BrokerTopic

Attributes:

brokertopic_ptr_id

Internal field, use brokertopic_ptr instead.

is_response_for_id

Internal field, use is_response_for instead.

is_response_topic

Is this topic a responsetopic?

source_messages

Type: ManyToManyField to BrokerMessage

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

brokertopic_ptr: BrokerTopic

Type: OneToOneField to BrokerTopic

Primary key: Brokertopic ptr (related name: responsetopic)

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')
brokertopic_ptr_id

Internal field, use brokertopic_ptr instead.

is_response_for

Type: ForeignKey to BrokerTopic

Is response for. Is this topic used only once for a single response? (related name: responsetopics)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
is_response_for_id

Internal field, use is_response_for instead.

property is_response_topic: bool

Is this topic a responsetopic?

source_messages

Type: ManyToManyField to BrokerMessage

Source messages. Messages from the producer to the reference topic. (related name: responsetopic)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager