User
User views for smarter api.
- smarter.apps.account.api.v1.views.user.USER_CREATE_FIELDS = ('username', 'password', 'email', 'first_name', 'last_name')
The fields of a new user that the request body may set.
('username', 'password', 'email', 'first_name', 'last_name')
- smarter.apps.account.api.v1.views.user.USER_UPDATE_FIELDS = ('username', 'email', 'first_name', 'last_name', 'is_active')
The fields of a user that the request body may update.
('username', 'email', 'first_name', 'last_name', 'is_active')
- class smarter.apps.account.api.v1.views.user.UserListView(*args, **kwargs)[source]
Bases:
AccountListViewBaseUser list view for smarter api.
- get_list(request)[source]
Get a list of all users the requesting user has access to, as
AccountApiUserDetailmodels.
- get_queryset()[source]
Return every User for a superuser, else the Users of the request user’s Accounts.
- Returns:
The queryset, or an error
Responsewhen the user or its UserProfile is not found.
- serializer_class
alias of
UserSerializer
- class smarter.apps.account.api.v1.views.user.UserView(*args, **kwargs)[source]
Bases:
AccountViewBaseUser view for smarter api.
- delete(request, user_id)[source]
Delete a user, and send
api_request_completed.- Parameters:
request – The request.
user_id – The User’s id.
- Returns:
The response of
delete_user().
- get(request, user_id)[source]
Return a user as json, and send
api_request_completed.- Parameters:
request – The request.
user_id (
int) – The User’s id.
- Returns:
The response of
get_user().
- handle_exception(exc)[source]
Answer an Http404 with a json 404 response, and leave any other exception to DRF.
- Parameters:
exc – The exception that the view raised.
- Returns:
The response.
- patch(request, user_id)[source]
Update a user from the request body, and send
api_request_completed.- Parameters:
request – The request.
user_id (
int) – The User’s id.
- Returns:
The response of
update_user().
- post(request, user_id=None)[source]
Create a user from the request body, and send
api_request_completed.- Parameters:
- Returns:
The response of
create_user().
- smarter.apps.account.api.v1.views.user.create_user(request)[source]
Create an account from a json representation in the body of the request.
- smarter.apps.account.api.v1.views.user.delete_user(request, user_id=None)[source]
Delete a user and its UserProfile, in one transaction.
- smarter.apps.account.api.v1.views.user.eval_permissions(request, user_to_update, user_to_update_profile=None)[source]
Check that the request user may modify a user.
A superuser may modify anyone. Anyone else needs a UserProfile, and may only modify users of their own Account; a non-staff user may only modify themself.
- Parameters:
request – The request.
user_to_update (
User) – The User to modify.user_to_update_profile (
UserProfile|None) – The UserProfile ofuser_to_update, if it has one.
- Returns:
None if the request user may modify the user, else a 401
JsonResponse.
- smarter.apps.account.api.v1.views.user.get_user(request, user_id=None)[source]
Get a user’s json representation, an
AccountApiUserDetail, by id.A superuser may get any user, a staff user the users of their own Account, and anyone else only themself.
- smarter.apps.account.api.v1.views.user.get_user_for_operation(request, user_id)[source]
Look up a User and its UserProfile by the User’s id.
- Parameters:
request – The request, whose user must be a
User.user_id (
int) – The User’s id.
- Return type:
- Returns:
The User and its UserProfile, or a 401 or 400
JsonResponsewhen the request user is not a User, or the User or its UserProfile does not exist.
- smarter.apps.account.api.v1.views.user.update_user(request, user_id)[source]
Update a user from a json representation in the body of the request.
Only the fields in
USER_UPDATE_FIELDSare changed, and the request user needs the permissions thateval_permissions()checks.- Parameters:
request (
Request) – The request, whose body is a json dict of the fields to change.user_id (
int) – The User’s id.
- Returns:
The response: the updated user, or an error
JsonResponse.
- smarter.apps.account.api.v1.views.user.user_response(user)[source]
The response of a user: its
AccountApiUserDetail.- Parameters:
user (django.contrib.auth.models.User) – The user.
- Returns:
The response.
- Return type:
Response