feat: add support for Compost Assets
This commit is contained in:
parent
a26f16a67e
commit
be528f0854
13 changed files with 359 additions and 0 deletions
|
|
@ -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")
|
||||
|
|
@ -53,6 +53,7 @@ from .asset_plant import (
|
|||
PlantAssetSeason,
|
||||
)
|
||||
from .asset_water import WaterAsset
|
||||
from .asset_compost import CompostAsset
|
||||
from .log import LogType, Log, LogAsset, LogGroup, LogLocation, LogQuantity, LogOwner
|
||||
from .log_activity import ActivityLog
|
||||
from .log_harvest import HarvestLog
|
||||
|
|
|
|||
45
src/wuttafarm/db/model/asset_compost.py
Normal file
45
src/wuttafarm/db/model/asset_compost.py
Normal 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)
|
||||
|
|
@ -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
|
||||
##############################
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ class FromWuttaFarmToFarmOS(FromWuttaFarmHandler, ToFarmOSHandler):
|
|||
importers["LandAsset"] = LandAssetImporter
|
||||
importers["StructureAsset"] = StructureAssetImporter
|
||||
importers["WaterAsset"] = WaterAssetImporter
|
||||
importers["CompostAsset"] = CompostAssetImporter
|
||||
importers["EquipmentType"] = EquipmentTypeImporter
|
||||
importers["EquipmentAsset"] = EquipmentAssetImporter
|
||||
importers["AnimalType"] = AnimalTypeImporter
|
||||
|
|
@ -475,6 +476,16 @@ class WaterAssetImporter(FromWuttaFarmAsset, farmos_importing.model.WaterAssetIm
|
|||
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
|
||||
##############################
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ class FromFarmOSToWuttaFarm(FromFarmOSHandler, ToWuttaFarmHandler):
|
|||
importers["StructureType"] = StructureTypeImporter
|
||||
importers["StructureAsset"] = StructureAssetImporter
|
||||
importers["WaterAsset"] = WaterAssetImporter
|
||||
importers["CompostAsset"] = CompostAssetImporter
|
||||
importers["EquipmentType"] = EquipmentTypeImporter
|
||||
importers["EquipmentAsset"] = EquipmentAssetImporter
|
||||
importers["AnimalType"] = AnimalTypeImporter
|
||||
|
|
@ -1033,6 +1034,14 @@ class WaterAssetImporter(AssetImporterBase):
|
|||
model_class = model.WaterAsset
|
||||
|
||||
|
||||
class CompostAssetImporter(AssetImporterBase):
|
||||
"""
|
||||
farmOS API → WuttaFarm importer for Compost Assets
|
||||
"""
|
||||
|
||||
model_class = model.CompostAsset
|
||||
|
||||
|
||||
class UserImporter(FromFarmOS, ToWutta):
|
||||
"""
|
||||
farmOS API → WuttaFarm importer for Users
|
||||
|
|
|
|||
|
|
@ -92,6 +92,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
|
|||
"route": "animal_assets",
|
||||
"perm": "animal_assets.list",
|
||||
},
|
||||
{
|
||||
"title": "Compost",
|
||||
"route": "compost_assets",
|
||||
"perm": "compost_assets.list",
|
||||
},
|
||||
{
|
||||
"title": "Equipment",
|
||||
"route": "equipment_assets",
|
||||
|
|
@ -259,6 +264,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
|
|||
"route": "farmos_animal_assets",
|
||||
"perm": "farmos_animal_assets.list",
|
||||
},
|
||||
{
|
||||
"title": "Compost Assets",
|
||||
"route": "farmos_compost_assets",
|
||||
"perm": "farmos_compost_assets.list",
|
||||
},
|
||||
{
|
||||
"title": "Equipment Assets",
|
||||
"route": "farmos_equipment_assets",
|
||||
|
|
@ -403,6 +413,11 @@ class WuttaFarmMenuHandler(base.MenuHandler):
|
|||
"route": "farmos_animal_assets",
|
||||
"perm": "farmos_animal_assets.list",
|
||||
},
|
||||
{
|
||||
"title": "Compost",
|
||||
"route": "farmos_compost_assets",
|
||||
"perm": "farmos_compost_assets.list",
|
||||
},
|
||||
{
|
||||
"title": "Equipment",
|
||||
"route": "farmos_equipment_assets",
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ def includeme(config):
|
|||
config.include("wuttafarm.web.views.groups")
|
||||
config.include("wuttafarm.web.views.plants")
|
||||
config.include("wuttafarm.web.views.water")
|
||||
config.include("wuttafarm.web.views.compost")
|
||||
config.include("wuttafarm.web.views.logs")
|
||||
config.include("wuttafarm.web.views.logs_activity")
|
||||
config.include("wuttafarm.web.views.logs_harvest")
|
||||
|
|
|
|||
|
|
@ -71,6 +71,18 @@ class AssetMasterView(WuttaFarmMasterView):
|
|||
"groups": "Group Membership",
|
||||
}
|
||||
|
||||
grid_columns = [
|
||||
"thumbnail",
|
||||
"drupal_id",
|
||||
"asset_name",
|
||||
"groups",
|
||||
"asset_type",
|
||||
"parents",
|
||||
"owners",
|
||||
"locations",
|
||||
"archived",
|
||||
]
|
||||
|
||||
sort_defaults = "asset_name"
|
||||
|
||||
filter_defaults = {
|
||||
|
|
|
|||
62
src/wuttafarm/web/views/compost.py
Normal file
62
src/wuttafarm/web/views/compost.py
Normal 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)
|
||||
|
|
@ -42,6 +42,7 @@ def includeme(config):
|
|||
config.include("wuttafarm.web.views.farmos.groups")
|
||||
config.include("wuttafarm.web.views.farmos.plants")
|
||||
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.logs_activity")
|
||||
config.include("wuttafarm.web.views.farmos.logs_harvest")
|
||||
|
|
|
|||
|
|
@ -327,6 +327,12 @@ class AssetMasterView(FarmOSMasterView):
|
|||
# archived
|
||||
f.set_node("archived", colander.Boolean())
|
||||
|
||||
# drupal_id
|
||||
if self.creating:
|
||||
f.remove("drupal_id")
|
||||
else:
|
||||
f.set_readonly("drupal_id")
|
||||
|
||||
# thumbnail_url
|
||||
if self.creating or self.editing:
|
||||
f.remove("thumbnail_url")
|
||||
|
|
|
|||
79
src/wuttafarm/web/views/farmos/compost.py
Normal file
79
src/wuttafarm/web/views/farmos/compost.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue