Exemple #1
0
	def _generate_datetime_select(self, element, attribs, arrays, values, names):
		def _create_option(index, v, option_data):
			tag = tags.option(value=index)[option_data[index]]
			if(index == v):
				tag(selected=None)
			return tag
		
		output = ''
		for index in range(len(arrays)):
			selected_item = arrays[index].index(values[index])
			attribs['name'] = '%s[%s]' % (element.get_element_name(), names[index])
			output += tags.select(**attribs)[[
				tags.option(value='')['Select...']
			]+[
				_create_option(i, selected_item, arrays[index]) for i in range(len(arrays[index]))
			]]
		
		return output
Exemple #2
0
	def theme_select(self, form_id, element):
		attribs = element.attr('attributes', {})
		attribs['name'] = element.get_element_name()
		if(element.attr('multiple', False)):
			attribs['size'] = element.attr('size', 5)
			attribs['multiple'] = None
		else:
			attribs['size'] = element.attr('size', 1)
		
		value = element.attr('value', 1)
		if not(isinstance(value, (list, tuple))):
			value = [value]
		value = map(str, value)
		
		comparator = element.attr('sort', cmp)
		
		options_clone = copy.copy(element.attr('options', []))
		option_keys, option_data = self._mangle_option_data(options_clone, comparator)
		
		if(attribs['size'] == 1):
			option_keys.insert(0, '')
			option_data[''] = element.attr('null_text', 'Select...')
			del attribs['size']
		
		def _create_option(k):
			tag = tags.option(value=k)[option_data[k]]
			if(str(k) in value):
				tag(selected=None)
			return tag
		
		options = map(_create_option, option_keys)
		
		if not(options):
			options = ' '
		
		return tags.select(**attribs)[options]
Exemple #3
0
	def test_longer_select(self):
		option = tags.option(value="some-value")['some-label']
		option2 = tags.option(value="some-other-value")['some-other-label']
		tag = tags.select(name="select_field")[(option, option2)]
		expected = '<select name="select_field"><option value="some-value">some-label</option><option value="some-other-value">some-other-label</option></select>'
		self.assertEqual(str(tag), expected, "Got '%s' instead of '%s'" % (str(tag), expected))
Exemple #4
0
	def test_select_trick2(self):
		options = ['some-label', 'other-label']
		opt_tags = map(lambda(item): tags.option(value=item[0])[item[1]], [(i,options[i]) for i in range(len(options))])
		tag = tags.select(name="select_field")[opt_tags]
		expected = '<select name="select_field"><option value="0">some-label</option><option value="1">other-label</option></select>'
		self.assertEqual(str(tag), expected, "Got '%s' instead of '%s'" % (str(tag), expected))
Exemple #5
0
	def test_select_trick(self):
		options = {1:'some-label', 2:'other-label'}
		opt_tags = map(lambda(item): tags.option(value=item[0])[item[1]], options.items())
		tag = tags.select(name="select_field")[opt_tags]
		expected = '<select name="select_field"><option value="1">some-label</option><option value="2">other-label</option></select>'
		self.assertEqual(str(tag), expected, "Got '%s' instead of '%s'" % (str(tag), expected))