Compare commits

...

6 commits

Author SHA1 Message Date
2998e67548 bump: version 0.12.0 → 0.12.1 2026-05-31 11:58:48 -05:00
fbae0bcfc8 fix: allow null for Quantity.measure field
since apparently that is optional, e.g. for "Precipitation" quick form
logs
2026-05-31 11:58:07 -05:00
913d5801cd bump: version 0.11.4 → 0.12.0 2026-05-30 21:30:32 -05:00
be528f0854 feat: add support for Compost Assets 2026-05-30 21:30:01 -05:00
a26f16a67e fix: fix Location column for All Logs subgrid when viewing Asset 2026-05-30 20:52:06 -05:00
03dacd9957 fix: sort related assets field when viewing a log 2026-05-30 20:37:20 -05:00
19 changed files with 438 additions and 8 deletions

View file

@ -5,6 +5,23 @@ All notable changes to WuttaFarm will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## v0.12.1 (2026-05-31)
### Fix
- allow null for `Quantity.measure` field
## v0.12.0 (2026-05-30)
### Feat
- add support for Compost Assets
### Fix
- fix Location column for All Logs subgrid when viewing Asset
- sort related assets field when viewing a log
## v0.11.4 (2026-05-30) ## v0.11.4 (2026-05-30)
### Fix ### Fix

View file

@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "WuttaFarm" name = "WuttaFarm"
version = "0.11.4" version = "0.12.1"
description = "Web app to integrate with and extend farmOS" description = "Web app to integrate with and extend farmOS"
readme = "README.md" readme = "README.md"
authors = [ authors = [

View file

@ -0,0 +1,102 @@
"""add CompostAsset
Revision ID: a240a1449de9
Revises: dd4d4142b96d
Create Date: 2026-05-30 21:12:36.464851
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = "a240a1449de9"
down_revision: Union[str, None] = "dd4d4142b96d"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# asset_compost
op.create_table(
"asset_compost",
sa.Column("uuid", wuttjamaican.db.util.UUID(), nullable=False),
sa.ForeignKeyConstraint(
["uuid"], ["asset.uuid"], name=op.f("fk_asset_compost_uuid_asset")
),
sa.PrimaryKeyConstraint("uuid", name=op.f("pk_asset_compost")),
)
op.create_table(
"asset_compost_version",
sa.Column(
"uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=False
),
sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
),
sa.Column("end_transaction_id", sa.BigInteger(), nullable=True),
sa.Column("operation_type", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint(
"uuid", "transaction_id", name=op.f("pk_asset_compost_version")
),
)
op.create_index(
op.f("ix_asset_compost_version_end_transaction_id"),
"asset_compost_version",
["end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_asset_compost_version_operation_type"),
"asset_compost_version",
["operation_type"],
unique=False,
)
op.create_index(
"ix_asset_compost_version_pk_transaction_id",
"asset_compost_version",
["uuid", sa.literal_column("transaction_id DESC")],
unique=False,
)
op.create_index(
"ix_asset_compost_version_pk_validity",
"asset_compost_version",
["uuid", "transaction_id", "end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_asset_compost_version_transaction_id"),
"asset_compost_version",
["transaction_id"],
unique=False,
)
def downgrade() -> None:
# asset_compost
op.drop_index(
op.f("ix_asset_compost_version_transaction_id"),
table_name="asset_compost_version",
)
op.drop_index(
"ix_asset_compost_version_pk_validity", table_name="asset_compost_version"
)
op.drop_index(
"ix_asset_compost_version_pk_transaction_id", table_name="asset_compost_version"
)
op.drop_index(
op.f("ix_asset_compost_version_operation_type"),
table_name="asset_compost_version",
)
op.drop_index(
op.f("ix_asset_compost_version_end_transaction_id"),
table_name="asset_compost_version",
)
op.drop_table("asset_compost_version")
op.drop_table("asset_compost")

View file

@ -0,0 +1,36 @@
"""allow null for quantity.measure_id
Revision ID: c30a725b54f9
Revises: a240a1449de9
Create Date: 2026-05-30 22:14:21.056993
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = "c30a725b54f9"
down_revision: Union[str, None] = "a240a1449de9"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# quantity
op.alter_column(
"quantity", "measure_id", existing_type=sa.VARCHAR(length=20), nullable=True
)
def downgrade() -> None:
# quantity
op.alter_column(
"quantity", "measure_id", existing_type=sa.VARCHAR(length=20), nullable=False
)

View file

@ -53,6 +53,7 @@ from .asset_plant import (
PlantAssetSeason, PlantAssetSeason,
) )
from .asset_water import WaterAsset from .asset_water import WaterAsset
from .asset_compost import CompostAsset
from .log import LogType, Log, LogAsset, LogGroup, LogLocation, LogQuantity, LogOwner from .log import LogType, Log, LogAsset, LogGroup, LogLocation, LogQuantity, LogOwner
from .log_activity import ActivityLog from .log_activity import ActivityLog
from .log_harvest import HarvestLog from .log_harvest import HarvestLog

View file

@ -0,0 +1,45 @@
# -*- 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/>.
#
################################################################################
"""
Model definition for Compost
"""
from wuttjamaican.db import model
from wuttafarm.db.model.asset import AssetMixin, add_asset_proxies
class CompostAsset(AssetMixin, model.Base):
"""
Represents an compost asset from farmOS
"""
__tablename__ = "asset_compost"
__versioned__ = {}
__wutta_hint__ = {
"model_title": "Compost Asset",
"model_title_plural": "Compost Assets",
"farmos_asset_type": "compost",
}
add_asset_proxies(CompostAsset)

View file

@ -109,7 +109,7 @@ class Quantity(model.Base):
measure_id = sa.Column( measure_id = sa.Column(
sa.String(length=20), sa.String(length=20),
sa.ForeignKey("measure.drupal_id"), sa.ForeignKey("measure.drupal_id"),
nullable=False, nullable=True,
doc=""" doc="""
Measure for the quantity. Measure for the quantity.
""", """,
@ -192,7 +192,12 @@ class Quantity(model.Base):
app = config.get_app() app = config.get_app()
value = app.render_quantity(value) value = app.render_quantity(value)
units = str(self.units or "") units = str(self.units or "")
return f"( {measure} ) {value} {units}"
if measure:
return f"( {measure} ) {value} {units}"
label = self.label or ""
return f"{label} {value} {units}"
def __str__(self): def __str__(self):
return self.render_as_text() return self.render_as_text()

View file

@ -574,6 +574,21 @@ class WaterAssetImporter(ToFarmOSAsset):
] ]
class CompostAssetImporter(ToFarmOSAsset):
model_title = "CompostAsset"
farmos_asset_type = "compost"
supported_fields = [
"uuid",
"asset_name",
"is_location",
"is_fixed",
"notes",
"archived",
]
############################## ##############################
# quantity importers # quantity importers
############################## ##############################

View file

@ -99,6 +99,7 @@ class FromWuttaFarmToFarmOS(FromWuttaFarmHandler, ToFarmOSHandler):
importers["LandAsset"] = LandAssetImporter importers["LandAsset"] = LandAssetImporter
importers["StructureAsset"] = StructureAssetImporter importers["StructureAsset"] = StructureAssetImporter
importers["WaterAsset"] = WaterAssetImporter importers["WaterAsset"] = WaterAssetImporter
importers["CompostAsset"] = CompostAssetImporter
importers["EquipmentType"] = EquipmentTypeImporter importers["EquipmentType"] = EquipmentTypeImporter
importers["EquipmentAsset"] = EquipmentAssetImporter importers["EquipmentAsset"] = EquipmentAssetImporter
importers["AnimalType"] = AnimalTypeImporter importers["AnimalType"] = AnimalTypeImporter
@ -475,6 +476,16 @@ class WaterAssetImporter(FromWuttaFarmAsset, farmos_importing.model.WaterAssetIm
source_model_class = model.WaterAsset source_model_class = model.WaterAsset
class CompostAssetImporter(
FromWuttaFarmAsset, farmos_importing.model.CompostAssetImporter
):
"""
WuttaFarm farmOS API exporter for Compost Assets
"""
source_model_class = model.CompostAsset
############################## ##############################
# quantity importers # quantity importers
############################## ##############################

View file

@ -107,6 +107,7 @@ class FromFarmOSToWuttaFarm(FromFarmOSHandler, ToWuttaFarmHandler):
importers["StructureType"] = StructureTypeImporter importers["StructureType"] = StructureTypeImporter
importers["StructureAsset"] = StructureAssetImporter importers["StructureAsset"] = StructureAssetImporter
importers["WaterAsset"] = WaterAssetImporter importers["WaterAsset"] = WaterAssetImporter
importers["CompostAsset"] = CompostAssetImporter
importers["EquipmentType"] = EquipmentTypeImporter importers["EquipmentType"] = EquipmentTypeImporter
importers["EquipmentAsset"] = EquipmentAssetImporter importers["EquipmentAsset"] = EquipmentAssetImporter
importers["AnimalType"] = AnimalTypeImporter importers["AnimalType"] = AnimalTypeImporter
@ -1033,6 +1034,14 @@ class WaterAssetImporter(AssetImporterBase):
model_class = model.WaterAsset model_class = model.WaterAsset
class CompostAssetImporter(AssetImporterBase):
"""
farmOS API WuttaFarm importer for Compost Assets
"""
model_class = model.CompostAsset
class UserImporter(FromFarmOS, ToWutta): class UserImporter(FromFarmOS, ToWutta):
""" """
farmOS API WuttaFarm importer for Users farmOS API WuttaFarm importer for Users

View file

@ -667,10 +667,17 @@ class AssetRefsWidget(Widget):
readonly = kw.get("readonly", self.readonly) readonly = kw.get("readonly", self.readonly)
if readonly: if readonly:
assets = [] assets = []
for uuid in cstruct or []: for uuid in cstruct or []:
asset = session.get(model.Asset, uuid) if asset := session.get(model.Asset, uuid):
assets.append( assets.append(asset)
assets.sort(key=lambda asset: asset.asset_name)
html = []
for asset in assets:
html.append(
HTML.tag( HTML.tag(
"li", "li",
c=tags.link_to( c=tags.link_to(
@ -681,7 +688,8 @@ class AssetRefsWidget(Widget):
), ),
) )
) )
return HTML.tag("ul", c=assets)
return HTML.tag("ul", c=html)
values = kw.get("values", self.values) values = kw.get("values", self.values)
if not isinstance(values, sequence_types): if not isinstance(values, sequence_types):

View file

@ -92,6 +92,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
"route": "animal_assets", "route": "animal_assets",
"perm": "animal_assets.list", "perm": "animal_assets.list",
}, },
{
"title": "Compost",
"route": "compost_assets",
"perm": "compost_assets.list",
},
{ {
"title": "Equipment", "title": "Equipment",
"route": "equipment_assets", "route": "equipment_assets",
@ -259,6 +264,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
"route": "farmos_animal_assets", "route": "farmos_animal_assets",
"perm": "farmos_animal_assets.list", "perm": "farmos_animal_assets.list",
}, },
{
"title": "Compost Assets",
"route": "farmos_compost_assets",
"perm": "farmos_compost_assets.list",
},
{ {
"title": "Equipment Assets", "title": "Equipment Assets",
"route": "farmos_equipment_assets", "route": "farmos_equipment_assets",
@ -403,6 +413,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
"route": "farmos_animal_assets", "route": "farmos_animal_assets",
"perm": "farmos_animal_assets.list", "perm": "farmos_animal_assets.list",
}, },
{
"title": "Compost",
"route": "farmos_compost_assets",
"perm": "farmos_compost_assets.list",
},
{ {
"title": "Equipment", "title": "Equipment",
"route": "farmos_equipment_assets", "route": "farmos_equipment_assets",

View file

@ -59,6 +59,7 @@ def includeme(config):
config.include("wuttafarm.web.views.groups") config.include("wuttafarm.web.views.groups")
config.include("wuttafarm.web.views.plants") config.include("wuttafarm.web.views.plants")
config.include("wuttafarm.web.views.water") config.include("wuttafarm.web.views.water")
config.include("wuttafarm.web.views.compost")
config.include("wuttafarm.web.views.logs") config.include("wuttafarm.web.views.logs")
config.include("wuttafarm.web.views.logs_activity") config.include("wuttafarm.web.views.logs_activity")
config.include("wuttafarm.web.views.logs_harvest") config.include("wuttafarm.web.views.logs_harvest")

View file

@ -71,6 +71,18 @@ class AssetMasterView(WuttaFarmMasterView):
"groups": "Group Membership", "groups": "Group Membership",
} }
grid_columns = [
"thumbnail",
"drupal_id",
"asset_name",
"groups",
"asset_type",
"parents",
"owners",
"locations",
"archived",
]
sort_defaults = "asset_name" sort_defaults = "asset_name"
filter_defaults = { filter_defaults = {
@ -103,6 +115,7 @@ class AssetMasterView(WuttaFarmMasterView):
row_labels = { row_labels = {
"message": "Log Name", "message": "Log Name",
"locations": "Location",
} }
row_grid_columns = [ row_grid_columns = [
@ -112,7 +125,7 @@ class AssetMasterView(WuttaFarmMasterView):
"message", "message",
"log_type", "log_type",
"assets", "assets",
"location", "locations",
"quantity", "quantity",
"is_group_assignment", "is_group_assignment",
] ]
@ -446,6 +459,9 @@ class AssetMasterView(WuttaFarmMasterView):
# assets # assets
g.set_renderer("assets", self.render_assets_for_grid) g.set_renderer("assets", self.render_assets_for_grid)
# locations
g.set_renderer("locations", self.render_assets_for_grid)
def render_assets_for_grid(self, log, field, value): def render_assets_for_grid(self, log, field, value):
assets = getattr(log, field) assets = getattr(log, field)

View file

@ -0,0 +1,62 @@
# -*- 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/>.
#
################################################################################
"""
Master view for Compost Assets
"""
from wuttafarm.db.model import CompostAsset
from wuttafarm.web.views.assets import AssetMasterView
class CompostAssetView(AssetMasterView):
"""
Master view for Compost Assets
"""
model_class = CompostAsset
route_prefix = "compost_assets"
url_prefix = "/assets/compost"
farmos_bundle = "compost"
farmos_refurl_path = "/assets/compost"
grid_columns = [
"thumbnail",
"drupal_id",
"asset_name",
"groups",
"parents",
"owners",
"locations",
"archived",
]
def defaults(config, **kwargs):
base = globals()
CompostAssetView = kwargs.get("CompostAssetView", base["CompostAssetView"])
CompostAssetView.defaults(config)
def includeme(config):
defaults(config)

View file

@ -42,6 +42,7 @@ def includeme(config):
config.include("wuttafarm.web.views.farmos.groups") config.include("wuttafarm.web.views.farmos.groups")
config.include("wuttafarm.web.views.farmos.plants") config.include("wuttafarm.web.views.farmos.plants")
config.include("wuttafarm.web.views.farmos.water") config.include("wuttafarm.web.views.farmos.water")
config.include("wuttafarm.web.views.farmos.compost")
config.include("wuttafarm.web.views.farmos.log_types") config.include("wuttafarm.web.views.farmos.log_types")
config.include("wuttafarm.web.views.farmos.logs_activity") config.include("wuttafarm.web.views.farmos.logs_activity")
config.include("wuttafarm.web.views.farmos.logs_harvest") config.include("wuttafarm.web.views.farmos.logs_harvest")

View file

@ -327,6 +327,12 @@ class AssetMasterView(FarmOSMasterView):
# archived # archived
f.set_node("archived", colander.Boolean()) f.set_node("archived", colander.Boolean())
# drupal_id
if self.creating:
f.remove("drupal_id")
else:
f.set_readonly("drupal_id")
# thumbnail_url # thumbnail_url
if self.creating or self.editing: if self.creating or self.editing:
f.remove("thumbnail_url") f.remove("thumbnail_url")

View file

@ -0,0 +1,79 @@
# -*- 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/>.
#
################################################################################
"""
Master view for farmOS Compost Assets
"""
from webhelpers2.html import tags
from wuttafarm.web.views.farmos.assets import AssetMasterView
class CompostAssetView(AssetMasterView):
"""
Master view for farmOS Compost Assets
"""
model_name = "farmos_compost_assets"
model_title = "farmOS Compost Asset"
model_title_plural = "farmOS Compost Assets"
route_prefix = "farmos_compost_assets"
url_prefix = "/farmOS/assets/compost"
farmos_asset_type = "compost"
farmos_refurl_path = "/assets/compost"
def get_xref_buttons(self, compost):
model = self.app.model
session = self.Session()
buttons = super().get_xref_buttons(compost)
if wf_compost := (
session.query(model.Asset)
.filter(model.Asset.farmos_uuid == compost["uuid"])
.first()
):
buttons.append(
self.make_button(
f"View {self.app.get_title()} record",
primary=True,
url=self.request.route_url(
"compost_assets.view", uuid=wf_compost.uuid
),
icon_left="eye",
)
)
return buttons
def defaults(config, **kwargs):
base = globals()
CompostAssetView = kwargs.get("CompostAssetView", base["CompostAssetView"])
CompostAssetView.defaults(config)
def includeme(config):
defaults(config)

View file

@ -298,7 +298,8 @@ class QuantityMasterView(WuttaFarmMasterView):
f.remove("measure") f.remove("measure")
else: else:
f.set_readonly("measure") f.set_readonly("measure")
f.set_default("measure", quantity.measure.name) if quantity.measure:
f.set_default("measure", quantity.measure.name)
# value # value
if self.creating: if self.creating: