feat: show link to Log record when viewing Quantity
This commit is contained in:
parent
b2b49d93ae
commit
81fa22bbd8
4 changed files with 56 additions and 1 deletions
|
|
@ -376,6 +376,7 @@ class LogQuantity(model.Base):
|
||||||
quantity = orm.relationship(
|
quantity = orm.relationship(
|
||||||
"Quantity",
|
"Quantity",
|
||||||
foreign_keys=quantity_uuid,
|
foreign_keys=quantity_uuid,
|
||||||
|
back_populates="_log",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ Model definition for Quantities
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
|
|
||||||
from wuttjamaican.db import model
|
from wuttjamaican.db import model
|
||||||
|
|
||||||
|
|
@ -161,6 +162,25 @@ class Quantity(model.Base):
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_log = orm.relationship(
|
||||||
|
"LogQuantity",
|
||||||
|
uselist=False,
|
||||||
|
cascade="all, delete-orphan",
|
||||||
|
cascade_backrefs=False,
|
||||||
|
back_populates="quantity",
|
||||||
|
)
|
||||||
|
|
||||||
|
def make_log_quantity(log):
|
||||||
|
from wuttafarm.db.model import LogQuantity
|
||||||
|
|
||||||
|
return LogQuantity(log=log)
|
||||||
|
|
||||||
|
log = association_proxy(
|
||||||
|
"_log",
|
||||||
|
"log",
|
||||||
|
creator=make_log_quantity,
|
||||||
|
)
|
||||||
|
|
||||||
def render_as_text(self, config=None):
|
def render_as_text(self, config=None):
|
||||||
measure = str(self.measure or self.measure_id or "")
|
measure = str(self.measure or self.measure_id or "")
|
||||||
value = self.value_numerator / self.value_denominator
|
value = self.value_numerator / self.value_denominator
|
||||||
|
|
@ -202,6 +222,7 @@ def add_quantity_proxies(subclass):
|
||||||
Quantity.make_proxy(subclass, "quantity", "units_uuid")
|
Quantity.make_proxy(subclass, "quantity", "units_uuid")
|
||||||
Quantity.make_proxy(subclass, "quantity", "units")
|
Quantity.make_proxy(subclass, "quantity", "units")
|
||||||
Quantity.make_proxy(subclass, "quantity", "label")
|
Quantity.make_proxy(subclass, "quantity", "label")
|
||||||
|
Quantity.make_proxy(subclass, "quantity", "log")
|
||||||
|
|
||||||
|
|
||||||
class StandardQuantity(QuantityMixin, model.Base):
|
class StandardQuantity(QuantityMixin, model.Base):
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,31 @@ class LogQuick(WuttaSet):
|
||||||
return LogQuickWidget(**kwargs)
|
return LogQuickWidget(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class LogRef(ObjectRef):
|
||||||
|
"""
|
||||||
|
Custom schema type for a
|
||||||
|
:class:`~wuttafarm.db.model.log.Log` reference field.
|
||||||
|
|
||||||
|
This is a subclass of
|
||||||
|
:class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def model_class(self): # pylint: disable=empty-docstring
|
||||||
|
""" """
|
||||||
|
model = self.app.model
|
||||||
|
return model.Log
|
||||||
|
|
||||||
|
def sort_query(self, query): # pylint: disable=empty-docstring
|
||||||
|
""" """
|
||||||
|
return query.order_by(self.model_class.message)
|
||||||
|
|
||||||
|
def get_object_url(self, obj): # pylint: disable=empty-docstring
|
||||||
|
""" """
|
||||||
|
log = obj
|
||||||
|
return self.request.route_url(f"logs_{log.log_type}.view", uuid=log.uuid)
|
||||||
|
|
||||||
|
|
||||||
class FarmOSUnitRef(colander.SchemaType):
|
class FarmOSUnitRef(colander.SchemaType):
|
||||||
|
|
||||||
def serialize(self, node, appstruct):
|
def serialize(self, node, appstruct):
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ from wuttaweb.db import Session
|
||||||
|
|
||||||
from wuttafarm.web.views import WuttaFarmMasterView
|
from wuttafarm.web.views import WuttaFarmMasterView
|
||||||
from wuttafarm.db.model import QuantityType, Quantity, StandardQuantity
|
from wuttafarm.db.model import QuantityType, Quantity, StandardQuantity
|
||||||
from wuttafarm.web.forms.schema import UnitRef
|
from wuttafarm.web.forms.schema import UnitRef, LogRef
|
||||||
|
|
||||||
|
|
||||||
def get_quantity_type_enum(config):
|
def get_quantity_type_enum(config):
|
||||||
|
|
@ -119,6 +119,7 @@ class QuantityMasterView(WuttaFarmMasterView):
|
||||||
"value",
|
"value",
|
||||||
"units",
|
"units",
|
||||||
"label",
|
"label",
|
||||||
|
"log",
|
||||||
"drupal_id",
|
"drupal_id",
|
||||||
"farmos_uuid",
|
"farmos_uuid",
|
||||||
]
|
]
|
||||||
|
|
@ -231,6 +232,13 @@ class QuantityMasterView(WuttaFarmMasterView):
|
||||||
# TODO: ugh
|
# TODO: ugh
|
||||||
f.set_default("units", quantity.quantity.units)
|
f.set_default("units", quantity.quantity.units)
|
||||||
|
|
||||||
|
# log
|
||||||
|
if self.creating or self.editing:
|
||||||
|
f.remove("log")
|
||||||
|
else:
|
||||||
|
f.set_node("log", LogRef(self.request))
|
||||||
|
f.set_default("log", quantity.log)
|
||||||
|
|
||||||
def get_xref_buttons(self, quantity):
|
def get_xref_buttons(self, quantity):
|
||||||
buttons = super().get_xref_buttons(quantity)
|
buttons = super().get_xref_buttons(quantity)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue