recordtransfer.views - Views

Home

Views for the homepage and static pages navigable from the home page.

class recordtransfer.views.home.Index(**kwargs)

The homepage.

class recordtransfer.views.home.Help(**kwargs)

The help page.

get_context_data(**kwargs) dict[str, Any]

Add context variables to the template context.

class recordtransfer.views.home.About(**kwargs)

About the application.

get_context_data(**kwargs) dict[str, Any]

Add context variables to the template context.

Account

Views for creating and activating user accounts.

class recordtransfer.views.account.CreateAccount(**kwargs)

Allows a user to create a new account with the SignUpForm. When the form is submitted successfully, send an email to that user with a link that lets them activate their account.

form_class

alias of SignUpForm

dispatch(request: HttpRequest, *args, **kwargs) HttpResponse

If the user is already authenticated, redirect them to the homepage.

form_valid(form: BaseModelForm) HttpResponse

Save the new user and send them an activation email.

form_invalid(form: BaseModelForm) HttpResponse

Handle invalid signup form submissions.

class recordtransfer.views.account.ActivateAccount(**kwargs)

View for activating user accounts via email link.

get(request: HttpRequest, uidb64: str, token: str) HttpResponse

Handle GET request for account activation.

class recordtransfer.views.account.ActivationSent(**kwargs)

The page a user sees after creating an account.

class recordtransfer.views.account.ActivationComplete(**kwargs)

The page a user sees when their account has been activated.

class recordtransfer.views.account.ActivationInvalid(**kwargs)

The page a user sees if their account could not be activated.

class recordtransfer.views.account.Login(**kwargs)

Custom LoginView that supports HTMX requests for login forms.

form_valid(form: AuthenticationForm) HttpResponse

Handle successful login.

form_invalid(form: AuthenticationForm) HttpResponse

Handle invalid login form submissions.

class recordtransfer.views.account.AsyncPasswordResetView(**kwargs)

The page a user sees when they request a password reset.

form_class

alias of AsyncPasswordResetForm

Profile

Views to manage user profile information and view their submission history.

class recordtransfer.views.profile.UserProfile(**kwargs)

Main profile page - handles GET requests only.

get(request: HttpRequest) HttpResponse

Render the user profile page.

class recordtransfer.views.profile.BaseUserProfileUpdateView(**kwargs)

Base view for updating user profile information.

model

alias of User

