Files
training-software/cms/serializers.py
Paperclip CTO 90f7a78197
Some checks failed
CI / Tests (Python 3.12) (push) Failing after 7m3s
CI / OpenAPI Schema (push) Has been skipped
CI / Lint (push) Failing after 4s
feat(TRA-248): WCAG 2.1 AA baseline and de/en i18n framework
A11y:
- Add alt_text field to MediaAsset and ContentBlock (WCAG 2.1 AA 1.1.1)
- Expose alt_text in MediaAssetSerializer and ContentBlockSerializer so
  frontends can render <img alt="..."> and <video aria-label="..."> correctly
- Migration 0002 adds the two alt_text columns

i18n:
- Add LocaleMiddleware to MIDDLEWARE stack (after SessionMiddleware per Django docs)
- Add LANGUAGES = [("de", ...), ("en", ...)] and LOCALE_PATHS = [BASE_DIR/"locale"]
- Add USE_L10N = True
- Seed locale/de/LC_MESSAGES/django.po and locale/en/LC_MESSAGES/django.po with
  translations for all user-facing API strings (upload errors, notification titles)

Tests (tests/a11y/test_a11y_i18n.py):
- alt_text field round-trip on MediaAsset and ContentBlock
- Serializer exposes and accepts alt_text on create, list, PATCH
- LANGUAGES/LOCALE_PATHS/LocaleMiddleware settings assertions
- Accept-Language header switching smoke test against /api/v1/notifications/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 09:36:31 +02:00

36 lines
1.3 KiB
Python

from rest_framework import serializers
from .models import ContentBlock, CourseTheme, MediaAsset
class MediaAssetSerializer(serializers.ModelSerializer):
class Meta:
model = MediaAsset
fields = [
"id", "file_name", "file_path", "file_size", "mime_type",
"extension", "scan_status", "alt_text", "created_at",
]
read_only_fields = ["id", "file_name", "file_path", "file_size", "mime_type",
"extension", "scan_status", "created_at"]
class ContentBlockSerializer(serializers.ModelSerializer):
media_asset = MediaAssetSerializer(read_only=True)
media_asset_id = serializers.UUIDField(write_only=True, required=False, allow_null=True)
class Meta:
model = ContentBlock
fields = [
"id", "page", "order", "block_type", "body",
"media_asset", "media_asset_id", "embed_url", "caption", "alt_text", "extra",
"created_at", "updated_at",
]
read_only_fields = ["id", "created_at", "updated_at", "media_asset"]
class CourseThemeSerializer(serializers.ModelSerializer):
class Meta:
model = CourseTheme
fields = ["id", "course", "primary_color", "secondary_color", "logo", "extra"]
read_only_fields = ["id", "course"]