Skip to content

Polling Mixin

wagtail_live.publishers.polling.PollingPublisherMixin

A mixin for publishers using the polling technique.

Attributes:

Name Type Description
url_path str

Path of the URL used by client side to fetch new updates.

url_name str

Name of the URL for reversing/resolving.

get(self, request, channel_id, *args, **kwargs)

Retrieves and sends new updates to the client side.

Parameters:

Name Type Description Default
request HttpRequest

Client side's request sent along with the timestamp of the last update received.

required
channel_id str

Id of the channel to get last update's timestamp from.

required

Returns:

Type Description
HttpResponse
  • JSONResponse with the following informations:

    • A mapping of the live posts updated since client side's last update timestamp.

      Keys represents IDs of the live posts edited and the values are the new content of those live posts.

    • A list of the IDs of the current live posts for the page requested.

      Client side compares this list to the one it has and remove the live posts whose IDs aren't in this new list.

    • Timestamp of the last update for the page requested.

    if a page corresponding to the channel_id given exists.

  • Http404 else.

Source code in wagtail_live/publishers/polling.py
def get(self, request, channel_id, *args, **kwargs):
    """
    Retrieves and sends new updates to the client side.

    Args:
        request (HttpRequest):
            Client side's request sent along with the timestamp of the
            last update received.
        channel_id (str):
            Id of the channel to get last update's timestamp from.

    Returns:
        HttpResponse:
        - JSONResponse with the following informations:
            - A mapping of the live posts updated since client side's last update timestamp.

                Keys represents IDs of the live posts edited and the values
                are the new content of those live posts.

            - A list of the IDs of the current live posts for the page requested.

                Client side compares this list to the one it has and remove the live posts
                whose IDs aren't in this new list.

            - Timestamp of the last update for the page requested.

            if a page corresponding to the `channel_id` given exists.

        - Http404 else.
    """

    raise NotImplementedError

get_last_update_client_from_request(request) staticmethod

Retrieves the timestamp of the last update received in the client side.

Parameters:

Name Type Description Default
request HttpRequest

client side request

required

Returns:

Type Description
float

Timestamp of the last update received in the client side.

Source code in wagtail_live/publishers/polling.py
@staticmethod
def get_last_update_client_from_request(request):
    """
    Retrieves the timestamp of the last update received in the client side.

    Args:
        request (HttpRequest): client side request

    Returns:
        float: Timestamp of the last update received in the client side.
    """

    return float(request.GET.get("last_update_ts"))

get_urls() classmethod

Retrieves the URLs client side uses to fetch updates.

Source code in wagtail_live/publishers/polling.py
@classmethod
def get_urls(cls):
    """Retrieves the URLs client side uses to fetch updates."""

    return [
        path(cls.url_path, cls.as_view(), name=cls.url_name),
    ]

post(self, request, channel_id, *args, **kwargs)

Initiates communication with client side and sends current live posts.

Parameters:

Name Type Description Default
request HttpRequest

Client side's request

required
channel_id str

Id of the channel to get updates from.

required

Returns:

Type Description
HttpResponse
  • JSONResponse with the following informations:

    • A list of the IDs of the current live posts for the page requested.

      Client side uses this list to keep track of live posts that have been deleted.

    • Timestamp of the last update for the page requested.

      Client side uses this to know when new updates are available.

    • The duration of the polling interval for interval polling.

    if a page corresponding to the channel_id given exists.

  • Http404 else.

Source code in wagtail_live/publishers/polling.py
def post(self, request, channel_id, *args, **kwargs):
    """
    Initiates communication with client side and sends current live posts.

    Args:
        request (HttpRequest):
            Client side's request
        channel_id (str):
            Id of the channel to get updates from.

    Returns:
        HttpResponse:
        - JSONResponse with the following informations:
            - A list of the IDs of the current live posts for the page requested.

                Client side uses this list to keep track of live posts that have been deleted.

            - Timestamp of the last update for the page requested.

                Client side uses this to know when new updates are available.

            - The duration of the polling interval for interval polling.

            if a page corresponding to the `channel_id` given exists.

        - Http404 else.
    """

    raise NotImplementedError