From 19b6738e5dfbe2e9ba3e1fd15604d76a969053a0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 7 Feb 2026 17:03:35 -0600 Subject: [PATCH] feat: add view for farmOS asset types of limited value perhaps, but what the heck --- 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/asset_types.py | 101 ++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 src/wuttafarm/web/views/farmos/asset_types.py diff --git a/src/wuttafarm/web/menus.py b/src/wuttafarm/web/menus.py index dbeba44..0f46281 100644 --- a/src/wuttafarm/web/menus.py +++ b/src/wuttafarm/web/menus.py @@ -57,6 +57,11 @@ class WuttaFarmMenuHandler(base.MenuHandler): "route": "farmos_structures", "perm": "farmos_structures.list", }, + { + "title": "Asset Types", + "route": "farmos_asset_types", + "perm": "farmos_asset_types.list", + }, {"type": "sep"}, { "title": "Users", diff --git a/src/wuttafarm/web/views/common.py b/src/wuttafarm/web/views/common.py index a238983..0a4e72f 100644 --- a/src/wuttafarm/web/views/common.py +++ b/src/wuttafarm/web/views/common.py @@ -52,6 +52,8 @@ class CommonView(base.CommonView): "farmos_animal_types.view", "farmos_animals.list", "farmos_animals.view", + "farmos_asset_types.list", + "farmos_asset_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 52652b8..d7e699b 100644 --- a/src/wuttafarm/web/views/farmos/__init__.py +++ b/src/wuttafarm/web/views/farmos/__init__.py @@ -28,6 +28,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.structures") config.include("wuttafarm.web.views.farmos.animal_types") config.include("wuttafarm.web.views.farmos.animals") diff --git a/src/wuttafarm/web/views/farmos/asset_types.py b/src/wuttafarm/web/views/farmos/asset_types.py new file mode 100644 index 0000000..75eebbe --- /dev/null +++ b/src/wuttafarm/web/views/farmos/asset_types.py @@ -0,0 +1,101 @@ +# -*- 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 asset types +""" + +from wuttafarm.web.views.farmos import FarmOSMasterView + + +class AssetTypeView(FarmOSMasterView): + """ + View for farmOS asset types + """ + + model_name = "farmos_asset_type" + model_title = "farmOS Asset Type" + model_title_plural = "farmOS Asset Types" + + route_prefix = "farmos_asset_types" + url_prefix = "/farmOS/asset-types" + + grid_columns = [ + "label", + "description", + ] + + sort_defaults = "label" + + form_fields = [ + "label", + "description", + ] + + def get_grid_data(self, columns=None, session=None): + asset_types = self.farmos_client.resource.get("asset_type", "asset_type") + return [self.normalize_asset_type(t) for t in asset_types["data"]] + + def configure_grid(self, grid): + g = grid + super().configure_grid(g) + + # label + g.set_link("label") + g.set_searchable("label") + + # description + g.set_searchable("description") + + def get_instance(self): + asset_type = self.farmos_client.resource.get_id( + "asset_type", "asset_type", self.request.matchdict["uuid"] + ) + return self.normalize_asset_type(asset_type["data"]) + + def get_instance_title(self, asset_type): + return asset_type["label"] + + def normalize_asset_type(self, asset_type): + return { + "uuid": asset_type["id"], + "drupal_internal_id": asset_type["attributes"]["drupal_internal__id"], + "label": asset_type["attributes"]["label"], + "description": asset_type["attributes"]["description"], + } + + def configure_form(self, form): + f = form + super().configure_form(f) + + # description + f.set_widget("description", "notes") + + +def defaults(config, **kwargs): + base = globals() + + AssetTypeView = kwargs.get("AssetTypeView", base["AssetTypeView"]) + AssetTypeView.defaults(config) + + +def includeme(config): + defaults(config)