recordtransfer.models - Models for recordtransfer app

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

Bases: AbstractUser

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.

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.

language

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

phone_number

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

address_line_1

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

address_line_2

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

city

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

province_or_state

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

other_province_or_state

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

postal_or_zip_code

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

country

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

property full_name: str

Return the full name of the user, which is a combination of first and last names.

property has_contact_info: bool

Check if user has complete contact information.

past_password_hashes(limit: int = 5) list

Get the past N hashes of this user’s previous password.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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_language_display(*, field=<django.db.models.fields.CharField: language>)
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.

password_history

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.

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

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.PasswordHistory(*args, **kwargs)

Bases: Model

Store a user’s previous password hashes for history validation.

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.

password

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

changed_at

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

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_next_by_changed_at(*, field=<django.db.models.fields.DateTimeField: changed_at>, is_next=True, **kwargs)
get_previous_by_changed_at(*, field=<django.db.models.fields.DateTimeField: changed_at>, 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
recordtransfer.models.add_previous_password_to_history(instance: User, **kwargs) None

Handle password history when User password changes.

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

Bases: Model

A model to store configurable site settings that administrators can modify through the Django admin interface without requiring code changes.

This model supports caching of settings values for improved performance.

Adding a New Setting

To add a new setting to the database, follow these steps:

  1. Add a new entry to the SiteSettingKey enum class:

    Add your new setting key to the SiteSetting enum in recordtransfer/enums.py. The key should be descriptive and follow existing naming conventions (i.e., all uppercase with underscores). Include a SettingKeyMeta with the value type, description, and optional default value.

    Example:

    NEW_SETTING_NAME = SettingKeyMeta(
        SiteSettingType.STR,
        _("Description of what this setting controls."),
        default_value="Default string value",
    )
    
  2. Create a data migration:

    Create a Django data migration to add the setting to the database. The migration should create a new SiteSetting instance with the required fields:

    • key: Must be unique and match the enum name (string)

    • value: The default value as a string (must use the enum’s default_value if available)

    • value_type: Either “int” for integers or “str” for strings

    Example migration for a string setting:

    from django.db import migrations
    
    
    def add_new_setting(apps, schema_editor):
        SiteSetting = apps.get_model("recordtransfer", "SiteSetting")
        SiteSetting.objects.get_or_create(
            key="NEW_SETTING_NAME",
            defaults={"value": "Default string value", "value_type": "str"},
        )
    
    
    class Migration(migrations.Migration):
        dependencies = [
            ("recordtransfer", "XXXX_previous_migration"),
        ]
    
        operations = [
            migrations.RunPython(add_new_setting),
        ]
    
  3. Validation requirements:

    • The key field must be unique across all settings

    • For value_type “int”: the value must be a valid string representation of an integer (e.g., “42”, “-1”, “0”)

    • For value_type “str”: the value can be any string

    • change_date is auto-generated and changed_by does not need to be set

  4. Document the new setting:

    Add an entry for the new setting to docs/admin_guide/site_settings.rst.

Removing a Setting

To remove an existing setting from the database:

  1. Remove the key from the SiteSettingKey enum class:

    Delete the corresponding enum entry from the SiteSetting enum in enums.py.

  2. Create a data migration:

    Create a Django data migration to remove the setting from the database:

    from django.db import migrations
    
    
    def remove_old_setting(apps, schema_editor):
        SiteSetting = apps.get_model("recordtransfer", "SiteSetting")
        SiteSetting.objects.filter(key="OLD_SETTING_NAME").delete()
    
    
    class Migration(migrations.Migration):
        dependencies = [
            ("recordtransfer", "XXXX_previous_migration"),
        ]
    
        operations = [
            migrations.RunPython(remove_old_setting),
        ]
    
  3. Update code references:

    Remove any code that references the old setting key.

  4. Update documentation:

    Remove the setting from docs/admin_guide/site_settings.rst.

Retrieving Settings in Code

Once a setting has been added to the database, retrieve it using the appropriate static method:

  • For string settings:

    value = SiteSetting.get_value_str(SiteSettingKey.SETTING_NAME)
    
  • For integer settings:

    value = SiteSetting.get_value_int(SiteSettingKey.SETTING_NAME)
    
key

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

value

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

value_type

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

change_date

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

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

set_cache(value: str | int | None) None

Cache the value of this setting.

static get_value_str(key: SiteSettingKey) str | None

Get the value of a site setting of type SettingType.STR by its key.

Parameters:

key – The key of the setting to retrieve.

Returns:

The value of the setting as a string, cached if available, or fetched from the database.

Raises:

ValidationError – If the setting is not of type SettingType.STR.

static get_value_int(key: SiteSettingKey) int | None

Get the value of a site setting of type SettingType.INT by its key.

Parameters:

key – The key of the setting to retrieve.

Returns:

The value of the setting as an integer, cached if available, or fetched from the database.

Raises:

ValidationError – If the setting is not of type SettingType.INT.

reset_to_default(user: User | None = None) None

Reset this setting to its default value as defined in the SiteSettingKey enum.

Parameters:

user – The user who initiated the reset operation (optional).

property default_value: str | None

Get the default value for this setting, if available. The default value is defined in the SiteSettingKey enum, in the form of a string.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

changed_by_id
get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)
get_value_type_display(*, field=<django.db.models.fields.CharField: value_type>)
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>
recordtransfer.models.update_cache_post_save(sender: SiteSetting, instance: SiteSetting, created: bool, **kwargs) None

Update cached value when setting is saved, but not on creation.

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

Bases: Model

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

UploadSession State Diagram

class SessionStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: TextChoices

The status of the session.

CREATED = 'CR'
EXPIRED = 'EX'
UPLOADING = 'UG'
COPYING_IN_PROGRESS = 'CP'
STORED = 'SD'
COPYING_FAILED = 'FD'
REMOVING_IN_PROGRESS = 'RP'
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.

last_upload_interaction_time

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

objects = <recordtransfer.managers.UploadSessionManager object>
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_file_by_name(name: str) BaseUploadedFile

Get an uploaded file in this session by name. The file can be either temporary or permanent.

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

Make all temporary uploaded files associated with this session permanent.

copy_session_uploads(destination: str) tuple[list[str], list[str]]

Copy permanent uploaded files associated with this session to a destination directory.

Parameters:

destination – The destination directory

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

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_next_by_last_upload_interaction_time(*, field=<django.db.models.fields.DateTimeField: last_upload_interaction_time>, is_next=True, **kwargs)
get_next_by_started_at(*, field=<django.db.models.fields.DateTimeField: started_at>, is_next=True, **kwargs)
get_previous_by_last_upload_interaction_time(*, field=<django.db.models.fields.DateTimeField: last_upload_interaction_time>, is_next=False, **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.

in_progress_submission

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

In the example:

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

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: TempUploadedFile, filename: str) str

Generate the upload location for a session file.

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

Bases: Model

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

Bases: object

Meta information for the BaseUploadedFile model.

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)

Bases: BaseUploadedFile

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

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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)

Bases: BaseUploadedFile

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

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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)

Bases: Model

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: int

Get the number of submissions in this group.

get_absolute_url() str

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

get_delete_url() str

Return the URL to delete this submission group.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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)

Bases: Model

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

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.

property bag_name: str

Get a name suitable for a submission bag.

The bag name contains the username, the date this submission was made, and the title of the metadata. This file name is properly sanitized to be used as a directory or part of a file name.

Raises:

ValueError – If there is no metadata or no user associated with this submission.

property extent_statements: str

Return the first extent statement for this submission.

get_admin_metadata_change_url() str

Get the URL to change the metadata object in the admin.

get_admin_change_url() str

Get the URL to change this object in the admin.

get_admin_report_url() str

Get the URL to generate a report for this object in the admin.

get_admin_zip_url() str

Get the URL to generate a zipped bag for this object in the admin.

make_bag(location: Path, algorithms: Iterable[str] = ('sha512',), file_perms: str = '644') Bag

Create a BagIt bag on the file system for this Submission. 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.

If given a location to an existing Bag, this function will check whether the Bag can be updated in-place. If not, the Bag will be completely re-generated again.

Raises:
  • ValueError – If any required state is incorrect (e.g., no upload session)

  • FileNotFoundError – If any files are missing when copying to temp location

  • FileExistsError – If the Bag at self.location already exists

  • bagit.BagValidationError – If the Bag is created, but it’s invalid

Parameters:
  • location (Path) – The path to make the Bag at

  • algorithms (Iterable[str]) – The checksum algorithms to generate the BagIt bag with

  • file_perms (str) – A string-based octal “chmod” number

remove_bag(location: Path) None

Remove everything in the Bag, including the Bag folder itself.

remove_bag_contents(location: Path) None

Remove everything in the Bag, but not the Bag directory itself.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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.

metadata_id
objects = <django.db.models.manager.Manager object>
part_of_group_id
upload_session_id
user_id
class recordtransfer.models.Job(*args, **kwargs)

Bases: Model

A background job executed by an admin user.

class JobStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: TextChoices

The status of the bag’s review.

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

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

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)
message_log

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

has_file() bool

Determine if this job has an attached file.

get_file_media_url() str

Generate the media URL to this file.

Raises:

FileNotFoundError if the file does not exist.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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>
user_triggered_id
class recordtransfer.models.InProgressSubmission(*args, **kwargs)

Bases: Model

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'), ('groupsubmission', 'GROUP_SUBMISSION'), ('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.

upload_session

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.

reminder_email_sent

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

objects = <recordtransfer.managers.InProgressSubmissionManager object>
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.

get_delete_url() str

Get the URL to delete this in-progress submission.

reset_reminder_email_sent() None

Reset the reminder email flag to False, if it isn’t already False.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: 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.

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