dispatch(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse

Ensure requests are made with HTMX.

get_object(queryset: QuerySet | None = None) User

Get the user object for the current request.

form_valid(form: BaseModelForm) HttpResponse

Handle valid form submission, return updated form and trigger success event in response.

form_invalid(form: BaseModelForm) HttpResponse

Handle invalid form submission.

class recordtransfer.views.profile.AccountInfoUpdateView(**kwargs)

View to update user account information such as name and notification preferences.

form_class

alias of UserAccountInfoForm

class recordtransfer.views.profile.ContactInfoUpdateView(**kwargs)

View to update user contact information such as email and phone number.

form_class

alias of UserContactInfoForm

recordtransfer.views.profile.delete_in_progress_submission(request: HttpRequest, uuid: str) HttpResponse

Handle GET (show modal) and DELETE (delete submission) for in-progress submissions. Both requests must be made by HTMX, or else a 400 Error is returned.

recordtransfer.views.profile.submission_group_table(request: HttpRequest) HttpResponse

Render the submission group table with pagination.

recordtransfer.views.profile.in_progress_submission_table(request: HttpRequest) HttpResponse

Render the in-progress submission table with pagination.

recordtransfer.views.profile.submission_table(request: HttpRequest) HttpResponse

Render the past submission table with pagination.

class recordtransfer.views.profile.SubmissionGroupModalCreateView(**kwargs)

Renders a modal form to create a new submission group. Handles GET requests to show the modal and POST requests to create the submission group. Both requests must be made by HTMX.

model

alias of SubmissionGroup

form_class

alias of SubmissionGroupForm

dispatch(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse

Ensure requests are made with HTMX.

get_form_kwargs() dict[str, Any]

Pass User instance to form to initialize it.

form_valid(form: BaseModelForm) HttpResponse

Handle valid form submission.

recordtransfer.views.profile.delete_submission_group(request: HttpRequest, uuid: str) HttpResponse

Handle GET (show delete confirmation modal) and DELETE (delete submission group). Both requests must be made by HTMX.

recordtransfer.views.profile.assign_submission_group_modal(request: HttpRequest, uuid: str) HttpResponse

Display a modal that shows the submission group currently assigned to a submission and all available submission groups which the submission can be assigned to.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • uuid (str) – The UUID of the submission.

recordtransfer.views.profile.assign_submission_group(request: HttpRequest) HttpResponse

Assign a submission to a submission group or unassign it.

Media

Views for handling media requests, such as uploading and deleting files. This also includes viewing and listing uploaded files.

recordtransfer.views.media.serve_media_file(file_url: str) HttpResponse

Create a response that allows a client to download a media file.

In development, the development server serves media files directly, so a re-direct to the file’s URL is returned.

In production, NGINX is used, and it serves media files. The media URL is locked down with an “internal” directive, and NGINX must receive an X-Accel-Redirect from the application to tell it that it’s OK to serve the file.

For more info, see: NGINX docs

Note

This function does not do any permission checking. Make sure the client that is asking for a file has the proper permission before calling this function.

Parameters:

file_url – The media URL to serve

Returns:

Direct redirect in development (DEBUG) mode, X-Accel-Redirect in production

Return type:

HttpResponse

recordtransfer.views.media.create_upload_session(request: HttpRequest) JsonResponse

Create a new upload session and return the session token.

Parameters:

request – The POST request sent by the user.

Returns:

The session token of the newly created upload session.

Return type:

JsonResponse

recordtransfer.views.media.upload_or_list_files(request: HttpRequest, session_token: str) JsonResponse

Upload a single file to the server list the files uploaded in a given upload session. The file is added to the upload session using the session token passed as a parameter in the request. If a session token is invalid, an error message is returned.

The file type is checked against this application’s ACCEPTED_FILE_FORMATS setting, if the file is not an accepted type, an error message is returned.

Parameters:
  • request – The HTTP GET or POST request

  • session_token – The upload session token from the URL

Returns:

If the list or upload operation was successful, the session token uploadSessionToken is included in the response. If not successful, the error description error is included.

Return type:

JsonResponse

recordtransfer.views.media.uploaded_file(request: HttpRequest, session_token: str, file_name: str) HttpResponse

Get or delete a file that has been uploaded in a given upload session.

Parameters:
  • request – The HTTP request

  • session_token – The upload session token from the URL

  • file_name – The name of the file to delete

Returns:

In the case of deletion, returns a 204 response when successfully deleted. In the case of getting a file, redirects to the file’s media path in development, or returns an X-Accel-Redirect to the file’s media path if in production.

Return type:

HttpResponse

recordtransfer.views.media.job_file(request: HttpRequest, job_uuid: str) HttpResponse

View to access the attached file associated with a job.

Parameters:
  • request – The HTTP request

  • job_uuid – The UUID of the job

Returns:

Redirects to the file’s media path if the job has an associated file.

Return type:

HttpResponse

Pre-Submission

Views for the submission form and submission process, responsible for creating, saving, and deleting in-progress submissions, as well as handling the final submission.

class recordtransfer.views.pre_submission.SubmissionSent(**kwargs)

The page a user sees when they finish a submission.

class recordtransfer.views.pre_submission.InProgressSubmissionExpired(**kwargs)

The page a user sees when they try to access an expired submission.

class recordtransfer.views.pre_submission.SubmissionFormWizard(*args, **kwargs)

A multi-page form for collecting user metadata and uploading files. Uses a form wizard. For more info, visit this link: https://django-formtools.readthedocs.io/en/latest/wizard.html.

class SubmissionStepMeta(template: str, title: str, form: type[SubmissionForm | BaseFormSet], info_message: str | None = None)

Metadata for each submission step, including the template to render, title, form class, and an optional info message to display on the page.

property current_step: SubmissionStep

Returns the current step as a SubmissionStep enum value.

dispatch(request: HttpRequest, *args, **kwargs) HttpResponse

Dispatch the request to the appropriate handler method.

get(request: HttpRequest, *args, **kwargs) HttpResponse

Handle GET request to load a submission.

load_form_data() None

Load form data from an InProgressSubmission instance.

post(request: HttpRequest, *args, **kwargs) HttpResponse

Handle POST request to save a submission.

save_form_data(request: HttpRequest) None

Save the current state of the form to the database.

Parameters:

request – The HTTP request object.

save_current_step(form: BaseInlineFormSet | BaseModelFormSet | ModelForm) None

Save the data from the current step.

render_goto_step(goto_step: str, *args, **kwargs) HttpResponse

Perform necessary validation and data saving before going to to desired step. Skips validation if the user is trying to go to a previous step. Otherwise, validates each form before the goto step, and takes user to the step with the first error if any form is invalid.

render_next_step(form: BaseForm | BaseFormSet, **kwargs) HttpResponse

Render next step of form. Overrides parent method to clear errors from the form.

trigger_contact_info_save_prompt(form: ContactInfoForm) HttpResponse

Trigger a prompt to save contact info using HTMX.

classmethod format_step_data(step: SubmissionStep, data: QueryDict) dict | list[dict]

Format form data for the current step to be saved for later.

Parameters:
  • step – The current step of the form.

  • data – The data from the form.

Returns:

The formatted step data. If this step represents a formset, the return object will be a list of dicts, otherwise, it will be a dict.

get_form_value(step: SubmissionStep, field: str) str | None

Get the value of a field in a form step.

Parameters:
  • step – The step of the form to get the field value from.

  • field – The field to get the value of.

Returns:

The value of the field in the form step, or None if the is not populated.

get_template_names() list[str]

Override the parent method to return the template name to render for the current step.

get_name_of_user(user: User) str

Get the name of a user.

Tries to get the name from the User object first, and falls back to using the form data submitted in the contact info.

get_form_initial(step: str) dict

Populate the initial state of the form.

Populate form with saved in-progress submission data if a “resume” request was received. Fills in the user’s name and email automatically where possible.

get_form_kwargs(step: str | None = None) dict

Add data to inject when initializing the form.

get_forms_for_review() OrderedDict[str, BaseForm | BaseFormSet]

Retrieve the relevant forms to be processed for the review step. This method does not validate the forms, but populates the cleaned_data attribute of each form.

property review_step_reached: bool

Check if the user has reached the review step at some point throughout this form. This check is valid for a resumed in-progress submission as well.

property form_started: bool

Check if the user has started the form. This is true if there is an in-progress submission, or if the user has submitted any data for the form.

get_context_data(form: BaseForm | BaseFormSet, **kwargs) dict[str, Any]

Retrieve context data for the current form template, including context for the JavaScript files used alongside the template.

Parameters:
  • form – The form to display to the user.

  • **kwargs – Additional keyword arguments.

Returns:

A dictionary of context data to be used to render the form template.

Return type:

dict

done(form_list: list[BaseForm], **kwargs) HttpResponse

Retrieve all of the form data, and creates a Submission from it.

Parameters:
  • form_list – A list of all the forms in the form wizard.

  • **kwargs – Additional keyword arguments.

Returns:

A redirect to the submission sent page, or an error page if there was an unexpected issue creating the submission.

Return type:

HttpResponse

Post-Submission

Views for completed submissions, and creating and managing submission groups.

class recordtransfer.views.post_submission.SubmissionDetailView(**kwargs)

Generates a report for a given submission.

model

alias of Submission

get_object(queryset: QuerySet | None = None) Submission

Retrieve the Submission object based on the UUID in the URL.

get_queryset() QuerySet

Return queryset filtered by user permissions.

get_context_data(**kwargs: Any) dict[str, Any]

Pass context variables to the template.

recordtransfer.views.post_submission.submission_csv_export(request: HttpRequest, uuid: str) HttpResponse

Generate and download a CSV for a specific submission.

recordtransfer.views.post_submission.submission_group_bulk_csv_export(request: HttpRequest, uuid: str) HttpResponse

Generate and download a CSV for all submissions in a submission group.

class recordtransfer.views.post_submission.SubmissionGroupDetailView(**kwargs: Any)

Handles updating and viewing details of a submission group.

model

alias of SubmissionGroup

form_class

alias of SubmissionGroupForm

get_object(queryset: QuerySet | None = None) SubmissionGroup

Return the SubmissionGroup for the given UUID, only if owned by the user. Raises 404 if not found or not owned.

get_queryset() QuerySet

Restrict queryset to groups created by the current user.

get_context_data(**kwargs: Any) dict[str, Any]

Pass submissions associated with the group to the template.

get_form_kwargs() dict[str, Any]

Pass User instance to form to initialize it.

form_valid(form: BaseModelForm) HttpResponse

Handle valid form submission.

form_invalid(form: BaseModelForm) HttpResponse

Handle invalid form submission.

recordtransfer.views.post_submission.get_user_submission_groups(request: HttpRequest) JsonResponse

Return a JSON response containing all submission groups created by the specified user.