Journal API Views

Smarter Journal api views.

They are mounted at /api/v1/journal/, and only superusers may call them: a journal entry’s documents hold every user’s content, e.g. prompts and manifests. 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.

The response is 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]

Return every journal entry with its user, newest first, without its documents.

Return type:

QuerySet[SAMJournal]

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

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

Sends the journal_entries_listed signal.

Parameters:
  • request (Request) – The request, whose query parameters choose the page, search and ordering.

  • args – Unused.

  • kwargs – Unused.

Returns:

A SAMJournalApiPage, as JSON.

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

Same as get(): Smarter list views are also served by POST.

Parameters:
  • request (Request) – The request.

  • args – Passed to list().

  • kwargs – Passed to list().

Returns:

A SAMJournalApiPage, as JSON.

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, and send the journal_entry_accessed signal.

Parameters:
  • request (Request) – The request.

  • key (str) – The journal entry’s key.

  • args – Unused.

  • kwargs – Unused.

Returns:

The entry as a SAMJournalApiEntry dict.

Raises:

Http404 – If there is no entry with this key.

get_queryset()[source]

Return every journal entry with its user, newest first.

Return type:

QuerySet[SAMJournal]

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

Same as get(): Smarter detail views are also served by POST.

Parameters:
  • request (Request) – The request.

  • key (str) – The journal entry’s key.

  • args – Unused.

  • kwargs – Unused.

Returns:

The entry as a SAMJournalApiEntry dict.

Raises:

Http404 – If there is no entry with this key.

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]

Return every journal entry, newest first, with its user.

Return type:

QuerySet[SAMJournal]

Returns:

The journal entries, with each entry’s user fetched in the same query.

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},
)