Example #1
0
    def line(self, fields, n):
        from uliweb.core.html import Tag

        _x = 0
        for _f in fields:
            if isinstance(_f, (str, unicode)):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get('colspan', 1)
            else:
                raise Exception('Colume definition is not right, only support string or dict')

        tr = Tag('tr')
        with tr:
            for x in fields:
                _span = n / _x
                if isinstance(x, (str, unicode)):
                    f = self.get_field(x)
                elif isinstance(x, dict):
                    f = self.get_field(x['name'])
                    _span = _span * x.get('colspan', 1)

                with tr.td(colspan=_span, width='%d%%' % (100*_span/n,), _class='view-cell'):
                    with tr.div(_class='table-field-row', id='view_field_{}'.format(f['name'])):
                        with tr.label(_class='table-field-label'):
                            tr << f['label'] + ':'
                        if isinstance(x, dict) and x.get('break'):
                            tr << '<br/>'
                        with tr.div(_class='table-field-col'):
                            tr << f['display']

        return tr
Example #2
0
 def line(self, obj, label, input, help_string='', error=None):
     _class = self.get_class(obj)
     if error:
         _class = _class + ' error'
     
     if self.get_widget_name(obj) == 'RadioSelect':
         obj.build = YamlRadioSelect
         fs = Tag('fieldset')
         fs << Tag('legend', label)
         fs << input
         return fs
     else:
         div = Tag('div', _class=_class, id='div_'+obj.id)
         with div:
             if error:
                 div.strong(error, _class="message")
             if self.get_widget_name(obj) == 'Checkbox':
                 div << input
                 div << label
                 div << help_string
             else:
                 div << label
                 div << help_string
                 div << input
         return div
Example #3
0
    def line(self, fields, n):
        _x = 0
        for _f in fields:
            if isinstance(_f, string_types):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get('colspan', 1)
            else:
                raise Exception(
                    'Colume definition is not right, only support string or dict'
                )

        tr = Tag('tr', newline=True)
        with tr:
            for x in fields:
                _span = int(n / _x)
                if isinstance(x, string_types):
                    name = x
                elif isinstance(x, dict):
                    name = x['name']
                    _span = _span * x.get('colspan', 1)

                f = getattr(self.form, name)
                obj = self.form.fields[name]

                #process hidden field
                if self.is_hidden(obj):
                    #tr << f
                    continue

                _class = "control-group"
                if f.error:
                    _class = _class + ' error'

                with tr.td(colspan=_span,
                           width='%d%%' % (100 * _span / n, ),
                           valign='top'):
                    with tr.Div(_class=_class, id='div_' + obj.id):
                        if self.get_widget_name(obj) == 'Checkbox':
                            tr << "&nbsp"
                        else:
                            if self.label_fix:
                                tr << f.field.get_label(_class='label_fix')
                            else:
                                tr << f.get_label(_class='control-label')

                        div = Div(_class='controls')
                        with div:
                            if self.get_widget_name(obj) == 'Checkbox':
                                div << f
                                div << f.label
                            else:
                                div << f
                            div << Div(_class="help help-block",
                                       _value=f.help_string or '')
                            if f.error:
                                div << Div(_class="message help-block",
                                           _value=f.error)
                        tr << str(div)
        return tr
Example #4
0
 def line(self, obj, label, input, help_string='', error=None):
     div = Div()
     div << label
     div << input
     if error:
         div << Tag('span', error, _class='error')
     div << Tag('br/')
     return div
Example #5
0
    def line(self, fields, n):
        _x = 0
        for _f in fields:
            if isinstance(_f, (str, unicode)):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get('colspan', 1)
            else:
                raise Exception, 'Colume definition is not right, only support string or dict'
            
        tr = Tag('tr', newline=True)
        with tr:
            for x in fields:
                _span = n / _x
                if isinstance(x, (str, unicode)):
                    name = x
                elif isinstance(x, dict):
                    name = x['name']
                    _span = _span * x.get('colspan', 1)

                f = getattr(self.form, name)
                obj = self.form.fields[name]
                
                #process hidden field
                if self.is_hidden(obj):
                    #tr << f
                    continue
                
                _class = "control-group"
                if f.error:
                    _class = _class + ' error'
                
                with tr.td(colspan=_span, width='%d%%' % (100*_span/n,), valign='top'):
                    with tr.Div(_class=_class, id='div_'+obj.id):
                        if self.get_widget_name(obj) == 'Checkbox':
                            tr << "&nbsp"
                        else:
                            if self.label_fix:
                                tr << f.field.get_label(_class='label_fix')
                            else:
                                tr << f.get_label(_class='control-label')                            
                            
                        div = Div(_class='controls')
                        with div:
                            if self.get_widget_name(obj) == 'Checkbox':
                                div << f
                                div << f.label
                            else:
                                div << f                    
                            div << Div(_class="help help-block", _value= f.help_string or '')
                            if f.error:
                                div << Div(_class="message help-block", _value=f.error)
                        tr << str(div)
        return tr
