Changeset View
Changeset View
Standalone View
Standalone View
static_assets/models/static_assets.py
| from typing import Optional | from typing import Optional | ||||
| from django.contrib.auth.models import User | from django.contrib.auth.models import User | ||||
| from django.core.exceptions import ValidationError | from django.core.exceptions import ValidationError | ||||
| from django.core.files.storage import FileSystemStorage | from django.core.files.storage import FileSystemStorage | ||||
| from django.db import models | from django.db import models | ||||
| from django.db.models import FileField | from django.db.models import FileField | ||||
| from django.db.models.fields.files import FieldFile | from django.db.models.fields.files import FieldFile | ||||
| from storages.backends.gcloud import GoogleCloudStorage | from storages.backends.gcloud import GoogleCloudStorage | ||||
| from common import mixins | from common import mixins | ||||
| from common.upload_paths import get_upload_to_hashed_path | from common.upload_paths import get_upload_to_hashed_path | ||||
| from static_assets.models import License, StorageLocation, StorageLocationCategoryChoices | from static_assets.models import License, StorageLocationCategoryChoices | ||||
| class StaticAssetFileTypeChoices(models.TextChoices): | class StaticAssetFileTypeChoices(models.TextChoices): | ||||
| file = 'file', 'File' | file = 'file', 'File' | ||||
| image = 'image', 'Image' | image = 'image', 'Image' | ||||
| video = 'video', 'Video' | video = 'video', 'Video' | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | author = models.ForeignKey( | ||||
| related_name='authored_assets', | related_name='authored_assets', | ||||
| verbose_name='author (optional)', | verbose_name='author (optional)', | ||||
| help_text='The actual author of the artwork/learning materials', | help_text='The actual author of the artwork/learning materials', | ||||
| ) | ) | ||||
| author.description = 'The actual author of the artwork/learning materials.' | author.description = 'The actual author of the artwork/learning materials.' | ||||
| license = models.ForeignKey( | license = models.ForeignKey( | ||||
| License, null=True, on_delete=models.SET_NULL, related_name='static_assets' | License, null=True, on_delete=models.SET_NULL, related_name='static_assets' | ||||
| ) | ) | ||||
| storage_location = models.ForeignKey( | |||||
| StorageLocation, on_delete=models.PROTECT, related_name='static_assets' | |||||
| ) | |||||
| thumbnail = models.FileField(upload_to=get_upload_to_hashed_path, blank=True) | thumbnail = models.FileField(upload_to=get_upload_to_hashed_path, blank=True) | ||||
| thumbnail.description = ( | thumbnail.description = ( | ||||
| "Asset thumbnail is auto-generated for images and videos. Required for other files." | "Asset thumbnail is auto-generated for images and videos. Required for other files." | ||||
| ) | ) | ||||
| # TODO(Natalia): generate preview if thumbnail not uploaded. | # TODO(Natalia): generate preview if thumbnail not uploaded. | ||||
| @property | @property | ||||
| ▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines | |||||