From bd972e30db69c49bd0e2e5f5b4162218bd0598f3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 4 Feb 2026 08:53:22 -0600 Subject: [PATCH] fix: add some more info when viewing animal --- src/wuttafarm/web/views/farmos/animals.py | 58 ++++++++++++++++++++--- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/wuttafarm/web/views/farmos/animals.py b/src/wuttafarm/web/views/farmos/animals.py index d765cd4..ab5167c 100644 --- a/src/wuttafarm/web/views/farmos/animals.py +++ b/src/wuttafarm/web/views/farmos/animals.py @@ -25,6 +25,8 @@ Master view for Farm Animals import datetime +import colander + from farmOS import farmOS from wuttafarm.web.views.farmos import FarmOSMasterView @@ -46,7 +48,8 @@ class AnimalView(FarmOSMasterView): farmos_refurl_path = "/assets/animal" labels = { - "species_breed": "Species / Breed", + "is_castrated": "Castrated", + "location_name": "Current Location", "raw_image_url": "Raw Image URL", "large_image_url": "Large Image URL", "thumbnail_image_url": "Thumbnail Image URL", @@ -54,20 +57,24 @@ class AnimalView(FarmOSMasterView): grid_columns = [ "name", - "species_breed", "birthdate", "sex", - "location", + "is_castrated", + "status", ] sort_defaults = "name" form_fields = [ "name", - "species_breed", + "animal_type_name", "birthdate", "sex", - "location", + "is_castrated", + "status", + "owners", + "location_name", + "notes", "raw_image_url", "large_image_url", "thumbnail_image_url", @@ -98,8 +105,38 @@ class AnimalView(FarmOSMasterView): # instance data data = self.normalize_animal(animal["data"]) - # add image_url if relationships := animal["data"].get("relationships"): + + # add animal type + if animal_type := relationships.get("animal_type"): + if animal_type["data"]: + animal_type = self.farmos_client.resource.get_id( + "taxonomy_term", "animal_type", animal_type["data"]["id"] + ) + data["animal_type_name"] = animal_type["data"]["attributes"]["name"] + + # add location + if location := relationships.get("location"): + if location["data"]: + location = self.farmos_client.resource.get_id( + "asset", "structure", location["data"][0]["id"] + ) + data["location_name"] = location["data"]["attributes"]["name"] + + # add owners + if owner := relationships.get("owner"): + owners = [] + for owner_data in owner["data"]: + owners.append( + self.farmos_client.resource.get_id( + "user", "user", owner_data["id"] + ) + ) + data["owners"] = ", ".join( + [o["data"]["attributes"]["display_name"] for o in owners] + ) + + # add image urls if image := relationships.get("image"): if image["data"]: image = self.farmos_client.resource.get_id( @@ -135,7 +172,10 @@ class AnimalView(FarmOSMasterView): "species_breed": "", # TODO "birthdate": birthdate, "sex": animal["attributes"]["sex"], + "is_castrated": animal["attributes"]["is_castrated"], "location": "", # TODO + "status": animal["attributes"]["status"], + "notes": animal["attributes"]["notes"]["value"], } def configure_form(self, form): @@ -143,6 +183,12 @@ class AnimalView(FarmOSMasterView): super().configure_form(f) animal = f.model_instance + # is_castrated + f.set_node("is_castrated", colander.Boolean()) + + # notes + f.set_widget("notes", "notes") + # image if url := animal.get("large_image_url"): f.set_widget("image", AnimalImage())