Example #6
0
    def line(self, fields, n):
        _x = 0
        for _f in fields:
            if isinstance(_f, (str, unicode)):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get('colspan', 1)
            else:
                raise Exception, 'Colume definition is not right, only support string or dict'

        tr = Tag('tr', newline=True)
        with tr:
            for x in fields:
                _span = n / _x
                if isinstance(x, (str, unicode)):
                    name = x
                elif isinstance(x, dict):
                    name = x['name']
                    _span = _span * x.get('colspan', 1)

                f = getattr(self.form, name)
                obj = self.form.fields[name]
                
                #process hidden field
                if self.is_hidden(obj):
                    tr << f
                    continue
                
                _class = self.get_class(obj)
                if f.error:
                    _class = _class + ' error'
                
                with tr.td(colspan=_span, width='%d%%' % (100*_span/n,), valign='top'):
                    with tr.Div(_class=_class, id='div_'+obj.id):
                        if f.error:
                            tr.strong(f.error, _class="message")
                        if self.get_widget_name(obj) == 'Checkbox':
                            tr << f
                            tr << f.label
                            tr << f.help_string or '&nbsp;'
                        else:
                            if self.label_fix:
                                tr << f.field.get_label(_class='field label_fix')
                            else:
                                tr << f.label
                            tr << f
                            tr << f.help_string or '&nbsp;'
                
        return tr
Example #7
0
    def do_field(self, indent, value, **kwargs):
        field_name = kwargs.pop('name')
        field = getattr(self.form, field_name)
        error = field.error
        obj = self.form.fields[field_name]
        help_string = kwargs.pop('help_string', None) or field.help_string
        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = obj.label
        if label:
            obj.label = label
            label_text = obj.get_label(_class='control-label')
        else:
            label_text = ''

        _class = self.get_class(obj) + " control-group"
        if label_text == '':
            _class = _class + " nolabel"
        if error:
            _class = _class + ' error'
        field.field.html_attrs.update(kwargs)
        if self.is_hidden(obj):
            return str(field)

        div_group = Tag('div', _class=_class, id='div_' + obj.id)
        with div_group:
            if self.get_widget_name(obj) == 'Checkbox':
                div_group << ""
            else:
                div_group << label_text

            div = Tag('div', _class='controls')
            with div:
                if self.get_widget_name(obj) == 'Checkbox':
                    div << '<label>' + str(field) + label + '</label>'


#                    div << label_text
                else:
                    div << field
                div << Tag('div', _class="help help-block", _value=help_string)
                if error:
                    div << Tag(
                        'div', _class="message help-block", _value=error)

            div_group << str(div)
        return indent * ' ' + str(div_group)
Example #8
0
    def line(self, fields, n):
        _x = 0
        for _f in fields:
            if isinstance(_f, (str, unicode)):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get("colspan", 1)
            else:
                raise Exception, "Colume definition is not right, only support string or dict"

        tr = Tag("tr")
        with tr:
            for x in fields:
                _span = n / _x
                if isinstance(x, (str, unicode)):
                    name = x
                elif isinstance(x, dict):
                    name = x["name"]
                    _span = _span * x.get("colspan", 1)

                f = getattr(self.form, name)
                obj = self.form.fields[name]
                _class = "control-group"
                if f.error:
                    _class = _class + " error"

                with tr.td(colspan=_span, width="%d%%" % (100 * _span / n,), valign="top"):
                    with tr.div(_class=_class, id="div_" + obj.id):
                        if self.get_widget_name(obj) == "Checkbox":
                            tr << "&nbsp"
                        else:
                            if self.label_fix:
                                tr << f.field.get_label(_class="field label_fix")
                            else:
                                tr << f.get_label(_class="control-label")

                        div = Tag("div", _class="controls")
                        with div:
                            if self.get_widget_name(obj) == "Checkbox":
                                div << f
                                div << f.label
                            else:
                                div << f
                            div << Tag("div", _class="help help-block", _value=f.help_string or "")
                            if f.error:
                                div << Tag("div", _class="message help-block", _value=f.error)
                        tr << str(div)
        return tr
