fix: add Notes schema type
this is because the dict we get from (normalizing the) farmOS API record will have e.g. `notes=None` but that winds up rendering as "None" instead of empty string - so we use colander.null value in such cases so empty string is rendered
This commit is contained in:
parent
331543d74b
commit
b9ab27523f
2 changed files with 25 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ import json
|
|||
import colander
|
||||
|
||||
from wuttaweb.forms.schema import ObjectRef, WuttaSet
|
||||
from wuttaweb.forms.widgets import NotesWidget
|
||||
|
||||
|
||||
class AnimalTypeRef(ObjectRef):
|
||||
|
|
@ -380,3 +381,25 @@ class LogAssetRefs(WuttaSet):
|
|||
from wuttafarm.web.forms.widgets import LogAssetRefsWidget
|
||||
|
||||
return LogAssetRefsWidget(self.request, **kwargs)
|
||||
|
||||
|
||||
class Notes(colander.String):
|
||||
"""
|
||||
Custom schema type for "note" fields.
|
||||
"""
|
||||
|
||||
def serialize(self, node, appstruct):
|
||||
""" """
|
||||
if not appstruct:
|
||||
return colander.null
|
||||
|
||||
return super().serialize(node, appstruct)
|
||||
|
||||
def widget_maker(self, **kwargs):
|
||||
"""
|
||||
Construct a default widget for the field.
|
||||
|
||||
:returns: Instance of
|
||||
:class:`~wuttaweb.forms.widgets.NotesWidget`.
|
||||
"""
|
||||
return NotesWidget(**kwargs)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ View for farmOS Harvest Logs
|
|||
|
||||
from webhelpers2.html import tags
|
||||
|
||||
from wuttaweb.forms.schema import WuttaDateTime, WuttaDictEnum, Notes
|
||||
from wuttaweb.forms.schema import WuttaDateTime, WuttaDictEnum
|
||||
from wuttaweb.forms.widgets import WuttaDateTimeWidget
|
||||
|
||||
from wuttafarm.web.views.farmos import FarmOSMasterView
|
||||
|
|
@ -42,6 +42,7 @@ from wuttafarm.web.forms.schema import (
|
|||
FarmOSAssetRefs,
|
||||
FarmOSRefs,
|
||||
LogQuick,
|
||||
Notes,
|
||||
)
|
||||
from wuttafarm.web.util import render_quantity_objects
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue