From d884a761ad0048430361fbfad680b141a2d1f700 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 19 Feb 2026 18:56:38 -0600 Subject: [PATCH] fix: expose farmOS integration mode, URL in app settings although as of now changing the integration mode setting will not actually change any behavior.. but it will refs: #3 --- src/wuttafarm/enum.py | 13 ++++ .../web/templates/appinfo/configure.mako | 28 +++++++ src/wuttafarm/web/views/__init__.py | 1 + src/wuttafarm/web/views/settings.py | 78 +++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 src/wuttafarm/web/templates/appinfo/configure.mako create mode 100644 src/wuttafarm/web/views/settings.py diff --git a/src/wuttafarm/enum.py b/src/wuttafarm/enum.py index 03181b9..870e4cd 100644 --- a/src/wuttafarm/enum.py +++ b/src/wuttafarm/enum.py @@ -28,6 +28,19 @@ from collections import OrderedDict from wuttjamaican.enum import * +FARMOS_INTEGRATION_MODE_WRAPPER = "wrapper" +FARMOS_INTEGRATION_MODE_MIRROR = "mirror" +FARMOS_INTEGRATION_MODE_NONE = "none" + +FARMOS_INTEGRATION_MODE = OrderedDict( + [ + (FARMOS_INTEGRATION_MODE_WRAPPER, "wrapper (API only)"), + (FARMOS_INTEGRATION_MODE_MIRROR, "mirror (2-way sync)"), + (FARMOS_INTEGRATION_MODE_NONE, "none (standalone)"), + ] +) + + ANIMAL_SEX = OrderedDict( [ ("M", "Male"), diff --git a/src/wuttafarm/web/templates/appinfo/configure.mako b/src/wuttafarm/web/templates/appinfo/configure.mako new file mode 100644 index 0000000..d9e448f --- /dev/null +++ b/src/wuttafarm/web/templates/appinfo/configure.mako @@ -0,0 +1,28 @@ +## -*- coding: utf-8; -*- +<%inherit file="wuttaweb:templates/appinfo/configure.mako" /> + +<%def name="form_content()"> + ${parent.form_content()} + +

farmOS

+
+ + + + % for value, label in enum.FARMOS_INTEGRATION_MODE.items(): + + % endfor + + + + + + + + +
+ diff --git a/src/wuttafarm/web/views/__init__.py b/src/wuttafarm/web/views/__init__.py index 21dcbad..5e31d84 100644 --- a/src/wuttafarm/web/views/__init__.py +++ b/src/wuttafarm/web/views/__init__.py @@ -36,6 +36,7 @@ def includeme(config): **{ "wuttaweb.views.auth": "wuttafarm.web.views.auth", "wuttaweb.views.common": "wuttafarm.web.views.common", + "wuttaweb.views.settings": "wuttafarm.web.views.settings", "wuttaweb.views.users": "wuttafarm.web.views.users", } ) diff --git a/src/wuttafarm/web/views/settings.py b/src/wuttafarm/web/views/settings.py new file mode 100644 index 0000000..3b2c858 --- /dev/null +++ b/src/wuttafarm/web/views/settings.py @@ -0,0 +1,78 @@ +# -*- 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 . +# +################################################################################ +""" +Custom views for Settings +""" + +from webhelpers2.html import tags + +from wuttaweb.views import settings as base + + +class AppInfoView(base.AppInfoView): + """ + Custom appinfo view + """ + + def get_appinfo_dict(self): + info = super().get_appinfo_dict() + enum = self.app.enum + + mode = self.config.get( + f"{self.app.appname}.farmos_integration_mode", default="wrapper" + ) + + info["farmos_integration"] = { + "label": "farmOS Integration", + "value": enum.FARMOS_INTEGRATION_MODE.get(mode, mode), + } + + url = self.app.get_farmos_url() + info["farmos_url"] = { + "label": "farmOS URL", + "value": tags.link_to(url, url, target="_blank"), + } + + return info + + def configure_get_simple_settings(self): # pylint: disable=empty-docstring + simple_settings = super().configure_get_simple_settings() + simple_settings.extend( + [ + {"name": "farmos.url.base"}, + { + "name": f"{self.app.appname}.farmos_integration_mode", + "default": "wrapper", + }, + ] + ) + return simple_settings + + +def defaults(config, **kwargs): + local = globals() + AppInfoView = kwargs.get("AppInfoView", local["AppInfoView"]) + base.defaults(config, **{"AppInfoView": AppInfoView}) + + +def includeme(config): + defaults(config)