Example #9
0
 def to_html(self):
     from itertools import groupby
     
     def _make(v, caption):
         v = safe_str(v)
         args = {'value': v}
         if isinstance(self.value, (tuple, list)) and v in [safe_str(x) for x in self.value]:
             args['selected'] = None
         elif v == safe_str(self.value):
             args['selected'] = None
         return str(Tag('option', safe_str(caption), **args))
         
     s = []
     #if the choices is 3-elements, then will do the group process
     group = False
     if self.choices:
         group = len(self.choices[0]) > 2
     if group:
         for k, g in groupby(self.choices, lambda x:x[0]):
             s.append(begin_tag('optgroup', label=k))
             for x in g:
                 s.append(_make(x[1], x[2]))
             s.append(end_tag('optgroup'))
             
     else:
         for v, caption in self.choices:
             s.append(_make(v, caption))
             
     args = self.kwargs.copy()
     if self.multiple:
         args['multiple'] = None
         args['size'] = self.size
     return str(Tag('select', '\n'.join(s), newline=True, **args))
Example #10
0
 def get_label(self, delimeter=True, label=None, **kwargs):
     if label is None:
         if self.label is None:
             label = capitalize(self.name)
         else:
             label = self.label
     if not label:
         return ''
     if delimeter and DEFAULT_LABEL_DELIMETER:
         label += DEFAULT_LABEL_DELIMETER
     if self.required and not self.static:
         if REQUIRED_CAPTION_AFTER:
             label += str(Tag('span', REQUIRED_CAPTION, _class='field_required'))
         else:
             label = str(Tag('span', REQUIRED_CAPTION, _class='field_required')) + label
     return str(Tag('label', label, _for=self.id, newline=False, **kwargs))
Example #11
0
 def _make(v, caption):
     v = safe_str(v)
     args = {'value': v}
     if isinstance(self.value, (tuple, list)) and v in [safe_str(x) for x in self.value]:
         args['selected'] = None
     elif v == safe_str(self.value):
         args['selected'] = None
     return str(Tag('option', safe_str(caption), **args))
Example #12
0
    def body(self):
        buf = Buf()

        if self.form.fieldset:
            form = buf << Tag('fieldset')
            if self.form.form_title:
                form << Tag('legend', self.form.form_title)
        else:
            form = buf

        for name, obj in self.form.fields_list:
            f = getattr(self.form, name)
            if self.is_hidden(obj):
                form << f
            else:
                form << self.line(obj, f.label, f, f.help_string, f.error)

        return str(buf)
Example #13
0
 def get_url(self, filename, query_para=None, **url_args):
     """
     Return <a href="filename" title="filename"> tag
     You should pass title and text to url_args, if not pass, then using filename
     """
     from uliweb.core.html import Tag
     
     title = url_args.pop('title', filename)
     text = url_args.pop('text', title)
     query_para = query_para or {}
     return str(Tag('a', title, href=self.get_href(filename, **query_para), **url_args))
Example #14
0
 def to_html(self):
     s = []
     for v, caption in self.choices:
         args = {'value' : v}
         kwargs = self.kwargs.copy()
         args['name'] = kwargs.pop('name')
         args['id'] = kwargs.pop('id')
         if v == self.value:
             args['checked'] = None
         r = str(Radio(**args))
         s.append(str(Tag('label', r+caption, **kwargs)))
     return '\n'.join(s)
Example #15
0
 def html(self):
     s = Buf()
     for v, caption in self.choices:
         args = {'value': v}
         id = args.setdefault('id', 'radio_%d' % self.get_id())
         args['name'] = self.kwargs.get('name')
         if v == self.value:
             args['checked'] = None
         div = Div(_class='type-check')
         div << Radio(**args)
         div << Tag('label', caption, _for=id)
         s << div
     return str(s)
Example #16
0
    def do_field(self, indent, value, **kwargs):
        field_name = kwargs['name']
        field = getattr(self.form, field_name)
        error = field.error
        obj = self.form.fields[field_name]
        help_string = kwargs.get('help_string', None) or field.help_string
        if 'label' in kwargs:
            label = kwargs['label']
        else:
            label = obj.label
        if label:
            obj.label = label
            label_text = obj.get_label(_class='field')
        else:
            label_text = ''

        _class = self.get_class(obj)
        if error:
            _class = _class + ' error'

        if self.is_hidden(obj):
            return str(field)

        div = Tag('div', _class=_class)
        with div:
            if error:
                div.strong(error, _class="message")
            if self.get_widget_name(obj) == 'Checkbox':
                div << '<label>' + str(field) + label + '</label>'
                #                div << label_text
                div << help_string
            else:
                div << label_text
                div << help_string
                div << field
        return indent * ' ' + str(div)
Example #17
0
 def do_field(self, indent, value, **kwargs):
     field_name = kwargs['name']
     field = getattr(self.form, field_name)
     error = field.error
     obj = self.form.fields[field_name]
     help_string = kwargs.get('help_string', None) or field.help_string
     if 'label' in kwargs:
         label = kwargs['label']
     else:
         label = obj.label
     if label:
         obj.label = label
         label_text = obj.get_label(_class='field')
     else:
         label_text = ''
     
     _class = self.get_class(obj)
     if error:
         _class = _class + ' error'
     
     if self.is_hidden(obj):
         return str(field)
     
     div = Tag('div', _class=_class)
     with div:
         if error:
             div.strong(error, _class="message")
         if self.get_widget_name(obj) == 'Checkbox':
             div << field
             div << label_text
             div << help_string
         else:
             div << label_text
             div << help_string
             div << field
     return indent*' ' + str(div)
Example #18
0
    def line(self, obj, label, input, help_string="", error=None):
        _class = self.get_class(obj)
        if error:
            _class = _class + " error"

        if self.get_widget_name(obj) == "RadioSelect":
            obj.build = YamlRadioSelect
            fs = Tag("fieldset")
            fs << input
            return fs
        else:
            div = Tag("div", _class=_class, id="div_" + obj.id)
            with div:
                if error:
                    div.strong(error, _class="message")
                if self.get_widget_name(obj) == "Checkbox":
                    div << input
                    div << label
                    div << help_string
                else:
                    div << label
                    div << help_string
                    div << input
            return div
Example #19
0
 def to_html(self):
     s = []
     for v, caption in self.choices:
         args = {'value' : v}
         kwargs = self.kwargs.copy()
         args['name'] = kwargs.pop('name')
         args['id'] = kwargs.pop('id')
         if isinstance(self.value, (tuple, list)):
             if v in self.value:
                 args['checked'] = None
         else:
             if v == self.value:
                 args['checked'] = None
         r = str(Checkbox(**args))
         s.append(str(Tag('label', r+caption, **kwargs)))
     return '\n'.join(s)
Example #20
0
 def line(self, obj, label, input, help_string='', error=None):
     
     _class = "control-group"
     if error:
         _class = _class + ' error'
     
     div_group = Div(_class=_class, id='div_'+obj.id, newline=True)
     with div_group: 
         div_group << input.get_label(_class='control-label')
         div = Div(_class='controls', newline=True)
         with div:
             div << input                    
             div << Tag('p', _class="help help-block", _value=help_string)
             if error:
                 div << Div(_class="message help-block", _value=error, newline=True)
                 
         div_group << str(div)
     return str(div_group)
Example #21
0
    def line(self, fields, n):
        _x = 0
        for _f in fields:
            if isinstance(_f, (str, unicode)):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get('colspan', 1)
            else:
                raise Exception, 'Colume definition is not right, only support string or dict'

        tr = Tag('tr', newline=True)
        with tr:
            for x in fields:
                _span = n / _x
                if isinstance(x, (str, unicode)):
                    name = x
                elif isinstance(x, dict):
                    name = x['name']
                    _span = _span * x.get('colspan', 1)

                f = getattr(self.form, name)
                obj = self.form.fields[name]

                #process hidden field
                if self.is_hidden(obj):
                    tr << f
                    continue

                _class = self.get_class(obj)
                if f.error:
                    _class = _class + ' error'

                with tr.td(colspan=_span,
                           width='%d%%' % (100 * _span / n, ),
                           valign='top'):
                    with tr.Div(_class=_class, id='div_' + obj.id):
                        if f.error:
                            tr.strong(f.error, _class="message")
                        if self.get_widget_name(obj) == 'Checkbox':
                            tr << f
                            tr << f.label
                            tr << f.help_string or '&nbsp;'
                        else:
                            if self.label_fix:
                                tr << f.field.get_label(
                                    _class='field label_fix')
                            else:
                                tr << f.label
                            tr << f
                            tr << f.help_string or '&nbsp;'

        return tr
