utils
DirectoryTree
dataclass
This dataclass is used as Storage backends in Django are not guaranteed to support os.walk type functionality.
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
The relative path of the directory as a string. |
files |
str
|
A list of filenames contained in the directory. |
children |
list[DirectoryTree]
|
A list of DirectoryTree objects representing child directories. |
add_child
Adds a child directory to the tree and recursively adds its children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child_name
|
str
|
The name of the child directory. |
required |
storage
|
Storage
|
The storage instance to use. |
default_storage
|
Source code in src/prune_media/utils.py
get_empty_child_directories
Get a list of empty child directories within the tree.
Returns:
Type | Description |
---|---|
list[str]
|
list of empty child directory paths as strings |
Source code in src/prune_media/utils.py
get_file_paths
Get a list of all file paths within the tree
Returns:
Type | Description |
---|---|
list[str]
|
list of file paths as strings |
Source code in src/prune_media/utils.py
FieldListing
dataclass
Represents a given model field within the Django project.
Attributes:
Name | Type | Description |
---|---|---|
app_label |
str
|
The app label the field belongs to. |
model_name |
str
|
The model label that the field belongs to. |
field_name |
str
|
The field name. |
get_all_file_fields
Get all fields in the project where a field is an instance or subclass of django.db.models.FileField.
Returns:
Type | Description |
---|---|
list[FieldListing]
|
list of fields as tuples with "app_label", "model_name", "field_name" |
Source code in src/prune_media/utils.py
get_empty_media_directories
Get a list of empty media directories found in the supplied storage instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage_backend
|
Storage
|
a Django Storage instance |
default_storage
|
Returns:
Type | Description |
---|---|
list[str]
|
list of empty media directory paths as strings |
Source code in src/prune_media/utils.py
get_media_paths
Get a list of all media files found in the supplied storage instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage_backend
|
Storage
|
a Django Storage instance |
default_storage
|
Returns:
Type | Description |
---|---|
list[str]
|
list of media file paths as strings |
Source code in src/prune_media/utils.py
get_referenced_file_paths
Get a list of all file paths from the supplied field data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields
|
list[tuple[str, str, str]]
|
list of fields as tuples with "app_label", "model_name", "field_name" |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of file paths as strings |
Source code in src/prune_media/utils.py
get_unreferenced_media_paths
Get a list of media files that are not referenced by Django FileFields
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage_backend
|
Storage
|
a Django Storage instance |
default_storage
|
Returns:
Type | Description |
---|---|
list[str]
|
list of media file paths as strings |