def __init__(self, field, request): SelectWidget.__init__(self, 'relateditems') UberSelectionWidget.__init__(self, field, request) self.site = getSite() pprops = getToolByName(self.site, 'portal_properties') site_props = pprops.site_properties folder_types = site_props.getProperty( 'typesLinkToFolderContentsInFC', ['Folder', 'Large Plone Folder']) base_query = self.source.base_query.copy() query = base_query.copy() criterias = [] if 'portal_type' in query: criterias.append({ 'i': 'portal_type', 'o': 'plone.app.querystring.operation.selection.is', 'v': query['portal_type'] }) if 'is_folderish' in query: criterias.append({ 'i': 'is_folderish', 'o': 'plone.app.querystring.operation.selection.is', 'v': query['is_folderish'] }) self.pattern_options = { 'separator': self.separator, 'maximumSelectionSize': 1, 'folderTypes': folder_types, 'baseCriteria': criterias }
def test_defaults(self): from plone.app.widgets.base import SelectWidget widget = SelectWidget('example') self.assertEqual(widget.render(), '<select class="pat-example"> </select>') self.assertEqual(list(widget.options), []) self.assertEqual(widget.selected, None)
def test_defaults(self): from plone.app.widgets.base import SelectWidget widget = SelectWidget('example') self.assertEqual( widget.render(), '<select class="pat-example"> </select>') self.assertEqual(list(widget.options), []) self.assertEqual(widget.selected, None)
def test_defaults(self): from plone.app.widgets.base import SelectWidget widget = SelectWidget('example1', name='example2') self.assertEqual( widget.render(), u'<select class="pat-example1" name="example2"></select>') self.assertEqual(list(widget.items), []) self.assertEqual(widget.value, [])
def test_multiple(self): from plone.app.widgets.base import SelectWidget items = [ ('token1', 'value1'), ('token2', 'value2'), ('token3', 'value3'), ] widget = SelectWidget( 'example1', name='example2', value=['token2'], items=items, multiple=True, ) self.assertEqual( widget.render(), u'<select class="pat-example1" multiple="multiple" name="example2">' '<option value="token1">value1</option>' '<option value="token2" selected="selected">value2</option>' '<option value="token3">value3</option>' '</select>') self.assertEqual(list(widget.items), items) self.assertEqual(widget.value, ['token2']) widget.value = ['token1', 'token2'] self.assertEqual( widget.render(), u'<select class="pat-example1" multiple="multiple" name="example2">' '<option value="token1" selected="selected">value1</option>' '<option value="token2" selected="selected">value2</option>' '<option value="token3">value3</option>' '</select>') self.assertEqual(list(widget.items), items) self.assertEqual(widget.value, ['token1', 'token2']) del widget.value self.assertEqual( widget.render(), u'<select class="pat-example1" multiple="multiple" name="example2">' '<option value="token1">value1</option>' '<option value="token2">value2</option>' '<option value="token3">value3</option>' '</select>') del widget.items self.assertEqual( widget.render(), u'<select class="pat-example1" multiple="multiple" ' 'name="example2"></select>')
def test_set_options_and_selected(self): from plone.app.widgets.base import SelectWidget options = [ ('token1', 'value1'), ('token2', 'value2'), ('token3', 'value3'), ] widget = SelectWidget('example', selected='token2', options=options) self.assertEqual( widget.render(), '<select class="pat-example">' '<option value="token1">value1</option>' '<option value="token2" selected="selected">value2</option>' '<option value="token3">value3</option>' '</select>') self.assertEqual(list(widget.options), options) self.assertEqual(widget.selected, 'token2') widget.selected = 'token1' self.assertEqual( widget.render(), '<select class="pat-example">' '<option value="token1" selected="selected">value1</option>' '<option value="token2">value2</option>' '<option value="token3">value3</option>' '</select>') self.assertEqual(list(widget.options), options) self.assertEqual(widget.selected, 'token1') del widget.selected self.assertEqual( widget.render(), '<select class="pat-example">' '<option value="token1">value1</option>' '<option value="token2">value2</option>' '<option value="token3">value3</option>' '</select>') del widget.options self.assertEqual( widget.render(), '<select class="pat-example"/>')
def test_set_options_and_selected(self): from plone.app.widgets.base import SelectWidget options = [ ('token1', 'value1'), ('token2', 'value2'), ('token3', 'value3'), ] widget = SelectWidget('example', selected='token2', options=options) self.assertEqual( widget.render(), '<select class="pat-example">' '<option value="token1">value1</option>' '<option value="token2" selected="selected">value2</option>' '<option value="token3">value3</option>' '</select>') self.assertEqual(list(widget.options), options) self.assertEqual(widget.selected, 'token2') widget.selected = 'token1' self.assertEqual( widget.render(), '<select class="pat-example">' '<option value="token1" selected="selected">value1</option>' '<option value="token2">value2</option>' '<option value="token3">value3</option>' '</select>') self.assertEqual(list(widget.options), options) self.assertEqual(widget.selected, 'token1') del widget.selected self.assertEqual( widget.render(), '<select class="pat-example">' '<option value="token1">value1</option>' '<option value="token2">value2</option>' '<option value="token3">value3</option>' '</select>') del widget.options self.assertEqual(widget.render(), '<select class="pat-example"/>')