2024-07-18 18:23:30 +00:00
|
|
|
from datetime import datetime
|
2024-10-21 08:30:35 +00:00
|
|
|
from pathlib import Path
|
2024-07-18 18:23:30 +00:00
|
|
|
|
2024-10-13 00:04:45 +00:00
|
|
|
from django.urls import reverse
|
2024-07-25 15:27:23 +00:00
|
|
|
from ninja import FilterSchema, ModelSchema, Schema
|
|
|
|
from pydantic import Field, NonNegativeInt
|
2024-07-18 18:23:30 +00:00
|
|
|
|
2024-10-13 22:45:31 +00:00
|
|
|
from core.schemas import SimpleUserSchema, UserProfileSchema
|
2024-10-21 08:30:35 +00:00
|
|
|
from sas.models import Album, Picture, PictureModerationRequest
|
|
|
|
|
|
|
|
|
|
|
|
class AlbumSchema(ModelSchema):
|
|
|
|
class Meta:
|
|
|
|
model = Album
|
|
|
|
fields = ["id", "name"]
|
|
|
|
|
|
|
|
path: str
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def resolve_path(obj: Album) -> str:
|
|
|
|
return str(Path(obj.get_parent_path()) / obj.name)
|
2024-07-18 18:23:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PictureFilterSchema(FilterSchema):
|
|
|
|
before_date: datetime | None = Field(None, q="date__lte")
|
|
|
|
after_date: datetime | None = Field(None, q="date__gte")
|
|
|
|
users_identified: set[int] | None = Field(None, q="people__user_id__in")
|
|
|
|
album_id: int | None = Field(None, q="parent_id")
|
|
|
|
|
|
|
|
|
|
|
|
class PictureSchema(ModelSchema):
|
|
|
|
class Meta:
|
|
|
|
model = Picture
|
2024-09-03 18:15:37 +00:00
|
|
|
fields = ["id", "name", "date", "size", "is_moderated", "asked_for_removal"]
|
2024-07-18 18:23:30 +00:00
|
|
|
|
2024-09-03 18:15:37 +00:00
|
|
|
owner: UserProfileSchema
|
2024-10-13 00:04:45 +00:00
|
|
|
sas_url: str
|
2024-07-18 18:23:30 +00:00
|
|
|
full_size_url: str
|
|
|
|
compressed_url: str
|
|
|
|
thumb_url: str
|
2024-07-31 09:56:38 +00:00
|
|
|
album: str
|
2024-07-25 15:27:23 +00:00
|
|
|
|
2024-10-13 00:04:45 +00:00
|
|
|
@staticmethod
|
|
|
|
def resolve_sas_url(obj: Picture) -> str:
|
|
|
|
return reverse("sas:picture", kwargs={"picture_id": obj.id})
|
|
|
|
|
2024-08-05 17:25:30 +00:00
|
|
|
@staticmethod
|
|
|
|
def resolve_full_size_url(obj: Picture) -> str:
|
|
|
|
return obj.get_download_url()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def resolve_compressed_url(obj: Picture) -> str:
|
|
|
|
return obj.get_download_compressed_url()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def resolve_thumb_url(obj: Picture) -> str:
|
|
|
|
return obj.get_download_thumb_url()
|
|
|
|
|
2024-07-25 15:27:23 +00:00
|
|
|
|
2024-08-01 17:02:29 +00:00
|
|
|
class PictureRelationCreationSchema(Schema):
|
|
|
|
picture: NonNegativeInt
|
|
|
|
users: list[NonNegativeInt]
|
2024-07-25 15:27:23 +00:00
|
|
|
|
|
|
|
|
2024-08-01 17:02:29 +00:00
|
|
|
class IdentifiedUserSchema(Schema):
|
|
|
|
id: int
|
|
|
|
user: UserProfileSchema
|
2024-10-13 22:45:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ModerationRequestSchema(ModelSchema):
|
|
|
|
author: SimpleUserSchema
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PictureModerationRequest
|
|
|
|
fields = ["id", "created_at", "reason"]
|