fix: add / display thumbnail image for animals
This commit is contained in:
parent
e120812eae
commit
5e4cd8978d
5 changed files with 81 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
||||||
|
"""add animal thumbnail url
|
||||||
|
|
||||||
|
Revision ID: 2a49127e974b
|
||||||
|
Revises: 8898184c5c75
|
||||||
|
Create Date: 2026-02-14 19:41:22.039343
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import wuttjamaican.db.util
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "2a49127e974b"
|
||||||
|
down_revision: Union[str, None] = "8898184c5c75"
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
|
||||||
|
# animal
|
||||||
|
op.add_column(
|
||||||
|
"animal", sa.Column("thumbnail_url", sa.String(length=255), nullable=True)
|
||||||
|
)
|
||||||
|
op.add_column(
|
||||||
|
"animal_version",
|
||||||
|
sa.Column(
|
||||||
|
"thumbnail_url", sa.String(length=255), autoincrement=False, nullable=True
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
|
||||||
|
# animal
|
||||||
|
op.drop_column("animal_version", "thumbnail_url")
|
||||||
|
op.drop_column("animal", "thumbnail_url")
|
||||||
|
|
@ -173,6 +173,14 @@ class Animal(model.Base):
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
thumbnail_url = sa.Column(
|
||||||
|
sa.String(length=255),
|
||||||
|
nullable=True,
|
||||||
|
doc="""
|
||||||
|
Optional thumbnail URL for the animal.
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
farmos_uuid = sa.Column(
|
farmos_uuid = sa.Column(
|
||||||
model.UUID(),
|
model.UUID(),
|
||||||
nullable=True,
|
nullable=True,
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,7 @@ class AnimalImporter(FromFarmOS, ToWutta):
|
||||||
"notes",
|
"notes",
|
||||||
"archived",
|
"archived",
|
||||||
"image_url",
|
"image_url",
|
||||||
|
"thumbnail_url",
|
||||||
]
|
]
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
|
@ -214,6 +215,7 @@ class AnimalImporter(FromFarmOS, ToWutta):
|
||||||
""" """
|
""" """
|
||||||
animal_type_uuid = None
|
animal_type_uuid = None
|
||||||
image_url = None
|
image_url = None
|
||||||
|
thumbnail_url = None
|
||||||
if relationships := animal.get("relationships"):
|
if relationships := animal.get("relationships"):
|
||||||
|
|
||||||
if animal_type := relationships.get("animal_type"):
|
if animal_type := relationships.get("animal_type"):
|
||||||
|
|
@ -232,6 +234,7 @@ class AnimalImporter(FromFarmOS, ToWutta):
|
||||||
"image_style_uri"
|
"image_style_uri"
|
||||||
):
|
):
|
||||||
image_url = image_style["large"]
|
image_url = image_style["large"]
|
||||||
|
thumbnail_url = image_style["thumbnail"]
|
||||||
|
|
||||||
if not animal_type_uuid:
|
if not animal_type_uuid:
|
||||||
log.warning("missing/invalid animal_type for farmOS Animal: %s", animal)
|
log.warning("missing/invalid animal_type for farmOS Animal: %s", animal)
|
||||||
|
|
@ -267,6 +270,7 @@ class AnimalImporter(FromFarmOS, ToWutta):
|
||||||
"archived": archived,
|
"archived": archived,
|
||||||
"notes": notes,
|
"notes": notes,
|
||||||
"image_url": image_url,
|
"image_url": image_url,
|
||||||
|
"thumbnail_url": thumbnail_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
Master view for Animals
|
Master view for Animals
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from webhelpers2.html import tags
|
||||||
|
|
||||||
from wuttaweb.forms.schema import WuttaDictEnum
|
from wuttaweb.forms.schema import WuttaDictEnum
|
||||||
|
|
||||||
from wuttafarm.db.model.animals import Animal
|
from wuttafarm.db.model.animals import Animal
|
||||||
|
|
@ -49,6 +51,7 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
}
|
}
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
|
"thumbnail",
|
||||||
"drupal_id",
|
"drupal_id",
|
||||||
"name",
|
"name",
|
||||||
"animal_type",
|
"animal_type",
|
||||||
|
|
@ -76,7 +79,9 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
"archived",
|
"archived",
|
||||||
"farmos_uuid",
|
"farmos_uuid",
|
||||||
"drupal_id",
|
"drupal_id",
|
||||||
|
"thumbnail_url",
|
||||||
"image_url",
|
"image_url",
|
||||||
|
"thumbnail",
|
||||||
"image",
|
"image",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -86,6 +91,11 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
model = self.app.model
|
model = self.app.model
|
||||||
enum = self.app.enum
|
enum = self.app.enum
|
||||||
|
|
||||||
|
# thumbnail
|
||||||
|
g.set_renderer("thumbnail", self.render_grid_thumbnail)
|
||||||
|
g.set_label("thumbnail", "", column_only=True)
|
||||||
|
g.set_centered("thumbnail")
|
||||||
|
|
||||||
# drupal_id
|
# drupal_id
|
||||||
g.set_label("drupal_id", "ID", column_only=True)
|
g.set_label("drupal_id", "ID", column_only=True)
|
||||||
|
|
||||||
|
|
@ -103,6 +113,11 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
# sex
|
# sex
|
||||||
g.set_enum("sex", enum.ANIMAL_SEX)
|
g.set_enum("sex", enum.ANIMAL_SEX)
|
||||||
|
|
||||||
|
def render_grid_thumbnail(self, animal, field, value):
|
||||||
|
if animal.thumbnail_url:
|
||||||
|
return tags.image(animal.thumbnail_url, "animal thumbnail")
|
||||||
|
return None
|
||||||
|
|
||||||
def grid_row_class(self, animal, data, i):
|
def grid_row_class(self, animal, data, i):
|
||||||
""" """
|
""" """
|
||||||
if animal.archived:
|
if animal.archived:
|
||||||
|
|
@ -131,10 +146,21 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
f.set_default("asset_type", "Animal")
|
f.set_default("asset_type", "Animal")
|
||||||
f.set_readonly("asset_type")
|
f.set_readonly("asset_type")
|
||||||
|
|
||||||
|
# thumbnail_url
|
||||||
|
if self.creating or self.editing:
|
||||||
|
f.remove("thumbnail_url")
|
||||||
|
|
||||||
# image_url
|
# image_url
|
||||||
if self.creating or self.editing:
|
if self.creating or self.editing:
|
||||||
f.remove("image_url")
|
f.remove("image_url")
|
||||||
|
|
||||||
|
# thumbnail
|
||||||
|
if self.creating or self.editing:
|
||||||
|
f.remove("thumbnail")
|
||||||
|
elif animal.thumbnail_url:
|
||||||
|
f.set_widget("thumbnail", ImageWidget("animal thumbnail"))
|
||||||
|
f.set_default("thumbnail", animal.thumbnail_url)
|
||||||
|
|
||||||
# image
|
# image
|
||||||
if self.creating or self.editing:
|
if self.creating or self.editing:
|
||||||
f.remove("image")
|
f.remove("image")
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,14 @@ class WuttaFarmMasterView(MasterView):
|
||||||
"farmos_uuid": "farmOS UUID",
|
"farmos_uuid": "farmOS UUID",
|
||||||
"drupal_id": "Drupal ID",
|
"drupal_id": "Drupal ID",
|
||||||
"image_url": "Image URL",
|
"image_url": "Image URL",
|
||||||
|
"thumbnail_url": "Thumbnail URL",
|
||||||
}
|
}
|
||||||
|
|
||||||
row_labels = {
|
row_labels = {
|
||||||
"farmos_uuid": "farmOS UUID",
|
"farmos_uuid": "farmOS UUID",
|
||||||
"drupal_id": "Drupal ID",
|
"drupal_id": "Drupal ID",
|
||||||
"image_url": "Image URL",
|
"image_url": "Image URL",
|
||||||
|
"thumbnail_url": "Thumbnail URL",
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_farmos_url(self, obj):
|
def get_farmos_url(self, obj):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue