def test_deserialize_empty(self): from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget widget = RelationCheckBoxListWidget(Tag, 'id', 'name') renderer = DummyRenderer() field = _get_field('tags', renderer) widget.populate(DBSession, None) result = widget.deserialize(field, null) self.assertEqual(result, [])
def test_deserialize(self): from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget widget = RelationCheckBoxListWidget(Tag, 'id', 'name') renderer = DummyRenderer() field = _get_field('tags', renderer) widget.populate(DBSession, None) result = widget.deserialize(field, ['1', '2']) self.assertEqual(result, [{'id': '1'}, {'id': '2'}])
def test_serialize_wrong_mapping(self): from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget widget = RelationCheckBoxListWidget( EmploymentStatus, 'id', 'name') renderer = DummyRenderer() field = _get_field('tags', renderer) widget.populate(DBSession, None) objs = [ {'bad_column': '101'}, {'bad_column': '102'}] with self.assertRaises(KeyError): widget.serialize(field, objs)
def test_serialize_empty(self): from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget widget = RelationCheckBoxListWidget(Tag, 'id', 'name') renderer = DummyRenderer() field = _get_field('tags', renderer) widget.populate(DBSession, None) widget.serialize(field, null) self.assertEqual(renderer.kw['values'], _convert_values(widget.values)) self.assertEqual(renderer.kw['cstruct'], []) first_value = renderer.kw['values'][0] self.assertEqual('0', first_value[0]) self.assertEqual('Tag A', first_value[1])
def roles_schema_node(name): return colander.SequenceSchema( GeoFormManyToManySchemaNode(Role), name=name, widget=RelationCheckBoxListWidget( Role, "id", "name", order_by="name", edit_url=lambda request, value: request.route_url( "c2cgeoform_item", table="roles", id=value), ), validator=manytomany_validator, missing=colander.drop, )
def test_serialize_wrong_mapping(self): from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget widget = RelationCheckBoxListWidget(EmploymentStatus, 'id', 'name') renderer = DummyRenderer() field = _get_field('tags', renderer) widget.populate(DBSession, None) objs = [{'bad_column': '101'}, {'bad_column': '102'}] with self.assertRaises(KeyError): widget.serialize(field, objs)
def roles_schema_node(prop: InstrumentedAttribute) -> colander.SequenceSchema: """Get the schema of all the items.""" return colander.SequenceSchema( GeoFormManyToManySchemaNode(Role), name=prop.key, title=prop.info["colanderalchemy"]["title"], description=prop.info["colanderalchemy"].get("description"), widget=RelationCheckBoxListWidget( Role, "id", "name", order_by="name", edit_url=lambda request, value: request.route_url( "c2cgeoform_item", table="roles", id=value), ), validator=manytomany_validator, missing=colander.drop, )
def create_widget(node, kw): del node return RelationCheckBoxListWidget( select([ Functionality.id, concat(Functionality.name, "=", Functionality.value).label("label"), ]).where( Functionality.name.in_([ f["name"] for f in available_functionalities_for( kw["request"].registry.settings, model) ])).alias("functionality_labels"), "id", "label", order_by="label", edit_url=lambda request, value: request.route_url( "c2cgeoform_item", table="functionalities", id=value), )
from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget from c2cgeoform.schema import GeoFormManyToManySchemaNode, manytomany_validator import colander from c2cgeoportal_admin import _ from c2cgeoportal_commons.models.main import RestrictionArea restrictionareas_schema_node = colander.SequenceSchema( GeoFormManyToManySchemaNode(RestrictionArea), name="restrictionareas", title=_("Restriction areas"), widget=RelationCheckBoxListWidget( RestrictionArea, "id", "name", order_by="name", edit_url=lambda request, value: request.route_url( "c2cgeoform_item", table="restriction_areas", id=value), ), validator=manytomany_validator, missing=colander.drop, )
from c2cgeoform.views.abstract_views import AbstractViews, ListField from ..models.c2cgeoform_demo import Excavation, Situation _list_field = partial(ListField, Excavation) base_schema = GeoFormSchemaNode(Excavation) base_schema.add_before( 'contact_persons', colander.SequenceSchema( GeoFormManyToManySchemaNode(Situation), name='situations', title='Situations', widget=RelationCheckBoxListWidget( Situation, 'id', 'name', order_by='name' ), validator=manytomany_validator ) ) base_schema.add_unique_validator(Excavation.reference_number, Excavation.hash) @view_defaults(match_param='table=excavations') class ExcavationViews(AbstractViews): _model = Excavation _base_schema = base_schema _id_field = 'hash'
import colander from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget from c2cgeoform.schema import ( GeoFormManyToManySchemaNode, manytomany_validator, ) from c2cgeoportal_commons.models.main import RestrictionArea from c2cgeoportal_admin import _ restrictionareas_schema_node = colander.SequenceSchema( GeoFormManyToManySchemaNode(RestrictionArea), name='restrictionareas', title=_('Restriction areas'), widget=RelationCheckBoxListWidget( RestrictionArea, 'id', 'name', order_by='name', edit_url=lambda request, value: request.route_url( 'c2cgeoform_item', table='restriction_areas', id=value, ) ), validator=manytomany_validator, missing=colander.drop )
from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget from c2cgeoform.schema import GeoFormManyToManySchemaNode, manytomany_validator import colander from c2cgeoportal_admin import _ from c2cgeoportal_commons.models.main import Interface interfaces_schema_node = colander.SequenceSchema( GeoFormManyToManySchemaNode(Interface), name="interfaces", title=_("Interfaces"), widget=RelationCheckBoxListWidget( Interface, "id", "name", order_by="name", edit_url=lambda request, value: request.route_url( "c2cgeoform_item", table="interfaces", id=value), ), validator=manytomany_validator, missing=colander.drop, )
# The views and conclusions contained in the software and documentation are those # of the authors and should not be interpreted as representing official policies, # either expressed or implied, of the FreeBSD Project. import colander from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget from c2cgeoform.schema import GeoFormManyToManySchemaNode, manytomany_validator from sqlalchemy import select from sqlalchemy.sql.functions import concat from c2cgeoportal_commons.models.main import Functionality functionalities_schema_node = colander.SequenceSchema( GeoFormManyToManySchemaNode(Functionality), name="functionalities", widget=RelationCheckBoxListWidget( select([Functionality.id, concat(Functionality.name, "=", Functionality.value).label("label")]).alias( "functionality_labels" ), "id", "label", order_by="label", edit_url=lambda request, value: request.route_url( "c2cgeoform_item", table="functionalities", id=value ), ), validator=manytomany_validator, missing=colander.drop, )
import colander from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget from c2cgeoform.schema import ( GeoFormManyToManySchemaNode, manytomany_validator, ) from c2cgeoportal_commons.models.main import Interface from c2cgeoportal_admin import _ interfaces_schema_node = colander.SequenceSchema( GeoFormManyToManySchemaNode(Interface), name='interfaces', title=_('Interfaces'), widget=RelationCheckBoxListWidget( Interface, 'id', 'name', order_by='name', edit_url=lambda request, value: request.route_url( 'c2cgeoform_item', table='interfaces', id=value ) ), validator=manytomany_validator, missing=colander.drop )