Example #22
0
    def line(self, obj, label, input, help_string='', error=None):
        _class = self.get_class(obj)
        if error:
            _class = _class + ' error'

        if self.get_widget_name(obj) == 'RadioSelect':
            obj.build = YamlRadioSelect
            fs = Tag('fieldset')
            fs << input
            return fs
        else:
            div = Div(_class=_class, id='div_' + obj.id)
            with div:
                if error:
                    div.strong(error, _class="message")
                if self.get_widget_name(obj) == 'Checkbox':
                    div << input
                    div << label
                    div << help_string
                else:
                    div << label
                    div << help_string
                    div << input
            return div
    def line(self, fields, n):
        from uliweb.core.html import Tag

        _x = 0
        for _f in fields:
            if isinstance(_f, (str, unicode)):
                _x += 1
            elif isinstance(_f, dict):
                _x += _f.get('colspan', 1)
            else:
                raise Exception(
                    'Colume definition is not right, only support string or dict'
                )

        tr = Tag('tr')
        with tr:
            for x in fields:
                _span = n / _x
                if isinstance(x, (str, unicode)):
                    f = self.get_field(x)
                elif isinstance(x, dict):
                    f = self.get_field(x['name'])
                    _span = _span * x.get('colspan', 1)

                with tr.td(colspan=_span,
                           width='%d%%' % (100 * _span / n, ),
                           _class='view-cell'):
                    with tr.div(_class='table-field-row',
                                id='view_field_{}'.format(f['name'])):
                        with tr.label(_class='table-field-label'):
                            tr << f['label'] + ':'
                        if isinstance(x, dict) and x.get('break'):
                            tr << '<br/>'
                        with tr.div(_class='table-field-col'):
                            tr << f['display']

        return tr
Example #24
0
 def id(value, obj):
     from uliweb.core.html import Tag
     return str(Tag('a', ("%04d"%obj.id), href='/redbreast/workflow/%d' % obj.id))
Example #25
0
 def buttons_line(self, buttons):
     div = Tag("div", _class="line")
     with div:
         with div.div(_class="type-button"):
             div << buttons
     return str(div)
Example #26
0
 def key(value, obj):
     url = get_url('view', id=obj.id)
     return str(Tag('a', value, href="%s" % url))
Example #27
0
 def _buttons_line(self, buttons):
     div = Div()
     div << Tag('label', '&nbsp;', _class='field')
     div << buttons
     div << Tag('br/')
     return div
Example #28
0
 def to_html(self):
     args = self.kwargs.copy()
     args.setdefault('type', 'checkbox')
     return str(Tag('input', '', **args))
Example #29
0
 def to_html(self):
     args = self.kwargs.copy()
     args.setdefault('type', self.type)
     return str(Tag(self.tag, '', **args))
Example #30
0
 def to_html(self):
     args = self.kwargs.copy()
     value = args.pop('value', None)
     return str(
         Tag('img', value, **args)
     ) + "<span id='refresh' class='glyphicon glyphicon-refresh icon-refresh'></span>"
Example #31
0
def task_id(value, obj):
    from uliweb.core.html import Tag
    display = "%04d"%obj.id
    return str(Tag('a', display, href='/redbreast/task/%d' % obj.id))
Example #32
0
 def buttons_line(self, buttons):
     div = Tag('div', _class='line')
     with div:
         with div.div(_class='type-button'):
             div << buttons
     return str(div)
Example #33
0
 def do_button(self, indent, value, **kwargs):
     v = {'type': 'submit', 'class': 'btn btn-primary'}
     v.update(kwargs)
     return indent * ' ' + str(Tag('button', value, **v))
Example #34
0
 def do_button(self, indent, value, **kwargs):
     v = {'value': value, 'type': 'submit'}
     v.update(kwargs)
     return indent * ' ' + str(Tag('input', None, **v))
Example #35
0
 def to_html(self):
     args = self.kwargs.copy()
     value = args.pop('value', None)
     return str(Tag('button', value, **args))
Example #36
0
 def to_html(self):
     args = self.kwargs.copy()
     return str(Tag('textarea', self.value, **args))
Example #37
0
 def workflow(value, obj):
     from uliweb.core.html import Tag
     display = obj.workflow.spec_name + ("%04d"%obj.workflow.id)
     tag = Tag('a', display, href='/redbreast/workflow/%d' % obj.workflow.id)
     return str(tag) + ("&nbsp; <a class='btn btn-small btn-primary' href='/redbreast/tasks?workflow=%d'>Filter</a>" % obj.workflow.id)
Example #38
0
 def username(value, obj):
     return str(Tag('a', value, href='/users/view/%d' % obj.id))