From acba07aa0e601b563a1ad83c94906a27c2a0faeb Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 7 Feb 2026 18:19:11 -0600 Subject: [PATCH] feat: add view for farmOS land types --- src/wuttafarm/web/menus.py | 5 ++ src/wuttafarm/web/views/common.py | 2 + src/wuttafarm/web/views/farmos/__init__.py | 1 + src/wuttafarm/web/views/farmos/land_types.py | 88 ++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 src/wuttafarm/web/views/farmos/land_types.py diff --git a/src/wuttafarm/web/menus.py b/src/wuttafarm/web/menus.py index a9e66e9..2897038 100644 --- a/src/wuttafarm/web/menus.py +++ b/src/wuttafarm/web/menus.py @@ -68,6 +68,11 @@ class WuttaFarmMenuHandler(base.MenuHandler): "route": "farmos_animal_types", "perm": "farmos_animal_types.list", }, + { + "title": "Land Types", + "route": "farmos_land_types", + "perm": "farmos_land_types.list", + }, { "title": "Asset Types", "route": "farmos_asset_types", diff --git a/src/wuttafarm/web/views/common.py b/src/wuttafarm/web/views/common.py index b13d43b..1c6e977 100644 --- a/src/wuttafarm/web/views/common.py +++ b/src/wuttafarm/web/views/common.py @@ -58,6 +58,8 @@ class CommonView(base.CommonView): "farmos_groups.view", "farmos_land_assets.list", "farmos_land_assets.view", + "farmos_land_types.list", + "farmos_land_types.view", "farmos_structures.list", "farmos_structures.view", "farmos_users.list", diff --git a/src/wuttafarm/web/views/farmos/__init__.py b/src/wuttafarm/web/views/farmos/__init__.py index a194d64..e1dc122 100644 --- a/src/wuttafarm/web/views/farmos/__init__.py +++ b/src/wuttafarm/web/views/farmos/__init__.py @@ -29,6 +29,7 @@ from .master import FarmOSMasterView def includeme(config): config.include("wuttafarm.web.views.farmos.users") 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.structures") config.include("wuttafarm.web.views.farmos.animal_types") diff --git a/src/wuttafarm/web/views/farmos/land_types.py b/src/wuttafarm/web/views/farmos/land_types.py new file mode 100644 index 0000000..aadece8 --- /dev/null +++ b/src/wuttafarm/web/views/farmos/land_types.py @@ -0,0 +1,88 @@ +# -*- 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 . +# +################################################################################ +""" +View for farmOS land types +""" + +from wuttafarm.web.views.farmos import FarmOSMasterView + + +class LandTypeView(FarmOSMasterView): + """ + Master view for Land Types in farmOS. + """ + + model_name = "farmos_land_type" + model_title = "farmOS Land Type" + model_title_plural = "farmOS Land Types" + + route_prefix = "farmos_land_types" + url_prefix = "/farmOS/land-types" + + grid_columns = [ + "label", + ] + + sort_defaults = "label" + + form_fields = [ + "label", + ] + + def get_grid_data(self, columns=None, session=None): + land_types = self.farmos_client.resource.get("land_type", "land_type") + return [self.normalize_land_type(t) for t in land_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): + land_type = self.farmos_client.resource.get_id( + "land_type", "land_type", self.request.matchdict["uuid"] + ) + return self.normalize_land_type(land_type["data"]) + + def get_instance_title(self, land_type): + return land_type["label"] + + def normalize_land_type(self, land_type): + return { + "uuid": land_type["id"], + "drupal_internal_id": land_type["attributes"]["drupal_internal__id"], + "label": land_type["attributes"]["label"], + } + + +def defaults(config, **kwargs): + base = globals() + + LandTypeView = kwargs.get("LandTypeView", base["LandTypeView"]) + LandTypeView.defaults(config) + + +def includeme(config): + defaults(config)