From 25b2dc6ceca9f1295dfcc2614f14adb26a11a4f6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 14 Feb 2026 19:27:19 -0600 Subject: [PATCH] fix: use Male/Female dict enum for animal sex field and some related changes to make Animal views more like farmOS --- src/wuttafarm/config.py | 3 +- src/wuttafarm/enum.py | 36 ++++++++++++++++++++++++ src/wuttafarm/web/views/animals.py | 44 +++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/wuttafarm/enum.py diff --git a/src/wuttafarm/config.py b/src/wuttafarm/config.py index fcc8aae..5828299 100644 --- a/src/wuttafarm/config.py +++ b/src/wuttafarm/config.py @@ -39,8 +39,9 @@ class WuttaFarmConfig(WuttaConfigExtension): config.setdefault(f"{config.appname}.app_title", "WuttaFarm") config.setdefault(f"{config.appname}.app_dist", "WuttaFarm") - # app model + # app model/enum config.setdefault(f"{config.appname}.model_spec", "wuttafarm.db.model") + config.setdefault(f"{config.appname}.enum_spec", "wuttafarm.enum") # app handler config.setdefault( diff --git a/src/wuttafarm/enum.py b/src/wuttafarm/enum.py new file mode 100644 index 0000000..41bf597 --- /dev/null +++ b/src/wuttafarm/enum.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8; -*- +################################################################################ +# +# WuttaFarm --Web app to integrate with and extend farmOS +# Copyright © 2026 Lance Edgar +# +# This file is part of WuttaFarm. +# +# WuttaFarm is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# WuttaFarm is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# WuttaFarm. If not, see . +# +################################################################################ +""" +WuttaFarm enum values +""" + +from collections import OrderedDict + +from wuttjamaican.enum import * + + +ANIMAL_SEX = OrderedDict( + [ + ("M", "Male"), + ("F", "Female"), + ] +) diff --git a/src/wuttafarm/web/views/animals.py b/src/wuttafarm/web/views/animals.py index adddf2a..0c53770 100644 --- a/src/wuttafarm/web/views/animals.py +++ b/src/wuttafarm/web/views/animals.py @@ -23,6 +23,8 @@ Master view for Animals """ +from wuttaweb.forms.schema import WuttaDictEnum + from wuttafarm.db.model.animals import Animal from wuttafarm.web.views import WuttaFarmMasterView from wuttafarm.web.forms.schema import AnimalTypeRef @@ -40,12 +42,19 @@ class AnimalView(WuttaFarmMasterView): farmos_refurl_path = "/assets/animal" + labels = { + "name": "Asset Name", + "animal_type": "Species/Breed", + "is_sterile": "Sterile", + } + grid_columns = [ + "drupal_id", "name", "animal_type", - "sex", - "is_sterile", "birthdate", + "is_sterile", + "sex", "archived", ] @@ -53,6 +62,7 @@ class AnimalView(WuttaFarmMasterView): filter_defaults = { "name": {"active": True, "verb": "contains"}, + "archived": {"active": True, "verb": "is_false"}, } form_fields = [ @@ -61,8 +71,9 @@ class AnimalView(WuttaFarmMasterView): "birthdate", "sex", "is_sterile", - "archived", "notes", + "asset_type", + "archived", "farmos_uuid", "drupal_id", "image_url", @@ -73,6 +84,10 @@ class AnimalView(WuttaFarmMasterView): g = grid super().configure_grid(g) model = self.app.model + enum = self.app.enum + + # drupal_id + g.set_label("drupal_id", "ID", column_only=True) # name g.set_link("name") @@ -82,19 +97,40 @@ class AnimalView(WuttaFarmMasterView): g.set_sorter("animal_type", model.AnimalType.name) g.set_filter("animal_type", model.AnimalType.name, label="Animal Type Name") + # birthdate + g.set_renderer("birthdate", "date") + + # sex + g.set_enum("sex", enum.ANIMAL_SEX) + def configure_form(self, form): f = form super().configure_form(f) + enum = self.app.enum animal = form.model_instance # animal_type f.set_node("animal_type", AnimalTypeRef(self.request)) + # sex + f.set_node("sex", WuttaDictEnum(self.request, enum.ANIMAL_SEX)) + # notes f.set_widget("notes", "notes") - # image + # asset_type if self.creating: + f.remove("asset_type") + else: + f.set_default("asset_type", "Animal") + f.set_readonly("asset_type") + + # image_url + if self.creating or self.editing: + f.remove("image_url") + + # image + if self.creating or self.editing: f.remove("image") elif animal.image_url: f.set_widget("image", ImageWidget("animal image"))