feat: add view for farmOS log types
This commit is contained in:
parent
33717bb055
commit
f7d5d0ab1c
4 changed files with 106 additions and 0 deletions
|
|
@ -91,6 +91,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
|
||||||
"route": "farmos_asset_types",
|
"route": "farmos_asset_types",
|
||||||
"perm": "farmos_asset_types.list",
|
"perm": "farmos_asset_types.list",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"title": "Log Types",
|
||||||
|
"route": "farmos_log_types",
|
||||||
|
"perm": "farmos_log_types.list",
|
||||||
|
},
|
||||||
{"type": "sep"},
|
{"type": "sep"},
|
||||||
{
|
{
|
||||||
"title": "Users",
|
"title": "Users",
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ class CommonView(base.CommonView):
|
||||||
"farmos_land_assets.view",
|
"farmos_land_assets.view",
|
||||||
"farmos_land_types.list",
|
"farmos_land_types.list",
|
||||||
"farmos_land_types.view",
|
"farmos_land_types.view",
|
||||||
|
"farmos_log_types.list",
|
||||||
|
"farmos_log_types.view",
|
||||||
"farmos_structure_types.list",
|
"farmos_structure_types.list",
|
||||||
"farmos_structure_types.view",
|
"farmos_structure_types.view",
|
||||||
"farmos_structures.list",
|
"farmos_structures.list",
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,4 @@ def includeme(config):
|
||||||
config.include("wuttafarm.web.views.farmos.animal_types")
|
config.include("wuttafarm.web.views.farmos.animal_types")
|
||||||
config.include("wuttafarm.web.views.farmos.animals")
|
config.include("wuttafarm.web.views.farmos.animals")
|
||||||
config.include("wuttafarm.web.views.farmos.groups")
|
config.include("wuttafarm.web.views.farmos.groups")
|
||||||
|
config.include("wuttafarm.web.views.farmos.log_types")
|
||||||
|
|
|
||||||
98
src/wuttafarm/web/views/farmos/log_types.py
Normal file
98
src/wuttafarm/web/views/farmos/log_types.py
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
# -*- 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 log types
|
||||||
|
"""
|
||||||
|
|
||||||
|
from wuttafarm.web.views.farmos import FarmOSMasterView
|
||||||
|
|
||||||
|
|
||||||
|
class LogTypeView(FarmOSMasterView):
|
||||||
|
"""
|
||||||
|
Master view for Log Types in farmOS.
|
||||||
|
"""
|
||||||
|
|
||||||
|
model_name = "farmos_log_type"
|
||||||
|
model_title = "farmOS Log Type"
|
||||||
|
model_title_plural = "farmOS Log Types"
|
||||||
|
|
||||||
|
route_prefix = "farmos_log_types"
|
||||||
|
url_prefix = "/farmOS/log-types"
|
||||||
|
|
||||||
|
grid_columns = [
|
||||||
|
"label",
|
||||||
|
"description",
|
||||||
|
]
|
||||||
|
|
||||||
|
sort_defaults = "label"
|
||||||
|
|
||||||
|
form_fields = [
|
||||||
|
"label",
|
||||||
|
"description",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_grid_data(self, columns=None, session=None):
|
||||||
|
log_types = self.farmos_client.resource.get("log_type", "log_type")
|
||||||
|
return [self.normalize_log_type(t) for t in log_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):
|
||||||
|
log_type = self.farmos_client.resource.get_id(
|
||||||
|
"log_type", "log_type", self.request.matchdict["uuid"]
|
||||||
|
)
|
||||||
|
return self.normalize_log_type(log_type["data"])
|
||||||
|
|
||||||
|
def get_instance_title(self, log_type):
|
||||||
|
return log_type["label"]
|
||||||
|
|
||||||
|
def normalize_log_type(self, log_type):
|
||||||
|
return {
|
||||||
|
"uuid": log_type["id"],
|
||||||
|
"drupal_internal_id": log_type["attributes"]["drupal_internal__id"],
|
||||||
|
"label": log_type["attributes"]["label"],
|
||||||
|
"description": log_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()
|
||||||
|
|
||||||
|
LogTypeView = kwargs.get("LogTypeView", base["LogTypeView"])
|
||||||
|
LogTypeView.defaults(config)
|
||||||
|
|
||||||
|
|
||||||
|
def includeme(config):
|
||||||
|
defaults(config)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue