Esempio n. 1
0
    def to_widget(self):
        value = self.html_value
        field = self.field
        attrs = self.attrs

        if value:
            attrs['checked'] = None
        if self.inline:
            attrs.pop('class', None)
            _attrs = to_attrs(attrs)
            return '<label class="checkbox-inline"><input type="checkbox"%s></input> %s</label>' % (_attrs, self.field.label)
        else:
            attrs['class'] = 'checkbox'
            _attrs = to_attrs(attrs)
            return '<input type="%s" %s></input>' % (self.input_type, _attrs)
Esempio n. 2
0
    def assemble(self, links):
        from uliweb.core.html import to_attrs

        toplinks = ['']
        bottomlinks = ['']
        for _type, result in [('toplinks', toplinks),
                              ('bottomlinks', bottomlinks)]:
            for link, kw in links[_type].items():
                _link = kw.pop('link', link)
                if kw:
                    attrs = to_attrs(kw)
                else:
                    attrs = ''
                if link.endswith('.js'):
                    result.append(
                        '<script type="text/javascript" src="%s"%s></script>' %
                        (_link, attrs))
                elif link.endswith('.css'):
                    result.append(
                        '<link rel="stylesheet" type="text/css" href="%s"%s/>'
                        % (_link, attrs))
                else:
                    result.append(link)

        return {
            'toplinks': '\n'.join(toplinks),
            'bottomlinks': '\n'.join(bottomlinks)
        }
Esempio n. 3
0
    def to_widget(self):
        """
        """
        from uliweb.form.widgets import Select
        from uliweb.utils.common import safe_str

        field = self.field
        attrs = self.attrs

        buf = Buf()
        _value = [safe_str(x) for x in (self.form.data.get(field.name) or [])]
        for i, (v, title) in enumerate(field.get_choices()):
            _attrs = copy.deepcopy(attrs)
            if safe_str(v) in _value:
                _attrs['checked'] = None
            _attrs.pop('class', None)
            _attrs['id'] = _attrs['id'] + '_' + str(i+1)
            v_attrs = to_attrs(_attrs)
            if self.inline:
                buf << '<label class="%s-inline"><input type="%s" value="%s"%s> %s</label>' % (self.input_type,
                                            self.input_type, v, v_attrs, title)
            else:
                buf << '<div class="%s"><label><input type="%s" value="%s"%s>%s</label></div>' % (self.input_type,
                                            self.input_type, v, v_attrs, title)
        return str(buf)
Esempio n. 4
0
    def to_widget(self):
        d = {}
        _attrs = copy.deepcopy(self.attrs)
        d['class'] = _attrs.pop('class', '')
        d['attrs'] = to_attrs(_attrs)
        d['before'] = b = _attrs.pop('before', '')
        if b:
            d['before'] = '<span class="input-group-btn">%s</span>' % b
        d['after'] = a = _attrs.pop('after', '')
        if a:
            d['after'] = '<span class="input-group-btn">%s</span>' % a
        return """<div class="input-group %(class)s">
  %(before)s
  <input type="text" class="form-control" %(attrs)s>
  %(after)s
</div>""" % d
Esempio n. 5
0
    def assemble(self, links):
        from uliweb.core.html import to_attrs

        toplinks = ['']
        bottomlinks = ['']
        for _type, result in [('toplinks', toplinks), ('bottomlinks', bottomlinks)]:
            for link, kw in links[_type].items():
                _link = kw.pop('link', link)
                if kw:
                    attrs = to_attrs(kw)
                else:
                    attrs = ''
                if link.endswith('.js'):
                    result.append('<script type="text/javascript" src="%s"%s></script>' % (_link, attrs))
                elif link.endswith('.css'):
                    result.append('<link rel="stylesheet" type="text/css" href="%s"%s/>' % (_link, attrs))
                else:
                    result.append(link)

        return {'toplinks':'\n'.join(toplinks), 'bottomlinks':'\n'.join(bottomlinks)}
Esempio n. 6
0
 def to_widget(self):
     _attrs = to_attrs(self.attrs)
     return '<input type="%s" value="%s"%s></input>' % (self.input_type, safe_str(self.html_value), _attrs)
Esempio n. 7
0
 def to_widget(self):
     self.attrs['rows'] = getattr(self.field, 'rows', 4)
     _attrs = to_attrs(self.attrs)
     return '<textarea%s>%s</textarea>' % (_attrs, self.html_value)