fix: cleanup Structure views to better match farmOS

This commit is contained in:
Lance Edgar 2026-02-14 20:18:35 -06:00
parent aae01c010b
commit e60b91fd45
6 changed files with 108 additions and 11 deletions

View file

@ -0,0 +1,41 @@
"""add structure thumbnail url
Revision ID: 8cc1565d38e7
Revises: 2a49127e974b
Create Date: 2026-02-14 20:07:33.913573
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = "8cc1565d38e7"
down_revision: Union[str, None] = "2a49127e974b"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# structure
op.add_column(
"structure", sa.Column("thumbnail_url", sa.String(length=255), nullable=True)
)
op.add_column(
"structure_version",
sa.Column(
"thumbnail_url", sa.String(length=255), autoincrement=False, nullable=True
),
)
def downgrade() -> None:
# structure
op.drop_column("structure_version", "thumbnail_url")
op.drop_column("structure", "thumbnail_url")

View file

@ -146,6 +146,14 @@ class Structure(model.Base):
""", """,
) )
thumbnail_url = sa.Column(
sa.String(length=255),
nullable=True,
doc="""
Optional thumbnail URL for the structure.
""",
)
farmos_uuid = sa.Column( farmos_uuid = sa.Column(
model.UUID(), model.UUID(),
nullable=True, nullable=True,

View file

@ -511,6 +511,7 @@ class StructureImporter(FromFarmOS, ToWutta):
"notes", "notes",
"archived", "archived",
"image_url", "image_url",
"thumbnail_url",
] ]
def setup(self): def setup(self):
@ -542,6 +543,7 @@ class StructureImporter(FromFarmOS, ToWutta):
notes = notes["value"] notes = notes["value"]
image_url = None image_url = None
thumbnail_url = None
if relationships := structure.get("relationships"): if relationships := structure.get("relationships"):
if image := relationships.get("image"): if image := relationships.get("image"):
if image["data"]: if image["data"]:
@ -552,6 +554,7 @@ class StructureImporter(FromFarmOS, ToWutta):
"image_style_uri" "image_style_uri"
): ):
image_url = image_style["large"] image_url = image_style["large"]
thumbnail_url = image_style["thumbnail"]
if self.farmos_4x: if self.farmos_4x:
archived = structure["attributes"]["archived"] archived = structure["attributes"]["archived"]
@ -568,6 +571,7 @@ class StructureImporter(FromFarmOS, ToWutta):
"archived": archived, "archived": archived,
"notes": notes, "notes": notes,
"image_url": image_url, "image_url": image_url,
"thumbnail_url": thumbnail_url,
} }

View file

@ -23,8 +23,6 @@
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
@ -113,11 +111,6 @@ 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:

View file

@ -23,6 +23,8 @@
Base class for WuttaFarm master views Base class for WuttaFarm master views
""" """
from webhelpers2.html import tags
from wuttaweb.views import MasterView from wuttaweb.views import MasterView
@ -57,6 +59,13 @@ class WuttaFarmMasterView(MasterView):
return context return context
def render_grid_thumbnail(self, obj, field, value):
if obj.thumbnail_url:
return tags.image(
obj.thumbnail_url, f"thumbnail for {self.get_model_title()}"
)
return None
def get_xref_buttons(self, obj): def get_xref_buttons(self, obj):
url = self.get_farmos_url(obj) url = self.get_farmos_url(obj)
if url: if url:

View file

@ -40,11 +40,15 @@ class StructureView(WuttaFarmMasterView):
farmos_refurl_path = "/assets/structure" farmos_refurl_path = "/assets/structure"
labels = {
"name": "Asset Name",
}
grid_columns = [ grid_columns = [
"thumbnail",
"drupal_id",
"name", "name",
"structure_type", "structure_type",
"is_location",
"is_fixed",
"archived", "archived",
] ]
@ -57,14 +61,17 @@ class StructureView(WuttaFarmMasterView):
form_fields = [ form_fields = [
"name", "name",
"notes",
"asset_type",
"structure_type", "structure_type",
"is_location", "is_location",
"is_fixed", "is_fixed",
"notes",
"archived", "archived",
"farmos_uuid", "farmos_uuid",
"drupal_id", "drupal_id",
"thumbnail_url",
"image_url", "image_url",
"thumbnail",
"image", "image",
] ]
@ -73,6 +80,14 @@ class StructureView(WuttaFarmMasterView):
super().configure_grid(g) super().configure_grid(g)
model = self.app.model model = self.app.model
# thumbnail
g.set_renderer("thumbnail", self.render_grid_thumbnail)
g.set_label("thumbnail", "", column_only=True)
g.set_centered("thumbnail")
# drupal_id
g.set_label("drupal_id", "ID", column_only=True)
# name # name
g.set_link("name") g.set_link("name")
@ -94,11 +109,38 @@ class StructureView(WuttaFarmMasterView):
super().configure_form(f) super().configure_form(f)
structure = form.model_instance structure = form.model_instance
# notes
f.set_widget("notes", "notes")
# asset_type
if self.creating:
f.remove("asset_type")
else:
f.set_default("asset_type", "Structure")
f.set_readonly("asset_type")
# structure_type # structure_type
f.set_node("structure_type", StructureTypeRef(self.request)) f.set_node("structure_type", StructureTypeRef(self.request))
# thumbnail_url
if self.creating or self.editing:
f.remove("thumbnail_url")
# image_url
if self.creating or self.editing:
f.remove("image_url")
# thumbnail
if self.creating or self.editing:
f.remove("thumbnail")
elif structure.thumbnail_url:
f.set_widget("thumbnail", ImageWidget("structure thumbnail"))
f.set_default("thumbnail", structure.thumbnail_url)
# image # image
if structure.image_url: if self.creating or self.editing:
f.remove("image")
elif structure.image_url:
f.set_widget("image", ImageWidget("structure image")) f.set_widget("image", ImageWidget("structure image"))
f.set_default("image", structure.image_url) f.set_default("image", structure.image_url)