def render(self, field, rargs): r_options = [Tag('option', opt[1], value=opt[0], selected=(opt[0] == field.cvalue)) for opt in self.options] rargs.setdefault('multiple', self.multiple) select = Tag('select', name=field.name, **rargs).add(r_options) return select.render()
""" # TODO pass class File(object): pass # TODO #attrs = attrs or dict() #if field.readonly: # does it make sense for file fields? # attrs['readonly'] = True #return html.input(name=field.name, type="file", **attrs) if __name__ == '__main__': class C(object): def __init__(self, val, text): self.val = val self.text = text options = [C(1, 'one'), C(2, 'two'), C(3, 'th"r<e>e')] current_val = 2 for x in range(100): select = Tag('select', multiple=True).add( [Tag('option', opt.text, value=opt.val, selected=opt.val == current_val) for opt in options] ) print(select.render())