Journal API Views

Smarter Journal api views.

They are mounted at /api/v1/journal/, and only superusers may call them: a journal entry’s request document holds the caller’s headers and cookies, including its api key. Each read is signaled, with smarter.lib.journal.signals.journal_entry_accessed or smarter.lib.journal.signals.journal_entries_listed.

class smarter.lib.journal.api.v1.views.SAMJournalListView(*args, **kwargs)[source]

Bases: SmarterAdminListAPIView

One page of the journal entries, newest first, without their request and response documents: a.

SAMJournalApiPage.

The query parameters page, page_size, search and ordering are those of smarter.lib.django.pagination.paginate_listview(). A search matches an entry’s key, thing or command.

get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

Return type:

QuerySet

list(request, *args, **kwargs)[source]

Return one page of the journal entries, and a description of the page.

post(request, *args, **kwargs)[source]

Same as get().

Smarter list views are also served by POST.

serializer_class

alias of SAMJournalMiniSerializer

class smarter.lib.journal.api.v1.views.SAMJournalView(*args, **kwargs)[source]

Bases: SmarterAdminAPIView

A journal entry, by its key, with its request and response documents: a SAMJournalApiEntry.

get(request, key, *args, **kwargs)[source]

Return the journal entry.

post(request, key, *args, **kwargs)[source]

Same as get().

Smarter detail views are also served by POST.

serializer_class

alias of SAMJournalSerializer

smarter.lib.journal.api.v1.views.SEARCH_FIELDS = ('key', 'thing', 'command')

The fields that a search of the list matches.

('key', 'thing', 'command')
smarter.lib.journal.api.v1.views.SORT_FIELDS = {'command': 'command', 'createdAt': 'created_at', 'statusCode': 'status_code', 'thing': 'thing', 'user': 'user__username'}

The columns that the list may be sorted by.

See smarter.lib.django.pagination.DEFAULT_SORT_FIELDS.

{
    'command': 'command',
    'createdAt': 'created_at',
    'statusCode': 'status_code',
    'thing': 'thing',
    'user': 'user__username',
}
smarter.lib.journal.api.v1.views.journal_entries()[source]

Every journal entry, newest first, with its user.

Return type:

QuerySet

URL configuration for the Smarter Journal api.

These are mounted at /api/v1/journal/. See smarter.lib.journal.api.v1.views.

class smarter.lib.journal.api.v1.urls.SAMJournalApiV1ReverseViews[source]

Reverse view names for the Smarter Journal api.

Example

from django.urls import reverse
url = reverse(
    f"{SAMJournalApiV1ReverseViews.namespace}:{SAMJournalApiV1ReverseViews.journal_view}",
    kwargs={"key": journal.key},
)