Esempio n. 1
0
    def render(self, value, vars, attributes):
        options = get_options(attributes.get("options", "[options]"))
        if isinstance(value, (list, tuple)):
            values = [_str(v) for v in value]
        else:
            values = [_str(value)]
        options = [(k, v) for k, v in options if k != '']
        opts = []
        cols = attributes.get('cols', self.DEFAULT_CONFIGURE["cols"])
        totals = len(options)
        mods = totals % cols
        rows = totals / cols
        if mods:
            rows += 1

        for r_index in range(rows):
            tds = []
            for k, v in options[r_index*cols:(r_index+1)*cols]:
                if  k in values:
                    r_value = k
                else:
                    r_value = []
                tds.append(TD(INPUT(_type='radio',
                         _name=attributes["fieldname"],
                         _value=k, value=r_value), v))
            opts.append(TR(tds))
        return TABLE(*opts)
Esempio n. 2
0
    def _postprocessing(self):
        component_list = []
        for c in self.components:
            if isinstance(c, OPTGROUP):
                component_list.append(c.components)
            elif isinstance(c, (list, tuple)):
                if len(c) == 1:
                    d = [c[0], c[0]]
                elif len(c) >= 2:
                    d = [c[0], c[1]]
                else:
                    continue
                component_list.append(OPTION(d[1], _value=str(d[0])))
            else:
                component_list.append(OPTION(c, _value=str(c)))
        options = itertools.chain(*component_list)

        value = self['value']
        if not value is None:
            if isinstance(value,(list,tuple)):
                values = [_str(item) for item in value]
            else:
                values = [_str(value)]
            for c in options: # my patch
                if value and _str(c['_value']) in values:
                    c['_selected'] = 'selected'
                else:
                    c['_selected'] = None
Esempio n. 3
0
 def _fixup(self):
     components = []
     for c in self.components:
         if isinstance(c, (OPTION, OPTGROUP)):
             components.append(c)
         elif isinstance(c, (list, tuple)):
             if len(c) == 1:
                 d = [c[0], c[0]]
             elif len(c) >= 2:
                 d = [c[0], c[1]]
             else:
                 continue
             components.append(OPTION(d[1], _value=_str(d[0])))
         else:
             components.append(OPTION(c, _value=_str(c)))
     self.components = components
Esempio n. 4
0
 def _postprocessing(self):
     t = self['_type']
     if not t:
         t = self['_type'] = 'text'
     t = t.lower()
     value = self['value']
     if self['_value'] == None:
         _value = None
     else:
         _value = _str(self['_value'])
     if t == 'checkbox':
         if not _value:
             _value = self['_value'] = 'on'
         if not value:
             value = []
         else:
             value = [_value]
         self['_checked'] = (_value in value) and 'checked' or None
     elif t == 'radio':
         if str(value) == str(_value):
             self['_checked'] = 'checked'
         else:
             self['_checked'] = None
     elif t == 'text' or t == 'hidden':
         if value != None:
             self['_value'] = value
         else:
             self['value'] = _value