Views¶
- class tom_common.views.GroupCreateView(**kwargs)¶
View that handles creation of a user
Group. Requires authorization.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- model¶
alias of
Group
- class tom_common.views.GroupDeleteView(**kwargs)¶
View that handles deletion of a user
Group. Requires authorization.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- model¶
alias of
Group
- class tom_common.views.GroupUpdateView(**kwargs)¶
View that handles modification of a user
Group. Requires authorization.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- model¶
alias of
Group
- get_initial(*args, **kwargs)¶
Adds the
Userobjects that are associated with thisGroupto the initial data.- Returns:
list of users
- Return type:
QuerySet
- class tom_common.views.UserListView(**kwargs)¶
View that handles display of the list of
UserandGroupobjects. Requires authentication.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- class tom_common.views.UserDeleteView(**kwargs)¶
View that handles deletion of a
User. Requires login.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- model¶
alias of
User
- dispatch(*args, **kwargs)¶
Directs the class-based view to the correct method for the HTTP request method. Ensures that non-superusers are not incorrectly updating the profiles of other users.
- class tom_common.views.RegenerateAPITokenView(**kwargs)¶
View that handles regeneration of a User’s DRF API token. Requires login.
Deletes the existing token (if any) and creates a new one. For HTMX requests, returns the api_token partial with the new token. For non-HTMX requests, redirects to the user update page with a success message.
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- dispatch(*args, **kwargs)¶
Ensure non-superusers can only regenerate their own token.
Checks authentication first (via LoginRequiredMixin), then checks that non-superusers are only operating on their own token.
- class tom_common.views.UserProfileView(**kwargs)¶
View to handle creating a user profile page. Requires a login.
Note: This is NOT a User Detail view that would require a primary Key tying it to a specific user. This is a profile page that always displays the information for the logged in user. A User Detail view would allow admin users to view the profile of any user which is not what we want here for security reasons.
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- class tom_common.views.UserPasswordChangeView(**kwargs)¶
View that handles modification of the password for a
User. Requires authorization.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- get_context_data(**kwargs)¶
Add the user object to the context for all templates.
- get(request, *args, **kwargs)¶
On a GET request, show a confirmation page before allowing the password change. This follows the pattern of Django’s DeleteView, but bypasses the confirmation if a superuser is changing their own password.
- post(request, *args, **kwargs)¶
A POST can come from the confirmation page (to show the form) or from the password change form itself (to perform the change).
- form_valid(form)¶
Called after form is validated. Updates the password for the current specified user.
- class tom_common.views.UserCreateView(**kwargs)¶
View that handles
Usercreation. Requires authorization.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- form_class¶
alias of
CustomUserCreationForm
- class tom_common.views.UserUpdateView(**kwargs)¶
View that handles
Usermodification. Requires authentication to call, and authorization to update.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- model¶
alias of
User
- form_class¶
alias of
CustomUserCreationForm
- get_success_url()¶
Returns the redirect URL for a successful update. If the current user is a superuser, returns the URL for the user list. Otherwise, returns the URL for updating the current user.
- Returns:
URL for user list or update user
- Return type:
str
- get_context_data(**kwargs)¶
Add current user and API token to the context for all templates.
- get_form(form_class=None)¶
Gets the user update form and removes the password requirement. Removes the groups field if the user is not a superuser.
- Returns:
Form used by this view
- Return type:
CustomUserCreationForm
- dispatch(*args, **kwargs)¶
Directs the class-based view to the correct method for the HTTP request method. Ensures that non-superusers are not incorrectly updating the profiles of other users.
- form_valid(form)¶
Called after form is validated. Updates the session hash if the password was changed to keep the user logged in, and ensures the UserSession is updated to the new session.
- Parameters:
form (django.forms.Form) – User creation form
- class tom_common.views.CommentDeleteView(**kwargs)¶
View that handles deletion of a
Comment. Requires authentication to call, and authorization to delete.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- model¶
alias of
Comment
- form_valid(form)¶
Checks if the user is authorized to delete the comment and then proceeds with deletion.
- tom_common.views.robots_txt(request)¶
A function-based view that handles the robots.txt content.
The default robots.txt is defined here. It disallows everything from everyone.
If you want to change that, we check for a path to a custom robots.txt file defined in settings.py as ROBOTS_TXT_PATH. If you set ROBOTS_TXT_PATH in your settings.py, then that file will be served instead of the default.