Files
guilan-ace-backend/apps/communications/api/schemas.py
Amirhossein Khalili 3ec28638d1 feat: replace email flows with in-app notifications
Add recipient notification detail and filtering, a queued admin composer, and contextual automatic titles. Retire email delivery, obsolete auth routes, newsletter data, and related templates and settings.
2026-09-26 12:23:10 +03:30

91 lines
2.2 KiB
Python

"""Schemas for communications-related endpoints."""
from datetime import datetime
from typing import Literal, Optional
from ninja import ModelSchema, Schema
from apps.blog.api.schemas import AuthorSchema
from apps.communications.models import Announcement, PushNotificationDevice
class AnnouncementSchema(ModelSchema):
author: AuthorSchema
content_html: str
class Config:
model = Announcement
model_fields = [
"id",
"title",
"content",
"announcement_type",
"priority",
"is_published",
"publish_date",
"created_at",
"updated_at",
]
@staticmethod
def resolve_content_html(obj):
return obj.content_html
class AnnouncementListSchema(Schema):
id: int
title: str
content: str
announcement_type: str
priority: str
author: AuthorSchema
is_published: bool
publish_date: Optional[datetime] = None
created_at: datetime
class AnnouncementCreateSchema(Schema):
title: str
content: str
announcement_type: Literal["general", "event", "academic", "urgent"] = "general"
priority: Literal["low", "normal", "high", "urgent"] = "normal"
is_published: bool = False
publish_date: Optional[datetime] = None
class AnnouncementUpdateSchema(Schema):
title: Optional[str] = None
content: Optional[str] = None
announcement_type: Optional[Literal["general", "event", "academic", "urgent"]] = None
priority: Optional[Literal["low", "normal", "high", "urgent"]] = None
is_published: Optional[bool] = None
publish_date: Optional[datetime] = None
class PushDeviceSchema(ModelSchema):
user: AuthorSchema
class Config:
model = PushNotificationDevice
model_fields = ["id", "device_token", "device_type", "is_active", "created_at"]
class PushDeviceCreateSchema(Schema):
device_token: str
device_type: str = "web"
class PushDeviceUpdateSchema(Schema):
is_active: bool
class MessageResponseSchema(Schema):
message: str
success: bool = True
class AnnouncementStatsSchema(Schema):
total_announcements: int
published_announcements: int
draft_announcements: int
urgent_announcements: int