fix: use Male/Female dict enum for animal sex field

and some related changes to make Animal views more like farmOS
This commit is contained in:
Lance Edgar 2026-02-14 19:27:19 -06:00
parent df4536741d
commit 25b2dc6cec
3 changed files with 78 additions and 5 deletions

View file

@ -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(

36
src/wuttafarm/enum.py Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
#
################################################################################
"""
WuttaFarm enum values
"""
from collections import OrderedDict
from wuttjamaican.enum import *
ANIMAL_SEX = OrderedDict(
[
("M", "Male"),
("F", "Female"),
]
)

View file

@ -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"))