feat: show quantities when viewing log
This commit is contained in:
parent
7890b18568
commit
32d23a7073
3 changed files with 57 additions and 4 deletions
|
|
@ -381,6 +381,23 @@ class LogAssetRefs(WuttaSet):
|
|||
return LogAssetRefsWidget(self.request, **kwargs)
|
||||
|
||||
|
||||
class LogQuantityRefs(WuttaSet):
|
||||
"""
|
||||
Schema type for Quantities field (on a Log record)
|
||||
"""
|
||||
|
||||
def serialize(self, node, appstruct):
|
||||
if not appstruct:
|
||||
return colander.null
|
||||
|
||||
return {qty.uuid for qty in appstruct}
|
||||
|
||||
def widget_maker(self, **kwargs):
|
||||
from wuttafarm.web.forms.widgets import LogQuantityRefsWidget
|
||||
|
||||
return LogQuantityRefsWidget(self.request, **kwargs)
|
||||
|
||||
|
||||
class LogOwnerRefs(WuttaSet):
|
||||
"""
|
||||
Schema type for Owners field (on a Log record)
|
||||
|
|
|
|||
|
|
@ -454,6 +454,38 @@ class LogAssetRefsWidget(WuttaCheckboxChoiceWidget):
|
|||
return super().serialize(field, cstruct, **kw)
|
||||
|
||||
|
||||
class LogQuantityRefsWidget(WuttaCheckboxChoiceWidget):
|
||||
"""
|
||||
Widget for Quantities field (on a Log record)
|
||||
"""
|
||||
|
||||
def serialize(self, field, cstruct, **kw):
|
||||
""" """
|
||||
model = self.app.model
|
||||
session = Session()
|
||||
|
||||
readonly = kw.get("readonly", self.readonly)
|
||||
if readonly:
|
||||
quantities = []
|
||||
for uuid in cstruct or []:
|
||||
qty = session.get(model.Quantity, uuid)
|
||||
quantities.append(
|
||||
HTML.tag(
|
||||
"li",
|
||||
c=tags.link_to(
|
||||
qty.render_as_text(self.config),
|
||||
# TODO
|
||||
self.request.route_url(
|
||||
"quantities_standard.view", uuid=qty.uuid
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
return HTML.tag("ul", c=quantities)
|
||||
|
||||
return super().serialize(field, cstruct, **kw)
|
||||
|
||||
|
||||
class LogOwnerRefsWidget(WuttaCheckboxChoiceWidget):
|
||||
"""
|
||||
Widget for Owners field (on a Log record)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ from wuttaweb.forms.widgets import WuttaDateTimeWidget
|
|||
|
||||
from wuttafarm.web.views import WuttaFarmMasterView
|
||||
from wuttafarm.db.model import LogType, Log
|
||||
from wuttafarm.web.forms.schema import LogAssetRefs, LogOwnerRefs
|
||||
from wuttafarm.web.forms.schema import LogAssetRefs, LogQuantityRefs, LogOwnerRefs
|
||||
from wuttafarm.util import get_log_type_enum
|
||||
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ class LogMasterView(WuttaFarmMasterView):
|
|||
"assets",
|
||||
"groups",
|
||||
"locations",
|
||||
"quantity",
|
||||
"quantities",
|
||||
"notes",
|
||||
"status",
|
||||
"log_type",
|
||||
|
|
@ -290,9 +290,13 @@ class LogMasterView(WuttaFarmMasterView):
|
|||
)
|
||||
f.set_readonly("log_type")
|
||||
|
||||
# quantity
|
||||
# quantities
|
||||
if self.creating or self.editing:
|
||||
f.remove("quantity") # TODO: need to support this
|
||||
f.remove("quantities") # TODO: need to support this
|
||||
else:
|
||||
f.set_node("quantities", LogQuantityRefs(self.request))
|
||||
# nb. must explicity declare value for non-standard field
|
||||
f.set_default("quantities", log.quantities)
|
||||
|
||||
# notes
|
||||
f.set_widget("notes", "notes")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue