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
This commit is contained in:
parent
cfe2e4b7b4
commit
d884a761ad
4 changed files with 120 additions and 0 deletions
|
|
@ -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"),
|
||||
|
|
|
|||
28
src/wuttafarm/web/templates/appinfo/configure.mako
Normal file
28
src/wuttafarm/web/templates/appinfo/configure.mako
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
<%inherit file="wuttaweb:templates/appinfo/configure.mako" />
|
||||
|
||||
<%def name="form_content()">
|
||||
${parent.form_content()}
|
||||
|
||||
<h3 class="block is-size-3">farmOS</h3>
|
||||
<div class="block" style="padding-left: 2rem; width: 50%;">
|
||||
|
||||
<b-field label="farmOS Integration Mode">
|
||||
<b-select name="${app.appname}.farmos_integration_mode"
|
||||
v-model="simpleSettings['${app.appname}.farmos_integration_mode']"
|
||||
@input="settingsNeedSaved = true">
|
||||
% for value, label in enum.FARMOS_INTEGRATION_MODE.items():
|
||||
<option value="${value}">${label}</option>
|
||||
% endfor
|
||||
</b-select>
|
||||
</b-field>
|
||||
|
||||
<b-field label="farmOS URL">
|
||||
<b-input name="farmos.url.base"
|
||||
v-model="simpleSettings['farmos.url.base']"
|
||||
@input="settingsNeedSaved = true">
|
||||
</b-input>
|
||||
</b-field>
|
||||
|
||||
</div>
|
||||
</%def>
|
||||
|
|
@ -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",
|
||||
}
|
||||
)
|
||||
|
|
|
|||
78
src/wuttafarm/web/views/settings.py
Normal file
78
src/wuttafarm/web/views/settings.py
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue