first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
60
backend/app/services/editions.py
Normal file
60
backend/app/services/editions.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
from app.models import EventEdition, MediaAsset
|
||||
from app.schemas import EditionTicketsPublic, EventEditionAdmin, EventEditionPublic, MediaAssetPublic
|
||||
|
||||
|
||||
def tickets_for_edition(edition: EventEdition) -> EditionTicketsPublic:
|
||||
return EditionTicketsPublic(
|
||||
bookmyshow=edition.bookmyshow_url,
|
||||
district=edition.district_url,
|
||||
instagram=edition.instagram_url,
|
||||
)
|
||||
|
||||
|
||||
def edition_to_public(edition: EventEdition, include_unpublished_media: bool = False) -> EventEditionPublic:
|
||||
cover = None
|
||||
if edition.cover_image_path:
|
||||
from app.services.media import public_url_for_path, thumb_url_for_path
|
||||
|
||||
cover = public_url_for_path(edition.cover_image_path)
|
||||
|
||||
media: list[MediaAssetPublic] = []
|
||||
for m in edition.media:
|
||||
if not include_unpublished_media and not m.is_published:
|
||||
continue
|
||||
from app.services.media import public_url_for_path, thumb_url_for_path
|
||||
|
||||
media.append(
|
||||
MediaAssetPublic(
|
||||
id=m.id,
|
||||
url=public_url_for_path(m.file_path),
|
||||
thumb_url=thumb_url_for_path(m.file_path),
|
||||
caption=m.caption,
|
||||
sort_order=m.sort_order,
|
||||
)
|
||||
)
|
||||
|
||||
return EventEditionPublic(
|
||||
id=edition.id,
|
||||
title=edition.title,
|
||||
slug=edition.slug,
|
||||
event_type=edition.event_type,
|
||||
city=edition.city,
|
||||
venue_name=edition.venue_name,
|
||||
event_date=edition.event_date,
|
||||
description=edition.description,
|
||||
is_featured=edition.is_featured,
|
||||
cover_image_url=cover,
|
||||
cover_thumb_url=thumb_url_for_path(edition.cover_image_path) if edition.cover_image_path else None,
|
||||
tickets=tickets_for_edition(edition),
|
||||
meta_description=edition.meta_description,
|
||||
media=media,
|
||||
)
|
||||
|
||||
|
||||
def edition_to_admin(edition: EventEdition) -> EventEditionAdmin:
|
||||
base = edition_to_public(edition, include_unpublished_media=True)
|
||||
return EventEditionAdmin(
|
||||
**base.model_dump(),
|
||||
is_published=edition.is_published,
|
||||
sort_order=edition.sort_order,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue