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:
parent
df4536741d
commit
25b2dc6cec
3 changed files with 78 additions and 5 deletions
|
|
@ -39,8 +39,9 @@ class WuttaFarmConfig(WuttaConfigExtension):
|
||||||
config.setdefault(f"{config.appname}.app_title", "WuttaFarm")
|
config.setdefault(f"{config.appname}.app_title", "WuttaFarm")
|
||||||
config.setdefault(f"{config.appname}.app_dist", "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}.model_spec", "wuttafarm.db.model")
|
||||||
|
config.setdefault(f"{config.appname}.enum_spec", "wuttafarm.enum")
|
||||||
|
|
||||||
# app handler
|
# app handler
|
||||||
config.setdefault(
|
config.setdefault(
|
||||||
|
|
|
||||||
36
src/wuttafarm/enum.py
Normal file
36
src/wuttafarm/enum.py
Normal 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"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
Master view for Animals
|
Master view for Animals
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from wuttaweb.forms.schema import WuttaDictEnum
|
||||||
|
|
||||||
from wuttafarm.db.model.animals import Animal
|
from wuttafarm.db.model.animals import Animal
|
||||||
from wuttafarm.web.views import WuttaFarmMasterView
|
from wuttafarm.web.views import WuttaFarmMasterView
|
||||||
from wuttafarm.web.forms.schema import AnimalTypeRef
|
from wuttafarm.web.forms.schema import AnimalTypeRef
|
||||||
|
|
@ -40,12 +42,19 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
|
|
||||||
farmos_refurl_path = "/assets/animal"
|
farmos_refurl_path = "/assets/animal"
|
||||||
|
|
||||||
|
labels = {
|
||||||
|
"name": "Asset Name",
|
||||||
|
"animal_type": "Species/Breed",
|
||||||
|
"is_sterile": "Sterile",
|
||||||
|
}
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
|
"drupal_id",
|
||||||
"name",
|
"name",
|
||||||
"animal_type",
|
"animal_type",
|
||||||
"sex",
|
|
||||||
"is_sterile",
|
|
||||||
"birthdate",
|
"birthdate",
|
||||||
|
"is_sterile",
|
||||||
|
"sex",
|
||||||
"archived",
|
"archived",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -53,6 +62,7 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
|
|
||||||
filter_defaults = {
|
filter_defaults = {
|
||||||
"name": {"active": True, "verb": "contains"},
|
"name": {"active": True, "verb": "contains"},
|
||||||
|
"archived": {"active": True, "verb": "is_false"},
|
||||||
}
|
}
|
||||||
|
|
||||||
form_fields = [
|
form_fields = [
|
||||||
|
|
@ -61,8 +71,9 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
"birthdate",
|
"birthdate",
|
||||||
"sex",
|
"sex",
|
||||||
"is_sterile",
|
"is_sterile",
|
||||||
"archived",
|
|
||||||
"notes",
|
"notes",
|
||||||
|
"asset_type",
|
||||||
|
"archived",
|
||||||
"farmos_uuid",
|
"farmos_uuid",
|
||||||
"drupal_id",
|
"drupal_id",
|
||||||
"image_url",
|
"image_url",
|
||||||
|
|
@ -73,6 +84,10 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
g = grid
|
g = grid
|
||||||
super().configure_grid(g)
|
super().configure_grid(g)
|
||||||
model = self.app.model
|
model = self.app.model
|
||||||
|
enum = self.app.enum
|
||||||
|
|
||||||
|
# drupal_id
|
||||||
|
g.set_label("drupal_id", "ID", column_only=True)
|
||||||
|
|
||||||
# name
|
# name
|
||||||
g.set_link("name")
|
g.set_link("name")
|
||||||
|
|
@ -82,19 +97,40 @@ class AnimalView(WuttaFarmMasterView):
|
||||||
g.set_sorter("animal_type", model.AnimalType.name)
|
g.set_sorter("animal_type", model.AnimalType.name)
|
||||||
g.set_filter("animal_type", model.AnimalType.name, label="Animal Type 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):
|
def configure_form(self, form):
|
||||||
f = form
|
f = form
|
||||||
super().configure_form(f)
|
super().configure_form(f)
|
||||||
|
enum = self.app.enum
|
||||||
animal = form.model_instance
|
animal = form.model_instance
|
||||||
|
|
||||||
# animal_type
|
# animal_type
|
||||||
f.set_node("animal_type", AnimalTypeRef(self.request))
|
f.set_node("animal_type", AnimalTypeRef(self.request))
|
||||||
|
|
||||||
|
# sex
|
||||||
|
f.set_node("sex", WuttaDictEnum(self.request, enum.ANIMAL_SEX))
|
||||||
|
|
||||||
# notes
|
# notes
|
||||||
f.set_widget("notes", "notes")
|
f.set_widget("notes", "notes")
|
||||||
|
|
||||||
# image
|
# asset_type
|
||||||
if self.creating:
|
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")
|
f.remove("image")
|
||||||
elif animal.image_url:
|
elif animal.image_url:
|
||||||
f.set_widget("image", ImageWidget("animal image"))
|
f.set_widget("image", ImageWidget("animal image"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue