feat: add view for farmOS structure types
This commit is contained in:
parent
acba07aa0e
commit
7d65d3c5a2
4 changed files with 98 additions and 0 deletions
|
|
@ -68,6 +68,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
|
|||
"route": "farmos_animal_types",
|
||||
"perm": "farmos_animal_types.list",
|
||||
},
|
||||
{
|
||||
"title": "Structure Types",
|
||||
"route": "farmos_structure_types",
|
||||
"perm": "farmos_structure_types.list",
|
||||
},
|
||||
{
|
||||
"title": "Land Types",
|
||||
"route": "farmos_land_types",
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ class CommonView(base.CommonView):
|
|||
"farmos_land_assets.view",
|
||||
"farmos_land_types.list",
|
||||
"farmos_land_types.view",
|
||||
"farmos_structure_types.list",
|
||||
"farmos_structure_types.view",
|
||||
"farmos_structures.list",
|
||||
"farmos_structures.view",
|
||||
"farmos_users.list",
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ def includeme(config):
|
|||
config.include("wuttafarm.web.views.farmos.asset_types")
|
||||
config.include("wuttafarm.web.views.farmos.land_types")
|
||||
config.include("wuttafarm.web.views.farmos.land_assets")
|
||||
config.include("wuttafarm.web.views.farmos.structure_types")
|
||||
config.include("wuttafarm.web.views.farmos.structures")
|
||||
config.include("wuttafarm.web.views.farmos.animal_types")
|
||||
config.include("wuttafarm.web.views.farmos.animals")
|
||||
|
|
|
|||
90
src/wuttafarm/web/views/farmos/structure_types.py
Normal file
90
src/wuttafarm/web/views/farmos/structure_types.py
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
View for farmOS structure types
|
||||
"""
|
||||
|
||||
from wuttafarm.web.views.farmos import FarmOSMasterView
|
||||
|
||||
|
||||
class StructureTypeView(FarmOSMasterView):
|
||||
"""
|
||||
Master view for Structure Types in farmOS.
|
||||
"""
|
||||
|
||||
model_name = "farmos_structure_type"
|
||||
model_title = "farmOS Structure Type"
|
||||
model_title_plural = "farmOS Structure Types"
|
||||
|
||||
route_prefix = "farmos_structure_types"
|
||||
url_prefix = "/farmOS/structure-types"
|
||||
|
||||
grid_columns = [
|
||||
"label",
|
||||
]
|
||||
|
||||
sort_defaults = "label"
|
||||
|
||||
form_fields = [
|
||||
"label",
|
||||
]
|
||||
|
||||
def get_grid_data(self, columns=None, session=None):
|
||||
structure_types = self.farmos_client.resource.get(
|
||||
"structure_type", "structure_type"
|
||||
)
|
||||
return [self.normalize_structure_type(t) for t in structure_types["data"]]
|
||||
|
||||
def configure_grid(self, grid):
|
||||
g = grid
|
||||
super().configure_grid(g)
|
||||
|
||||
# label
|
||||
g.set_link("label")
|
||||
g.set_searchable("label")
|
||||
|
||||
def get_instance(self):
|
||||
structure_type = self.farmos_client.resource.get_id(
|
||||
"structure_type", "structure_type", self.request.matchdict["uuid"]
|
||||
)
|
||||
return self.normalize_structure_type(structure_type["data"])
|
||||
|
||||
def get_instance_title(self, structure_type):
|
||||
return structure_type["label"]
|
||||
|
||||
def normalize_structure_type(self, structure_type):
|
||||
return {
|
||||
"uuid": structure_type["id"],
|
||||
"drupal_internal_id": structure_type["attributes"]["drupal_internal__id"],
|
||||
"label": structure_type["attributes"]["label"],
|
||||
}
|
||||
|
||||
|
||||
def defaults(config, **kwargs):
|
||||
base = globals()
|
||||
|
||||
StructureTypeView = kwargs.get("StructureTypeView", base["StructureTypeView"])
|
||||
StructureTypeView.defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
defaults(config)
|
||||
Loading…
Add table
Add a link
Reference in a new issue