recordtransfer.models - Data Models
- class recordtransfer.models.User(*args, **kwargs)
The main User object used to authenticate users
- get_full_name()
Return the first_name plus the last_name, with a space in between.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class recordtransfer.models.UploadSession(*args, **kwargs)
Represents a file upload session. This model is used to track the files that a user uploads during a session.
The following state diagram illustrates the possible states and transitions for an UploadSession:
flowchart TD CREATED --> EXPIRED CREATED --> UPLOADING UPLOADING --> CREATED UPLOADING --> EXPIRED UPLOADING --> COPYING_IN_PROGRESS UPLOADING --> REMOVING_IN_PROGRESS COPYING_IN_PROGRESS --> COPYING_FAILED COPYING_IN_PROGRESS --> STORED STORED --> COPYING_IN_PROGRESS STORED --> REMOVING_IN_PROGRESS REMOVING_IN_PROGRESS --> CREATEDUploadSession State Diagram
- class SessionStatus(value)
The status of the session.
- classmethod new_session(user: User | None = None) UploadSession
Start a new upload session.
- property upload_size: int
Get total size (in bytes) of all uploaded files in this session. This includes the size of both temporary and permanent files.
- property file_count: int
Get the total count of temporary + permanent uploaded files.
- property expires_at: datetime | None
Calculate this session’s expiration time. Only sessions in the CREATED, UPLOADING, or EXPIRED state can have an expiration time. Returns None for sessions in other states, or if the upload session expiry feature is disabled.
- property is_expired: bool
Determine if this session has expired. A session is considered expired if it is in the EXPIRED state, or if it has gone past its expiration time.
- property expires_soon: bool
Determine if this session will expire within the set expiration reminder time.
- expires_within(minutes: int) bool
Determine if this session will expire within the given number of minutes.
- Parameters:
minutes – The number of minutes in the future to check for expiration.
- Returns:
True if the session will expire before the given number of minutes from now, False otherwise.
- expire() None
Set the status of this session to EXPIRED, but only if the current status is CREATED or UPLOADING.
- Raises:
ValueError – If the current status is not CREATED or UPLOADING.
- touch(save: bool = True) None
Reset the last upload interaction time to the current time.
- add_temp_file(file: UploadedFile) TempUploadedFile
Add a temporary uploaded file to this session.
- remove_temp_file_by_name(name: str) None
Remove a temporary uploaded file from this session by name.
- get_temp_file_by_name(name: str) TempUploadedFile
Get an temporary uploaded file in this session by name.
- Parameters:
name – The name of the file to find
- get_temporary_uploads() list[TempUploadedFile]
Get a list of temporary uploaded files associated with this session.
May be empty if temp uploads have already been moved to permanent storage.
- get_permanent_uploads() list[PermUploadedFile]
Get a list of permanent uploaded files associated with this session.
May be empty if temp uploads have not been moved.
- get_uploads() list[TempUploadedFile] | list[PermUploadedFile]
Get a list of temporary or permanent uploaded files associated with this session. Will return temporary files if in the UPLOADING state, and permanent files if in the STORED state.
- remove_temp_uploads(save: bool = True) None
Remove all temp uploaded files associated with this session.
- make_uploads_permanent(logger: Logger | None = None) None
Make all temporary uploaded files associated with this session permanent.
- Parameters:
logger – Optional logger instance to use for logging operations
- copy_session_uploads(destination: str, logger: Logger | None = None) tuple[list[str], list[str]]
Copy permanent uploaded files associated with this session to a destination directory.
- Parameters:
destination – The destination directory
logger – A logger object
- Returns:
A tuple containing lists of copied and missing files
- get_quantity_and_unit_of_measure() str
Create a human-readable statement of how many files are in this session.
If the session is in the state UPLOADING, returns a count of temp files. If the session is in the state STORED, returns a count of permanent files. If the session is in the state CREATED, returns an appropriate value that indicates the lack of files.
Uses the ACCEPTED_FILE_FORMATS setting to group file types together.
- Returns:
A human readable count and size of all files in this session.
- exception DoesNotExist
- exception MultipleObjectsReturned
- recordtransfer.models.session_upload_location(instance, filename: str) str
Generate the upload location for a session file.
- class recordtransfer.models.BaseUploadedFile(*args, **kwargs)
Base class for uploaded files with shared methods.
- property exists: bool
Determine if the file this object represents exists on the file system.
- Returns:
True if file exists, False otherwise
- Return type:
(bool)
- copy(new_path: str) None
Copy this file to a new path.
- Parameters:
new_path – The new path to copy this file to
- remove() None
Remove this file from the file system.
- get_file_media_url() str
Generate the media URL to this file.
- Raises:
FileNotFoundError if the file does not exist. –
- get_file_access_url() str
Generate URL to request access for this file.
- class recordtransfer.models.TempUploadedFile(*args, **kwargs)
Represent a temporary file that a user uploaded during an upload session.
- move_to_permanent_storage() None
Move the file from TempFileStorage to UploadedFileStorage.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class recordtransfer.models.PermUploadedFile(*args, **kwargs)
Represent a file that a user uploaded and has been stored.
- exception DoesNotExist
- exception MultipleObjectsReturned
- recordtransfer.models.delete_file_on_model_delete(sender: TempUploadedFile | PermUploadedFile, instance: TempUploadedFile | PermUploadedFile, **kwargs) None
Delete the actual file when an uploaded file model instance is deleted.
- Parameters:
sender – The model class that sent the signal
instance – The model uploaded file instance being deleted
**kwargs – Additional keyword arguments passed to the signal handler
- class recordtransfer.models.SubmissionGroup(*args, **kwargs)
Represents a group of submissions.
- name
The name of the group
- Type:
CharField
- description
A description of the group
- Type:
TextField
- created_by
The user who created the group
- Type:
ForeignKey
- uuid
A unique ID for the group
- Type:
UUIDField
- get_absolute_url() str
Return the URL to access a detail view of this submission group.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class recordtransfer.models.Submission(*args, **kwargs)
The object that represents a user’s submission, including metadata, and the files they submitted.
- submission_date
The date and time the submission was made
- Type:
DateTimeField
- raw_form
A pickled object containing the transfer form as it was submitted
- Type:
BinaryField
- metadata
Foreign key to a
Metadataobject. The metadata object is generated from the form metadata, and any defaults that have been set in the settings- Type:
OneToOneField
- part_of_group
The group that this submission is a part of
- Type:
ForeignKey
- upload_session
The upload session associated with this submission. If file uploads are disabled, this will always be NULL/None
- Type:
- uuid
A unique ID for the submission
- Type:
UUIDField
- bag_name
A name that is used when the Submission is to be dumped to the file system as a BagIt bag
- Type:
str
- generate_bag_name() None
Generate a name suitable for a submission bag, and set self.bag_name to that name.
- Raises:
ValueError – If there is no metadata or no user associated with this submission.
- property user_folder: str
Get the location of the submission user’s bag storage folder.
- Raises:
FileNotFoundError – If BAG_STORAGE_FOLDER is not set.
ValueError – If there is no user associated with this submission.
- property location: str
Get the location on the file system for the BagIt bag for this submission.
- Raises:
ValueError – If there is no user associated with this submission.
- property extent_statements
Return the first extent statement for this submission.
- get_admin_metadata_change_url()
Get the URL to change the metadata object in the admin
- get_admin_change_url()
Get the URL to change this object in the admin
- get_admin_report_url()
Get the URL to generate a report for this object in the admin
- get_admin_zip_url()
Get the URL to generate a zipped bag for this object in the admin
- make_bag(algorithms: str | list = 'sha512', file_perms: str = '644', logger: Logger | None = None)
Create a BagIt bag on the file system for this Submission. The location of the BagIt bag is determined by self.location. Checks the validity of the Bag post-creation to ensure that integrity is maintained. The data payload files come from the UploadSession associated with this submission.
- Parameters:
algorithms (Union[str, list]) – The algorithms to generate the BagIt bag with
file_perms (str) – A string-based octal “chmod” number
logger – A logger instance (optional)
- remove_bag()
Remove the BagIt bag if it exists.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class recordtransfer.models.Job(*args, **kwargs)
A background job executed by an admin user.
- class JobStatus(value)
The status of the bag’s review.
- get_admin_change_url() str
Get the URL to change this object in the admin.
- get_admin_download_url() str
Get the URL to download the attached file from the admin.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class recordtransfer.models.InProgressSubmission(*args, **kwargs)
A submission that is in progress, created when a user saves a submission form.
- uuid
A unique ID for the submission
- user
The user who is submitting the form
- last_updated
The last time the form was updated
- current_step
The current step the user is on
- step_data
The data contained in the form
- title
The accession title of the submission
- clean() None
Validate the current step value. This gets called when the model instance is modified through a form.
- property upload_session_expires_at: datetime | None
Get the expiration time of the upload session associated with this submission.
- property upload_session_expired: bool
Determine if the associated upload session has expired or not.
- property upload_session_expires_soon: bool
Determine if the associated upload session is expiring soon or not.
- get_resume_url() str
Get the URL to access and resume the in-progress submission.
- reset_reminder_email_sent() None
Reset the reminder email flag to False, if it isn’t already False.
- exception DoesNotExist
- exception MultipleObjectsReturned
- recordtransfer.models.update_upon_save(sender: InProgressSubmission, instance: InProgressSubmission, **kwargs) None
Update the last upload interaction time of the associated upload session when the InProgressSubmission is saved, and reset the reminder email flag, if an upload session exists.