Views

PluginMeta views.

class smarter.apps.llmtool.api.v1.views.PluginCloneView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

Plugin clone view for smarter api.

post(request, plugin_id, new_name)[source]

Clone a plugin under a new name, and redirect to the clone.

Parameters:
  • request (ASGIRequest) – The request.

  • plugin_id – The id of the plugin to clone, from the url.

  • new_name – The clone’s name, from the url.

Returns:

A redirect to /plugins/<new id>/, or an error response.

class smarter.apps.llmtool.api.v1.views.PluginListView(*args, **kwargs)[source]

Bases: ContractListMixin, SmarterAuthenticatedListAPIView

Plugins list view for smarter api.

contract_model

alias of PluginApiPluginMeta

get_queryset()[source]

Return the plugins that the requesting user has ownership permission for, newest first.

item(row)[source]

A plugin of the response, whose canDelete is the requesting user’s.

serializer_class

alias of PluginMetaSerializer

class smarter.apps.llmtool.api.v1.views.PluginUploadView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

Plugin view for smarter api.

static parse_yaml_file(data)[source]

Parse a plugin manifest, as YAML or else JSON.

Parameters:

data – The manifest: a YAML or JSON string or bytes, or an already parsed dict or list, which is returned as is.

Returns:

The parsed manifest.

Raises:

SmarterValueError – If the data is neither YAML nor JSON.

parser_class = (<class 'rest_framework.parsers.FileUploadParser'>,)
post(request)[source]

Create a plugin from the YAML or JSON manifest in the request body.

Parameters:

request (ASGIRequest) – The request.

Returns:

The response of create_plugin().

put(request)[source]

Create a plugin from the YAML or JSON manifest in the request body.

Parameters:

request (ASGIRequest) – The request.

Returns:

The response of create_plugin().

class smarter.apps.llmtool.api.v1.views.PluginView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

Plugin view for smarter api.

delete(request, plugin_id)[source]

Delete a plugin.

Parameters:
  • request (ASGIRequest) – The request.

  • plugin_id – The plugin’s id, from the url.

Returns:

The response of delete_plugin().

get(request, plugin_id)[source]

Return a plugin’s manifest, if the ALLOW_API_GET waffle switch is active.

Parameters:
  • request (ASGIRequest) – The request.

  • plugin_id – The plugin’s id, from the url.

Returns:

The response of get_plugin(), or 405 if the switch is inactive.

patch(request, plugin_id=None)[source]

Update a plugin from the manifest in the request body.

Parameters:
  • request (ASGIRequest) – The request, whose body is the plugin’s manifest.

  • plugin_id (int | None) – The plugin’s id, from the url, or None to find the plugin by the manifest’s name.

Returns:

The response of update_plugin().

post(request, plugin_id=None)[source]

Update the plugin with the given id from the manifest in the request body, or create one if no id is given.

Parameters:
  • request (ASGIRequest) – The request, whose body is the plugin’s manifest.

  • plugin_id (int | None) – The plugin’s id, from the url.

Returns:

A redirect to the plugin, or an error response.

put(request, plugin_id=None)[source]

Update the plugin with the given id from the manifest in the request body, or create one if no id is given.

Parameters:
  • request (ASGIRequest) – The request, whose body is the plugin’s manifest.

  • plugin_id (int | None) – The plugin’s id, from the url.

Returns:

A redirect to the plugin, or an error response.

smarter.apps.llmtool.api.v1.views.create_plugin(request, data=None)[source]

Create a plugin from a json representation in the body of the request.

Parameters:
  • request – The request. Its user’s profile owns the new plugin.

  • data (dict[str, Any] | None) – The plugin’s manifest. If not given, the request’s parsed body is used.

Returns:

A redirect to the new plugin in the plugins api, or an error response.

smarter.apps.llmtool.api.v1.views.delete_plugin(request, plugin_id)[source]

Delete a plugin by id.

Parameters:
  • request – The request.

  • plugin_id – The id of the plugin to delete.

Returns:

A redirect to the plugins list, or an error response.

smarter.apps.llmtool.api.v1.views.get_plugin(request, plugin_id)[source]

Get a plugin’s manifest, by id, if the user may read the plugin.

A plugin that the user may not read is not found, so that the plugins of other accounts are not disclosed. Errors are Django REST framework’s {"detail": ...}.

smarter.apps.llmtool.api.v1.views.update_plugin(request, plugin_id=None)[source]

Update a plugin from a json representation in the body of the request.

Parameters:

plugin_id (int | None) – The id of the plugin to update, from the url. If provided, it must be the plugin that the manifest names.