Media
This package contains all media-related models:
MediaFile
and
Directory
Directory
- class integreat_cms.cms.models.media.directory.Directory(*args, **kwargs)[source]
Bases:
AbstractBaseModel
Model representing a directory containing documents. This is only a virtual directory and does not necessarily exist on the actual file system. Each directory is tied to a region.
- Parameters:
id (BigAutoField) – Primary key: ID
name (CharField) – Name
created_date (DateTimeField) – Creation date. The date and time when the directory was created
is_hidden (BooleanField) – Hidden. Whether the directory is hidden in the regional media library
Relationship fields:
- Parameters:
region (
ForeignKey
toRegion
) – Region (related name:media_directories
)parent (
ForeignKey
toDirectory
) – Parent directory (related name:subdirectories
)
Reverse relationships:
- Parameters:
subdirectories (Reverse
ForeignKey
fromDirectory
) – All subdirectories of this media directory (related name ofparent
)files (Reverse
ForeignKey
fromMediaFile
) – All files of this media directory (related name ofparent_directory
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- get_repr() str [source]
This overwrites the default Django
__repr__()
method which would return<Directory: Directory object (id)>
. It is used for logging.- Returns:
The canonical string representation of the directory
- Return type:
Media File
This module contains the MediaFile
model as well as the helper functions
upload_path()
and upload_path_thumbnail()
which
are used to determine the file system path to which the files should be uploaded.
- class integreat_cms.cms.models.media.media_file.MediaFile(*args, **kwargs)[source]
Bases:
AbstractBaseModel
The MediaFile model is used to store basic information about files which are uploaded to the CMS. This is only a virtual document and does not necessarily exist on the actual file system. Each document is tied to a region via its directory.
- Parameters:
id (BigAutoField) – Primary key: ID
file (FileField) – File
thumbnail (FileField) – Thumbnail file
file_size (IntegerField) – File size
type (CharField) – File type
name (CharField) – Name
alt_text (CharField) – Description
uploaded_date (DateTimeField) – Uploaded date. The date and time when the media file was uploaded
last_modified (DateTimeField) – Last modified. The date and time when the physical media file was last modified
is_hidden (BooleanField) – Hidden. Whether the media file is hidden in the regional media library
Relationship fields:
- Parameters:
parent_directory (
ForeignKey
toDirectory
) – Parent directory (related name:files
)region (
ForeignKey
toRegion
) – Region (related name:files
)
Reverse relationships:
- Parameters:
icon_regions (Reverse
ForeignKey
fromRegion
) – All icon regions of this media file (related name oficon
)icon_organizations (Reverse
ForeignKey
fromOrganization
) – All icon organizations of this media file (related name oficon
)pois (Reverse
ForeignKey
fromPOI
) – All pois of this media file (related name oficon
)events (Reverse
ForeignKey
fromEvent
) – All events of this media file (related name oficon
)pages (Reverse
ForeignKey
fromPage
) – All pages of this media file (related name oficon
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- content_usages[source]
Check where this media file is embedded in the content
- Returns:
list with the search result
- get_repr() str [source]
This overwrites the default Django
__repr__()
method which would return<MediaFile: MediaFile object (id)>
. It is used for logging.- Returns:
The canonical string representation of the document
- Return type:
- icon_usages[source]
Check where a media file is used as icon
- Returns:
List of all objects that use this file as icon
- is_deletable[source]
Check if a media file deletable
- Returns:
Whether a file is deletable
- is_embedded[source]
Check if a media file is embedded in the content
- Returns:
Whether a file is embedded
- is_icon[source]
Check if a media file is used as icon
- Returns:
Whether a file is an icon
- is_only_used_in_past_events[source]
Check if a media file is used in past events only
- Returns:
if a media file is only used in past events
- is_used[source]
Check if a media file is used
- Returns:
Whether a file is used
- objects = <django.db.models.manager.ManagerFromMediaFileQuerySet object>[source]
Django manager to access the ORM Use
MediaFile.objects.all()
to fetch all objects.Custom model manager for media file objects
- past_event_usages[source]
Count in how many past events this file is used
- Returns:
count of usages in past events
- classmethod search(region: Region, query: str) QuerySet [source]
Searches for all media files which match the given query in their name.
- serialize() dict[str, Any] [source]
This methods creates a serialized string of that document. This can later be used in the AJAX calls.
- serialize_usages() dict[str, Any] [source]
This methods creates a serialized dict of the file’s usages. This can later be used in the AJAX calls.
- class integreat_cms.cms.models.media.media_file.MediaFileQuerySet(model=None, query=None, using=None, hints=None)[source]
Bases:
QuerySet
Custom queryset for media files
- filter_unused() MediaFileQuerySet [source]
Filter for unused media files
- Returns:
The queryset of unused media files
- Return type:
- integreat_cms.cms.models.media.media_file.file_size_limit(value: FieldFile) None [source]
This function checks if the uploaded file exceeds the file size limit
- Parameters:
value (FieldFile) – the size of upload file
- Raises:
ValidationError – when the file size exceeds the size given in the settings.
- Return type:
None
- integreat_cms.cms.models.media.media_file.upload_path(instance: MediaFile, filename: str) str [source]
This function calculates the path for a file which is uploaded to the media library. It contains the region id, the current year and month as subdirectories and the filename. It also contains the current epoch time to make sure that no path will be used twice. It is just the provisionally requested path for the media storage. If it already exists, Django will automatically append a random string to make sure the file name is unique.
- integreat_cms.cms.models.media.media_file.upload_path_thumbnail(instance: MediaFile, filename: str) str [source]
This function derives the upload path of a thumbnail file from it’s original file. This makes it a bit easier to determine which thumbnail belongs to which file if there are multiple files with the same file name (in which case Django automatically appends a random string to the original’s file name).
E.g. if the files
A.jpg
andA_thumbnail.jpg
already exist, andA.jpg
is uploaded again, the resulting file names might be e.g.A_EOHRFQ2.jpg
andA_thumbnail_IWxPiOq.jpg
, while with this function, the thumbnail will be stored asA_EOHRFQ2_thumbnail.jpg
, making it easier to examine these files on the file system.