from colander import Mapping, SchemaNode from deform import widget from deform.widget import MappingWidget, SequenceWidget registry = widget.default_resource_registry registry.set_js_resources( 'magicsuggest', None, 'c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.js') registry.set_css_resources( 'magicsuggest', None, 'c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.css') # temporary workaround for https://github.com/Pylons/deform/pull/369 widget.DateTimeInputWidget._pstruct_schema = SchemaNode( # pylint: disable=protected-access Mapping(), SchemaNode(widget._StrippedString(), name='date'), # pylint: disable=protected-access SchemaNode(widget._StrippedString(), name='time'), # pylint: disable=protected-access SchemaNode(widget._StrippedString(), name='date_submit', missing=''), # pylint: disable=protected-access SchemaNode(widget._StrippedString(), name='time_submit', missing='') # pylint: disable=protected-access ) class ChildWidget(MappingWidget): template = 'child' def serialize(self, field, cstruct, **kw): from c2cgeoportal_commons.models.main import TreeItem if cstruct['treeitem_id'] == colander.null: kw['treeitem'] = TreeItem() else:
from colander import Mapping, SchemaNode from deform import widget from deform.widget import MappingWidget, SequenceWidget registry = widget.default_resource_registry registry.set_js_resources( "magicsuggest", None, "c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.js") registry.set_css_resources( "magicsuggest", None, "c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.css") # temporary workaround for https://github.com/Pylons/deform/pull/369 widget.DateTimeInputWidget._pstruct_schema = SchemaNode( # pylint: disable=protected-access Mapping(), SchemaNode(widget._StrippedString(), name="date"), # pylint: disable=protected-access SchemaNode(widget._StrippedString(), name="time"), # pylint: disable=protected-access SchemaNode(widget._StrippedString(), name="date_submit", missing=""), # pylint: disable=protected-access SchemaNode(widget._StrippedString(), name="time_submit", missing=""), # pylint: disable=protected-access ) class ChildWidget(MappingWidget): template = "child" def serialize(self, field, cstruct, **kw): from c2cgeoportal_commons.models.main import TreeItem # pylint: disable=import-outside-toplevel if cstruct["treeitem_id"] == colander.null: kw["treeitem"] = TreeItem()
from colander import Mapping, SchemaNode from deform import widget from deform.widget import MappingWidget, SequenceWidget registry = widget.default_resource_registry registry.set_js_resources( 'magicsuggest', None, 'c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.js') registry.set_css_resources( 'magicsuggest', None, 'c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.css') # temporary workaround for https://github.com/Pylons/deform/pull/369 widget.DateTimeInputWidget._pstruct_schema = SchemaNode( # pylint: disable=W0212 Mapping(), SchemaNode(widget._StrippedString(), name='date'), # pylint: disable=W0212 SchemaNode(widget._StrippedString(), name='time'), # pylint: disable=W0212 SchemaNode(widget._StrippedString(), name='date_submit', missing=''), # pylint: disable=W0212 SchemaNode(widget._StrippedString(), name='time_submit', missing='') # pylint: disable=W0212 ) class ChildWidget(MappingWidget): template = 'child' def serialize(self, field, cstruct, **kw): from c2cgeoportal_commons.models.main import TreeItem if cstruct['treeitem_id'] == colander.null: kw['treeitem'] = TreeItem() else:
class BBoxWidget(Widget): """ Renders a BoundingBox Widget. **Attributes/Arguments** template The template name used to render the input widget. Default: ``bbox``. readonly_template The template name used to render the widget in read-only mode. Default: ``readonly/bbox``. """ template = 'bbox' readonly_template = 'readonly/bbox' _pstruct_schema = SchemaNode( Mapping(), SchemaNode(_StrippedString(), name='minx'), SchemaNode(_StrippedString(), name='miny'), SchemaNode(_StrippedString(), name='maxx'), SchemaNode(_StrippedString(), name='maxy')) def serialize(self, field, cstruct, **kw): if cstruct is null: minx = '-180' miny = '-90' maxx = '180' maxy = '90' else: minx, miny, maxx, maxy = cstruct.split(',', 3) kw.setdefault('minx', minx) kw.setdefault('miny', miny) kw.setdefault('maxx', maxx) kw.setdefault('maxy', maxy) # readonly = kw.get('readonly', self.readonly) # TODO: add readonly template readonly = False template = readonly and self.readonly_template or self.template values = self.get_template_values(field, cstruct, kw) return field.renderer(template, **values) def deserialize(self, field, pstruct): if pstruct is null: return null else: try: validated = self._pstruct_schema.deserialize(pstruct) except Invalid as exc: raise Invalid(field.schema, text_("Invalid pstruct: %s" % exc)) minx = validated['minx'] miny = validated['miny'] maxx = validated['maxx'] maxy = validated['maxy'] if not minx and not minx and not maxx and not maxy: return null result = ','.join([minx, miny, maxx, maxy]) if not minx or not miny or not maxx or not maxy: raise Invalid(field.schema, 'Incomplete bbox', result) return result