ContentAsset records metadata (kind, title, description, release date, season/episode/sequence) for an UploadedAsset, scoped to a studio. ContentGroup groups episodes into a series or movies into a collection. The studio page now has tabs for uploaded files and content, both loaded with htmx. Files without content get a "Create content" button. Content opens read-only with an Edit button; the form shows immediately when a save fails validation. Also adds the draft job status to the migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
3.4 KiB
Python
105 lines
3.4 KiB
Python
from django.contrib import admin, messages
|
|
from django.utils.html import format_html
|
|
|
|
from privatestudio.studio import models
|
|
from privatestudio.studio.auth import generate_api_key, hash_api_key
|
|
|
|
|
|
@admin.register(models.Studio)
|
|
class StudioAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "bucket_name", "group", "created_at")
|
|
search_fields = ("name", "bucket_name")
|
|
|
|
|
|
@admin.register(models.APIKey)
|
|
class APIKeyAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "user", "created_at", "is_active")
|
|
list_filter = ("is_active",)
|
|
readonly_fields = ("key_hash",)
|
|
|
|
def get_fields(self, request, obj=None):
|
|
fields = super().get_fields(request, obj)
|
|
if obj is None:
|
|
# Generated in save_model, so there is nothing to show yet.
|
|
return [f for f in fields if f != "key_hash"]
|
|
return fields
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
if change:
|
|
super().save_model(request, obj, form, change)
|
|
return
|
|
plain_key = generate_api_key()
|
|
obj.key_hash = hash_api_key(plain_key)
|
|
super().save_model(request, obj, form, change)
|
|
messages.warning(
|
|
request,
|
|
format_html(
|
|
"API key for {}: <code>{}</code> Copy it now; it will not be shown again.",
|
|
obj.user,
|
|
plain_key,
|
|
),
|
|
)
|
|
|
|
|
|
@admin.register(models.S3Credential)
|
|
class S3CredentialAdmin(admin.ModelAdmin):
|
|
list_display = ("access_key", "user", "created_at", "expires_at")
|
|
exclude = ("secret_key",)
|
|
|
|
|
|
@admin.register(models.UploadedAsset)
|
|
class UploadedAssetAdmin(admin.ModelAdmin):
|
|
list_display = ("s3_path", "studio", "size", "uploaded_by", "upload_timestamp")
|
|
list_filter = ("studio",)
|
|
|
|
|
|
@admin.register(models.MultipartUpload)
|
|
class MultipartUploadAdmin(admin.ModelAdmin):
|
|
list_display = ("key", "studio", "status", "total_size", "created_by", "created_at")
|
|
list_filter = ("status", "studio")
|
|
readonly_fields = ("upload_id",)
|
|
|
|
|
|
@admin.register(models.UploadPart)
|
|
class UploadPartAdmin(admin.ModelAdmin):
|
|
list_display = ("upload", "part_number", "size", "uploaded_at")
|
|
|
|
|
|
@admin.register(models.TranscodeProfile)
|
|
class TranscodeProfileAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "studio", "created_by", "created_at")
|
|
list_filter = ("studio",)
|
|
|
|
|
|
@admin.register(models.TranscodeJob)
|
|
class TranscodeJobAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "studio", "asset", "profile", "status", "requested_at", "completed_at")
|
|
list_filter = ("studio", "status")
|
|
|
|
|
|
@admin.register(models.PackagingJob)
|
|
class PackagingJobAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "studio", "transcode_job", "status", "requested_at", "completed_at")
|
|
list_filter = ("studio", "status")
|
|
|
|
|
|
@admin.register(models.TranscodedAsset)
|
|
class TranscodedAssetAdmin(admin.ModelAdmin):
|
|
list_display = ("s3_path", "studio", "transcode_job", "format", "created_at")
|
|
list_filter = ("studio", "format")
|
|
|
|
|
|
@admin.register(models.ContentGroup)
|
|
class ContentGroupAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "kind", "studio", "created_at")
|
|
list_filter = ("studio", "kind")
|
|
search_fields = ("title",)
|
|
|
|
|
|
@admin.register(models.ContentAsset)
|
|
class ContentAssetAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "kind", "group", "season_number", "episode_number", "release_date")
|
|
list_filter = ("studio", "kind")
|
|
search_fields = ("title",)
|
|
raw_id_fields = ("uploaded_asset",)
|