web/formwidgets.py
changeset 2519 ac1a869e1e93
parent 2518 38c28ee40138
child 2522 562f5dcf2345
equal deleted inserted replaced
2518:38c28ee40138 2519:ac1a869e1e93
   222     vocabulary_widget = True
   222     vocabulary_widget = True
   223 
   223 
   224     def render(self, form, field):
   224     def render(self, form, field):
   225         name, curvalues, attrs = self._render_attrs(form, field)
   225         name, curvalues, attrs = self._render_attrs(form, field)
   226         domid = attrs.pop('id', None)
   226         domid = attrs.pop('id', None)
   227         sep = attrs.pop('separator', u'<br/>')
   227         sep = attrs.pop('separator', u'<br/>\n')
   228         options = []
   228         options = []
   229         for i, option in enumerate(field.vocabulary(form)):
   229         for i, option in enumerate(field.vocabulary(form)):
   230             try:
   230             try:
   231                 label, value, oattrs = option
   231                 label, value, oattrs = option
   232             except ValueError:
   232             except ValueError:
   237             if i == 0 and domid is not None:
   237             if i == 0 and domid is not None:
   238                 iattrs.setdefault('id', domid)
   238                 iattrs.setdefault('id', domid)
   239             if value in curvalues:
   239             if value in curvalues:
   240                 iattrs['checked'] = u'checked'
   240                 iattrs['checked'] = u'checked'
   241             tag = tags.input(name=name, type=self.type, value=value, **iattrs)
   241             tag = tags.input(name=name, type=self.type, value=value, **iattrs)
   242             options.append(tag + label + sep)
   242             options.append(tag + label)
   243         return '\n'.join(options)
   243         return sep.join(options)
   244 
   244 
   245 
   245 
   246 class Radio(CheckBox):
   246 class Radio(CheckBox):
   247     """<input type='radio'>, for field having a specific vocabulary. One
   247     """<input type='radio'>, for field having a specific vocabulary. One
   248     input will be generated for each possible value.
   248     input will be generated for each possible value.