Account

Account views for smarter api.

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

Bases: ContractListMixin, AccountListViewBase

Account list view for smarter api: AccountApiAccountDetail models.

contract_model

alias of AccountApiAccountDetail

get_queryset()[source]

Return every Account for a superuser, and none for anyone else.

Returns:

The queryset.

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

Bases: AccountViewBase

Account view for smarter api.

Its GET returns an AccountApiAccountDetail.

delete(request, account_id)[source]

Delete an Account.

Parameters:
  • request – The request.

  • account_id (int) – The Account’s id.

Returns:

A redirect to /, or a 500 response when the delete fails.

Raises:

Http404 – when the Account does not exist.

get(request, account_id)[source]

Return an Account as json.

Parameters:
  • request (Request) – The request.

  • account_id (int) – The Account’s id. Only a superuser may read another Account; anyone else gets the Account of their own UserProfile.

Returns:

The AccountApiAccountDetail of the Account.

Raises:

PermissionDenied – when a non-superuser has no UserProfile.

patch(request, account_id)[source]

Update an Account’s fields from the json dict in the request body, and save it.

Keys that are not attributes of the Account are ignored.

Parameters:
  • request (Request) – The request, whose body holds the fields to change.

  • account_id (int) – The Account’s id.

Returns:

The response: 404 when the Account does not exist, 400 when the body or the new values are not valid.

post(request, account_id=None)[source]

Create an Account from the json dict in the request body.

Parameters:
  • request (Request) – The request, whose body holds the Account’s fields.

  • account_id (int | None) – Unused.

Returns:

A redirect to the new Account’s url, or a 400 response when the body is not a json dict or the Account cannot be created.