Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(hot-fix): project image_url on project lists #178

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class DbProject(BaseModel):
gsd_cm_px: Optional[float] = None
altitude_from_ground: Optional[float] = None
is_terrain_follow: bool = False
image_url: Optional[str] = None

async def one(db: Connection, project_id: uuid.UUID):
"""Get a single project & all associated tasks by ID."""
Expand Down Expand Up @@ -413,13 +414,13 @@ class ProjectOut(BaseModel):
tasks: Optional[list[TaskOut]] = []
image_url: Optional[str] = None

@model_validator(mode="before")
@model_validator(mode="after")
def set_image_url(cls, values):
"""Set image_url before rendering the model."""
project_id = values.get("id")
if project_id and not values.get("image_url"):
project_id = values.id
if project_id:
image_dir = f"images/{project_id}/screenshot.png"
values["image_url"] = get_image_dir_url(settings.S3_BUCKET_NAME, image_dir)
values.image_url = get_image_dir_url(settings.S3_BUCKET_NAME, image_dir)
return values


Expand Down