recordtransfer.models - Data Models

class recordtransfer.models.User(*args, **kwargs)

The main User object used to authenticate users

gets_submission_email_updates

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

confirmed_email

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

gets_notification_emails

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_full_name()

Return the first_name plus the last_name, with a space in between.

exception DoesNotExist
exception MultipleObjectsReturned
date_joined

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

email

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

first_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=True, **kwargs)
get_previous_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=False, **kwargs)
groups

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

inprogresssubmission_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

is_active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_staff

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_superuser

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

job_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

last_login

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

logentry_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

password

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

submission_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

submissiongroup_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

uploadsession_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

user_permissions

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

username

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

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 --> DELETED
    

UploadSession State Diagram

class SessionStatus(value)

The status of the session.

CREATED = 'CR'
EXPIRED = 'EX'
UPLOADING = 'UG'
COPYING_IN_PROGRESS = 'CP'
STORED = 'SD'
COPYING_FAILED = 'FD'
REMOVING_IN_PROGRESS = 'RP'
DELETED = 'DL'
token

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

started_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

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.

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_uploads() None

Remove all 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

exception DoesNotExist
exception MultipleObjectsReturned
get_next_by_started_at(*, field=<django.db.models.fields.DateTimeField: started_at>, is_next=True, **kwargs)
get_previous_by_started_at(*, field=<django.db.models.fields.DateTimeField: started_at>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.CharField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
permuploadedfile_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

submission_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

tempuploadedfile_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

user_id
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.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

session

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

file_upload

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
class Meta
abstract = False
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.

session_id
class recordtransfer.models.TempUploadedFile(*args, **kwargs)

Represent a temporary file that a user uploaded during an upload session.

file_upload

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
move_to_permanent_storage() None

Move the file from TempFileStorage to UploadedFileStorage.

exception DoesNotExist
exception MultipleObjectsReturned
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
session

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

session_id
class recordtransfer.models.PermUploadedFile(*args, **kwargs)

Represent a file that a user uploaded and has been stored.

file_upload

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
exception DoesNotExist
exception MultipleObjectsReturned
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
session

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

session_id
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

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

uuid

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property number_of_submissions_in_group
get_absolute_url() str

Return the URL to access a detail view of this submission group.

exception DoesNotExist
exception MultipleObjectsReturned
created_by_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
submission_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

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

user

The user who submitted the metadata (and optionally, files)

Type:

User

raw_form

A pickled object containing the transfer form as it was submitted

Type:

BinaryField

metadata

Foreign key to a Metadata object. 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:

UploadSession

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

submission_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

raw_form

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

metadata

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

part_of_group

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

upload_session

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

uuid

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

bag_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.ManagerFromSubmissionQuerySet object>
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
get_next_by_submission_date(*, field=<django.db.models.fields.DateTimeField: submission_date>, is_next=True, **kwargs)
get_previous_by_submission_date(*, field=<django.db.models.fields.DateTimeField: submission_date>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

job

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

metadata_id
part_of_group_id
upload_session_id
user_id
class recordtransfer.models.Job(*args, **kwargs)

A background job executed by an admin user

class JobStatus(value)

The status of the bag’s review

NOT_STARTED = 'NS'
IN_PROGRESS = 'IP'
COMPLETE = 'CP'
FAILED = 'FD'
start_time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

end_time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user_triggered

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

job_status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

attached_file

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
submission

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

get_admin_change_url()

Get the URL to change this object in the admin

get_admin_download_url()

Get the URL to download the attached file from the admin

exception DoesNotExist
exception MultipleObjectsReturned
get_job_status_display(*, field=<django.db.models.fields.CharField: job_status>)
get_next_by_start_time(*, field=<django.db.models.fields.DateTimeField: start_time>, is_next=True, **kwargs)
get_previous_by_start_time(*, field=<django.db.models.fields.DateTimeField: start_time>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
submission_id
user_triggered_id
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

STEP_CHOICES: ClassVar = [('acceptlegal', 'ACCEPT_LEGAL'), ('contactinfo', 'CONTACT_INFO'), ('sourceinfo', 'SOURCE_INFO'), ('recorddescription', 'RECORD_DESCRIPTION'), ('rights', 'RIGHTS'), ('otheridentifiers', 'OTHER_IDENTIFIERS'), ('grouptransfer', 'GROUP_TRANSFER'), ('uploadfiles', 'UPLOAD_FILES'), ('finalnotes', 'FINAL_NOTES'), ('review', 'REVIEW')]
uuid

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

last_updated

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

current_step

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

step_data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

clean() None

Validate the current step value.

exception DoesNotExist
exception MultipleObjectsReturned
get_current_step_display(*, field=<django.db.models.fields.CharField: current_step>)
get_next_by_last_updated(*, field=<django.db.models.fields.DateTimeField: last_updated>, is_next=True, **kwargs)
get_previous_by_last_updated(*, field=<django.db.models.fields.DateTimeField: last_updated>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
user_id