Ejemplo n.º 1
0
def dynatree_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    if isinstance(value, (list, tuple)):
        value = '|'.join(value)    
    input_attrs = {
        'type': 'hidden',
        'value':  value,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input')    
    }
    result = tag('input', **input_attrs)
    source = attr_value('source', widget, data)
    if isinstance(source, dict):        
        source_type = 'local'
        ulid = cssid(widget, 'dynatree-source');
        result += build_inline_dynatree(source, fetch_value(widget, data), tag, 
                                        ulid=ulid)        
    elif isinstance(source, basestring):
        source_type = 'remote'  
        result += tag('div', source, 
                      **{'class': 'dynatree-source hiddenStructure'})
    else:
        raise ValueError, 'resulting source must be [o]dict or string'
    p_keys = ['selectMode', 'minExpandLevel', 'rootVisible', 'autoCollapse', 
              'checkbox']
    params = [('%s,%s' % (_, attr_value(_, widget, data))) \
                  for _ in parameter_keys]
    params.append('type,%s' % source_type)
    if source_type == 'local':
        params.append(('initId,%s' % ulid))
    result += tag('div', '|'.join(params), 
                  **{'class': 'dynatree-params hiddenStructure'})
    result += tag('div','', **{'class': 'yafowil-widget-dynatree-tree'})
    return tag('div', result, **{'class': 'yafowil-widget-dynatree'})
Ejemplo n.º 2
0
def expiration_edit_renderer(widget, data):
    tag = data.tag
    active_attrs = dict()
    active_attrs["id"] = cssid(widget, "checkbox")
    active_attrs["type"] = "checkbox"
    active_attrs["name"] = "%s.active" % widget.name
    active_attrs["value"] = "1"
    value = fetch_value(widget, data)
    if value == 8639913600:
        value = UNSET
    if value != 0:
        active_attrs["checked"] = "checked"
    active = tag("input", **active_attrs)
    until = tag("label", u"until")
    locale = widget.attrs["locale"]
    if callable(locale):
        locale = locale(widget, data)
    date = None
    time = widget.attrs["time"]
    if value in [0, UNSET]:
        date = ""
    else:
        date = datetime.fromtimestamp(value)
        if time:
            time = format_time(date)
        date = format_date(date, locale, widget.attrs["delimiter"])
    expires = render_datetime_input(widget, data, date, time)
    return tag("div", active + until + expires, class_="expiration-widget")
Ejemplo n.º 3
0
def expiration_edit_renderer(widget, data):
    tag = data.tag
    active_attrs = dict()
    active_attrs['id'] = cssid(widget, 'checkbox')
    active_attrs['type'] = 'checkbox'
    active_attrs['name'] = '%s.active' % widget.name
    active_attrs['value'] = '1'
    value = fetch_value(widget, data)
    if value == 8639913600:
        value = UNSET
    if value != 0:
        active_attrs['checked'] = 'checked'
    active = tag('input', **active_attrs)
    until = tag('label', u'until')
    locale = widget.attrs['locale']
    if callable(locale):
        locale = locale(widget, data)
    date = None
    time = widget.attrs['time']
    if value in [0, UNSET]:
        date = ''
    else:
        date = datetime.fromtimestamp(value)
        if time:
            time = format_time(date)
        date = format_date(date, locale, widget.attrs['delimiter'])
    expires = render_datetime_input(widget, data, date, time)
    return tag('div', active + until + expires, class_='expiration-widget')
Ejemplo n.º 4
0
def slider_edit_renderer(widget, data):
    value = fetch_value(widget, data)
    content = ''
    range = attr_value('range', widget, data)
    if range is True:
        lower_input_attrs = {
            'type': 'text',
            'name': '%s.lower' % widget.dottedpath,
            'id': cssid(widget, 'input-lower'),
            'style': 'display:none;',
            'class': 'lower_value',
            'value': value and value[0],
        }
        content += data.tag('input', **lower_input_attrs)
        upper_input_attrs = {
            'type': 'text',
            'name': '%s.upper' % widget.dottedpath,
            'id': cssid(widget, 'input-upper'),
            'style': 'display:none;',
            'class': 'upper_value',
            'value': value and value[1],
        }
        content += data.tag('input', **upper_input_attrs)
    else:
        input_attrs = {
            'type': 'text',
            'name': widget.dottedpath,
            'id': cssid(widget, 'input'),
            'style': 'display:none;',
            'class': 'slider_value',
            'value': value,
        }
        content += data.tag('input', **input_attrs)
    show_value = attr_value('show_value', widget, data)
    if show_value:
        unit = attr_value('unit', widget, data)
        if unit:
            content += data.tag('span', '%s: ' % unit, **{'class': 'unit'})
        if range is True:
            content += data.tag('span', value[0], **{'class': 'lower_value'})
            content += ' - '
            content += data.tag('span', value[1], **{'class': 'upper_value'})
        else:
            content += data.tag('span', value, **{'class': 'slider_value'})
    slider_attrs = {'class': 'slider'}
    if attr_value('orientation', widget, data) == 'vertical':
        height = attr_value('height', widget, data)
        if height:
            slider_attrs['style'] = 'height:%spx;' % height
    content += data.tag('div', ' ', **slider_attrs)
    wrapper_attrs = data_attrs_helper(widget, data, js_options)
    wrapper_attrs['class'] = cssclasses(widget, data)
    html_data = widget.attrs['data']
    data_keys = html_data.keys()
    for key in data_keys:
        if key in js_options:
            raise ValueError(u"Additional data dict contains reserved "
                             u"attribute name '%s'" % key)
        wrapper_attrs['data-%s' % key] = html_data[key]
    return data.tag('div', content, **wrapper_attrs)
Ejemplo n.º 5
0
def input_generic_renderer(widget, data):
    """Generic HTML ``input`` tag render.
    
    Properties:
    
    ``type``
        Type of this input tag.
    
    ``size``
        Size of input tag.
    
    ``disabled``
        Bool evaluating value, if evaluates to True, set disabled="disabled" on
        input tag.
    """
    tag = data.tag
    input_attrs = {
        'type': widget.attrs['type'],
        'value': fetch_value(widget, data),
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),    
        'class_': cssclasses(widget, data),
        'size': widget.attrs.get('size'),
        'disabled': bool(widget.attrs.get('disabled')) and 'disabled' or None,
        'placeholder': widget.attrs.get('placeholder'),
    }
    return tag('input', **input_attrs)
Ejemplo n.º 6
0
def textarea_renderer(widget, data):
    """Render text area.
    
    Properties:
    
    ``wrap``
        Wrap property of textarea element.
    
    ``cols``
        Number of characters.
    
    ``rows``
        Number of lines.
    
    ``readonly``
        Flag wether textarea is readonly.
    """
    tag = data.tag
    area_attrs = {
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),            
        'wrap': widget.attrs['wrap'],
        'cols': widget.attrs['cols'],
        'rows': widget.attrs['rows'],
        'readonly': widget.attrs['readonly'] and 'readonly',
        'placeholder': widget.attrs.get('placeholder'),
    }
    value = fetch_value(widget, data)
    if not value:
        value = ''
    return tag('textarea', value, **area_attrs)
Ejemplo n.º 7
0
def checkbox_edit_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    input_attrs = {
        'type': 'checkbox',
        'value': value,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),
        'disabled': bool(widget.attrs.get('disabled')) and 'disabled' or None,
    }
    if widget.attrs['checked'] is not None:
        if widget.attrs['checked']:
            input_attrs['checked'] = 'checked'
    else:
        input_attrs['checked'] = value and 'checked' or None
    if widget.attrs['format'] == 'bool':
        input_attrs['value'] = ''
    checkbox = tag('input', **input_attrs)
    input_attrs = {
        'type': 'hidden',
        'value': 'checkboxexists',
        'name_': "%s-exists" % widget.dottedpath,
        'id': cssid(widget, 'checkboxexists'),
    }
    exists_marker = tag('input', **input_attrs)
    return checkbox + exists_marker
Ejemplo n.º 8
0
def cron_display_renderer(widget, data):
    value = fetch_value(widget, data)
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % attr_value('class', widget, data)
    }
    return data.tag('div', data.tag('code', value), **attrs)
Ejemplo n.º 9
0
def checkbox_edit_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    input_attrs = {
        'type': 'checkbox',
        'value': value,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),    
        'class_': cssclasses(widget, data),
        'disabled': bool(widget.attrs.get('disabled')) and 'disabled' or None,            
    }
    if widget.attrs['checked'] is not None:
        if widget.attrs['checked']:
            input_attrs['checked'] = 'checked'
    else:
        input_attrs['checked'] = value and 'checked' or None
    if widget.attrs['format'] == 'bool':
        input_attrs['value'] = ''
    checkbox = tag('input', **input_attrs)
    input_attrs = {
        'type': 'hidden',
        'value':  'checkboxexists',
        'name_': "%s-exists" % widget.dottedpath,
        'id': cssid(widget, 'checkboxexists'),    
    }
    exists_marker = tag('input', **input_attrs)
    return checkbox + exists_marker
Ejemplo n.º 10
0
def expiration_edit_renderer(widget, data):
    tag = data.tag
    active_attrs = dict()
    active_attrs['id'] = cssid(widget, 'checkbox')
    active_attrs['type'] = 'checkbox'
    active_attrs['name'] = '%s.active' % widget.name
    active_attrs['value'] = '1'
    value = fetch_value(widget, data)
    if value == 8639913600:
        value = UNSET
    if value != 0:
        active_attrs['checked'] = 'checked'
    active = tag('input', **active_attrs)
    until = tag('label', u'until')
    locale = widget.attrs['locale']
    if callable(locale):
        locale = locale(widget, data)
    date = None
    time = widget.attrs['time']
    if value in [0, UNSET]:
        date = ''
    else:
        date = datetime.fromtimestamp(value)
        if time:
            time = format_time(date)
        date = format_date(date, locale, widget.attrs['delimiter'])
    expires = render_datetime_input(widget, data, date, time)
    return tag('div', active + until + expires, class_='expiration-widget')
Ejemplo n.º 11
0
def hidden_renderer(widget, data):
    hidden_attrs = {
        'type': 'hidden',
        'value':  fetch_value(widget, data),
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),    
        'class_': cssclasses(widget, data),    
    }
    return data.tag('input', **hidden_attrs)
Ejemplo n.º 12
0
def textarea_renderer(widget, data):
    """Renders text area.
    """
    tag = data.tag
    area_attrs = textarea_attributes(widget, data)
    value = fetch_value(widget, data)
    if value is None:
        value = ''
    return tag('textarea', value, **area_attrs)
Ejemplo n.º 13
0
def textarea_renderer(widget, data):
    """Renders text area.
    """
    tag = data.tag
    area_attrs = textarea_attributes(widget, data)
    value = fetch_value(widget, data)
    if value is None:
        value = ''
    return tag('textarea', value, **area_attrs)
Ejemplo n.º 14
0
    def test_fetch_value(self):
        dmarker = list()
        defaults = dict(default=dmarker)
        widget_no_return = Widget('blueprint_names_goes_here', [], [], [],
                                  'empty',
                                  defaults=defaults)  # noqa
        widget_with_value = Widget('blueprint_names_goes_here', [], [], [],
                                   'value',
                                   value_or_getter='withvalue',
                                   defaults=defaults)
        widget_with_default = Widget('blueprint_names_goes_here', [], [], [],
                                     'default',
                                     properties=dict(default='defaultvalue'),
                                     defaults=defaults)
        widget_with_both = Widget('blueprint_names_goes_here', [], [], [],
                                  'both',
                                  value_or_getter='valueboth',
                                  properties=dict(default='defaultboth'),
                                  defaults=defaults)
        data_empty = RuntimeData()
        data_filled = RuntimeData()
        data_filled.extracted = 'extractedvalue'

        data_empty.value = widget_no_return.getter
        self.assertTrue(fetch_value(widget_no_return, data_empty) is dmarker)

        data_filled.value = widget_no_return.getter
        self.assertEqual(fetch_value(widget_no_return, data_filled),
                         'extractedvalue')

        data_empty.value = widget_with_value.getter
        self.assertEqual(fetch_value(widget_with_value, data_empty),
                         'withvalue')

        data_filled.value = widget_with_value.getter
        self.assertEqual(fetch_value(widget_with_value, data_filled),
                         'extractedvalue')

        data_empty.value = widget_with_default.getter
        self.assertEqual(fetch_value(widget_with_default, data_empty),
                         'defaultvalue')

        data_filled.value = widget_with_default.getter
        self.assertEqual(fetch_value(widget_with_default, data_filled),
                         'extractedvalue')

        data_empty.value = widget_with_both.getter
        self.assertEqual(fetch_value(widget_with_both, data_empty),
                         'valueboth')

        data_filled.value = widget_with_both.getter
        self.assertEqual(fetch_value(widget_with_default, data_filled),
                         'extractedvalue')
Ejemplo n.º 15
0
def lines_renderer(widget, data):
    """Renders text area with list value as lines.
    """
    tag = data.tag
    area_attrs = textarea_attributes(widget, data)
    value = fetch_value(widget, data)
    if value is None:
        value = u''
    else:
        value = u'\n'.join(value)
    return tag('textarea', value, **area_attrs)
Ejemplo n.º 16
0
def lines_renderer(widget, data):
    """Renders text area with list value as lines.
    """
    tag = data.tag
    area_attrs = textarea_attributes(widget, data)
    value = fetch_value(widget, data)
    if value is None:
        value = u''
    else:
        value = u'\n'.join(value)
    return tag('textarea', value, **area_attrs)
Ejemplo n.º 17
0
def array_display_proxy_renderer(widget, data):
    """B/C. Use ``display_proxy`` widget attribute.
    """
    input_attrs = {
        'type': 'hidden',
        'value': fetch_value(widget, data),
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),
        'required': attr_value('required', widget, data) and 'required' or None
    }
    return data.tag('input', **input_attrs) + data.rendered
Ejemplo n.º 18
0
def reference_display_renderer(widget, data):
    if widget.attrs.get('multivalued'):
        return select_display_renderer(widget, data)
    value = fetch_value(widget, data)
    if value in [UNSET, u'', None]:
        value = u''
    else:
        value = value[1]
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    return data.tag('div', value, **attrs)
Ejemplo n.º 19
0
def select_display_renderer(widget, data):
    value = fetch_value(widget, data)
    if not widget.attrs['multivalued'] or not value:
        return generic_display_renderer(widget, data)
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    content = u''
    vocab = dict(vocabulary(widget.attrs.get('vocabulary', [])))
    for key in value:
        content += data.tag('li', vocab[key])
    return data.tag('ul', content, **attrs)
Ejemplo n.º 20
0
def dynatree_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    if isinstance(value, (list, tuple)):
        value = '|'.join(value)
    input_attrs = {
        'type': 'hidden',
        'value': value,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input')
    }
    result = tag('input', **input_attrs)
    source = attr_value('source', widget, data)
    if isinstance(source, dict):
        source_type = 'local'
        ulid = cssid(widget, 'dynatree-source').decode()
        result += build_inline_dynatree(source,
                                        fetch_value(widget, data),
                                        tag,
                                        ulid=ulid)
    elif isinstance(source, STR_TYPE):
        source_type = 'remote'
        result += tag('div', source,
                      **{'class': 'dynatree-source hiddenStructure'})
    else:
        raise ValueError('resulting source must be [o]dict or string')
    p_keys = [
        'selectMode', 'minExpandLevel', 'rootVisible', 'autoCollapse',
        'checkbox'
    ]
    params = [('%s,%s' % (_, attr_value(_, widget, data))) \
                  for _ in parameter_keys]
    params.append('type,%s' % source_type)
    if source_type == 'local':
        params.append(('initId,%s' % ulid))
    result += tag('div', '|'.join(params),
                  **{'class': 'dynatree-params hiddenStructure'})
    result += tag('div', '', **{'class': 'yafowil-widget-dynatree-tree'})
    return tag('div', result, **{'class': 'yafowil-widget-dynatree'})
Ejemplo n.º 21
0
def select_display_renderer(widget, data):
    value = fetch_value(widget, data)
    if not widget.attrs['multivalued'] or not value:
        return generic_display_renderer(widget, data)
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    content = u''
    vocab = dict(vocabulary(widget.attrs.get('vocabulary', [])))
    for key in value:
        content += data.tag('li', vocab[key])
    return data.tag('ul', content, **attrs)
Ejemplo n.º 22
0
def reference_display_renderer(widget, data):
    if widget.attrs.get('multivalued'):
        return select_display_renderer(widget, data)
    value = fetch_value(widget, data)
    if value in [UNSET, u'', None]:
        value = u''
    else:
        value = value[1]
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-{}'.format(widget.attrs['class'] or 'generic')
    }
    return data.tag('div', value, **attrs)
Ejemplo n.º 23
0
def select_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    if value is None:
        value = []
    if isinstance(value, basestring) or not hasattr(value, '__iter__'):
        value = [value]
    if widget.attrs['format'] == 'block':
        optiontags = []
        for key, term in vocabulary(widget.attrs.get('vocabulary', [])):
            attrs = {
                'selected': (key in value) and 'selected' or None,
                'value': key,
                'id': cssid(widget, 'input', key),
            }
            optiontags.append(tag('option', term, **attrs))
        select_attrs = {
            'name_': widget.dottedpath,
            'id': cssid(widget, 'input'),
            'class_': cssclasses(widget, data),                        
            'multiple': widget.attrs['multivalued'] and 'multiple' or None,
        }
        return tag('select', *optiontags, **select_attrs)
    else:
        tags = []
        for key, term in vocabulary(widget.attrs.get('vocabulary', [])):
            if widget.attrs['multivalued']:
                tagtype = 'checkbox'
            else:
                tagtype = 'radio'
            attrs = {
                'type': tagtype,
                'value':  key,
                'checked': (key in value) and 'checked' or None,
                'name_': widget.dottedpath,
                'id': cssid(widget, 'input', key),    
                'class_': cssclasses(widget, data),    
            }
            input = tag('input', **attrs)
            text = tag('span', term)
            tags.append(tag('div', input, text, 
                            **{'id': cssid(widget, 'radio', key)}))
        attrs = {
            'type': 'hidden',
            'value':  'exists',
            'name_': "%s-exists" % widget.dottedpath,
            'id': cssid(widget, 'exists'),    
        }
        exists_marker = tag('input', **attrs)            
        return exists_marker + u''.join(tags)
Ejemplo n.º 24
0
def generic_display_renderer(widget, data):
    """Generic display renderer to render a value.
    """
    if callable(widget.attrs['template']):
        content = widget.attrs['template'](widget, data)
    else:
        value = fetch_value(widget, data)
        if value is None:
            value = u''
        content = widget.attrs['template'] % value
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    return data.tag('div', content, **attrs)
Ejemplo n.º 25
0
def checkbox_display_renderer(widget, data):
    """Generic display renderer to render a value.
    """
    value = fetch_value(widget, data)
    if widget.attrs['format'] == 'string' and bool(value):
        content = value
    else:
        vocab = dict(vocabulary(widget.attrs.get('vocabulary', [])))
        content = vocab[bool(value)]

    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    return data.tag('div', content, **attrs)
Ejemplo n.º 26
0
def generic_display_renderer(widget, data):
    """Generic display renderer to render a value.
    """
    if callable(widget.attrs['template']):
        content = widget.attrs['template'](widget, data)
    else:
        value = fetch_value(widget, data)
        if value is None:
            value = u''
        content = widget.attrs['template'] % value
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    return data.tag('div', content, **attrs)
Ejemplo n.º 27
0
def array_edit_renderer(widget, data):
    if len(widget) == 1 and not widget.has_key(CONTAINER):
        raise Exception(u"Empty array widget defined")
    if not widget.has_key(CONTAINER):
        template = widget.detach(widget.keys()[1])
        hook_array_template(widget, template)
    value = fetch_value(widget, data)
    # XXX: reset table body if already filled -> case form in memory.
    if value:
        widget.getter = UNSET
        data.value = UNSET
        template = widget[CONTAINER][TEMPLATE]
        create_array_children(widget, template, value)
    if not widget.attrs['add'] or widget.attrs['static']:
        del widget[CONTAINER]
Ejemplo n.º 28
0
def checkbox_display_renderer(widget, data):
    """Generic display renderer to render a value.
    """
    value = fetch_value(widget, data)
    if widget.attrs['format'] == 'string' and bool(value):
        content = value
    else:
        vocab = dict(vocabulary(widget.attrs.get('vocabulary', [])))
        content = vocab[bool(value)]

    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % widget.attrs['class'] or 'generic'
    }
    return data.tag('div', content, **attrs)
Ejemplo n.º 29
0
def datetime_edit_renderer(widget, data):
    locale = attr_value('locale', widget, data)
    delim = attr_value('delimiter', widget, data)
    time = attr_value('time', widget, data)
    date = None
    if data.value and isinstance(data.value, datetime):
        date = format_date(data.value, locale, delim)
        if time:
            time = format_time(data.value)
    if data.extracted and isinstance(data.extracted, datetime):
        date = format_date(data.extracted, locale, delim)
        if time:
            time = format_time(data.extracted)
    if not date:
        date = fetch_value(widget, data)
    return render_datetime_input(widget, data, date, time)
Ejemplo n.º 30
0
def datetime_edit_renderer(widget, data):
    locale = attr_value('locale', widget, data)
    delim = attr_value('delimiter', widget, data)
    time = attr_value('time', widget, data)
    date = None
    if data.value and isinstance(data.value, datetime):
        date = format_date(data.value, locale, delim)
        if time:
            time = format_time(data.value)
    if data.extracted and isinstance(data.extracted, datetime):
        date = format_date(data.extracted, locale, delim)
        if time:
            time = format_time(data.extracted)
    if not date:
        date = fetch_value(widget, data)
    return render_datetime_input(widget, data, date, time)
Ejemplo n.º 31
0
def input_generic_renderer(widget, data):
    """Generic HTML ``input`` tag render.
    """
    input_attrs = {
        'type': widget.attrs['type'],
        'value': fetch_value(widget, data),
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),
        'size': widget.attrs.get('size'),
        'placeholder': widget.attrs.get('placeholder') or None,
        'autofocus': widget.attrs.get('autofocus') and 'autofocus' or None,
        'disabled': bool(widget.attrs.get('disabled')) and 'disabled' or None,
        'autocomplete': widget.attrs.get('autocomplete'),
    }
    input_attrs['required'] = \
        widget.attrs.get('required') and 'required' or None
    if widget.attrs['type'] in ['range', 'number']:
        input_attrs['min'] = widget.attrs.get('min') or None
        input_attrs['max'] = widget.attrs.get('min') or None
        input_attrs['step'] = widget.attrs.get('step') or None
    return data.tag('input', **input_attrs)
Ejemplo n.º 32
0
def input_generic_renderer(widget, data):
    """Generic HTML ``input`` tag render.
    """
    input_attrs = {
        'type': widget.attrs['type'],
        'value': fetch_value(widget, data),
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),    
        'class_': cssclasses(widget, data),
        'size': widget.attrs.get('size'),
        'placeholder': widget.attrs.get('placeholder') or None,
        'autofocus': widget.attrs.get('autofocus') and 'autofocus' or None,
        'disabled': bool(widget.attrs.get('disabled')) and 'disabled' or None,
        'autocomplete': widget.attrs.get('autocomplete'),
    }
    input_attrs['required'] = \
        widget.attrs.get('required') and 'required' or None
    if widget.attrs['type'] in ['range', 'number']:
        input_attrs['min'] = widget.attrs.get('min') or None
        input_attrs['max'] = widget.attrs.get('min') or None
        input_attrs['step'] = widget.attrs.get('step') or None
    return data.tag('input', **input_attrs)
Ejemplo n.º 33
0
def ace_edit_renderer(widget, data):
    value = fetch_value(widget, data)
    if not value:
        value = ''
    ta_attrs = {
        'id': cssid(widget, 'ace', 'value'),
        'name': widget.dottedpath,
        'class': 'ace-editor-value',
        'style': 'display:none;',
    }
    ta = data.tag('textarea', value, **ta_attrs)
    editor_attrs = {
        'id': cssid(widget, 'ace'),
        'class': 'ace-editor',
    }
    editor = data.tag('div', value, **editor_attrs)
    wrapper_css = [
        'ace-editor-wrapper',
        'ace-option-theme-%s' % widget.attrs['theme'],
        'ace-option-mode-%s' % widget.attrs['mode'],
    ]
    wrapper_attrs = {'class': ' '.join(wrapper_css)}
    return data.tag('div', ta + editor, **wrapper_attrs)
Ejemplo n.º 34
0
def dict_edit_renderer(widget, data):
    static = widget.attrs['static']
    table = widget['table']
    table.attrs['id'] = 'dictwidget_%s.entry' % widget.dottedpath
    body = table['body']
    body.clear()
    if data.errors and static:
        basename = '%s.entry' % body.dottedpath
        value = extract_static(data, basename)
    else:
        value = fetch_value(widget, data)
    if not value:
        return
    i = 0
    for key, val in value.items():
        row = body['entry%i' % i] = factory('tr')
        k_props = {
            'td.class': 'key',
            'text.class': attr_value('key_class', widget, data),
        }
        if static:
            k_props['disabled'] = 'disabled'
        row['key'] = factory('td:text', value=key, name='key', props=k_props)
        row['value'] = factory('td:text', value=val, name='value', props={
            'td.class': 'value',
            'text.class': attr_value('value_class', widget, data),
        })
        if not static:
            row['actions'] = factory('td:dict_actions', props={
                'add': True,
                'remove': True,
                'up': True,
                'down': True,
                'class': 'actions',
            })
        i += 1
def alohaeditor_display_renderer(widget, data):
    value = fetch_value(widget, data)
    if not value:
        value = ""
    return data.tag("div", value, **{"class": "display-alohaeditor"})
Ejemplo n.º 36
0
def time_edit_renderer(widget, data):
    format, unit = time_data_defs(widget, data)
    time = time_value(format, unit, fetch_value(widget, data))
    return render_time_input(widget, data, time, css_class=True)
Ejemplo n.º 37
0
def richtext_display_renderer(widget, data):
    value = fetch_value(widget, data)
    if not value:
        value = ''
    return data.tag('div', value, **{'class': 'display-richtext'})
Ejemplo n.º 38
0
def time_edit_renderer(widget, data):
    format, unit = time_data_defs(widget, data)
    time = time_value(format, unit, fetch_value(widget, data))
    return render_time_input(widget, data, time, css_class=True)
Ejemplo n.º 39
0
def select_edit_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    if isinstance(value, basestring) or not hasattr(value, '__iter__'):
        value = [value]
    if not widget.attrs['multivalued'] and len(value) > 1:
        raise ValueError(u"Multiple values for single selection.")
    disabled = widget.attrs.get('disabled', False)
    if widget.attrs['format'] == 'block':
        optiontags = []
        for key, term in vocabulary(widget.attrs.get('vocabulary', [])):
            attrs = {
                'selected': (key in value) and 'selected' or None,
                'value': key,
                'id': cssid(widget, 'input', key),
            }
            if disabled and disabled is not True and key in disabled:
                attrs['disabled'] = 'disabled'
            optiontags.append(tag('option', term, **attrs))
        select_attrs = {
            'name_': widget.dottedpath,
            'id': cssid(widget, 'input'),
            'class_': cssclasses(widget, data),
            'multiple': widget.attrs['multivalued'] and 'multiple' or None,
            'placeholder': widget.attrs.get('placeholder') or None,
            'autofocus': widget.attrs.get('autofocus') and 'autofocus' or None,
            'required': widget.attrs.get('required') and 'required' or None,
        }
        if disabled is True:
            select_attrs['disabled'] = 'disabled'
        rendered = tag('select', *optiontags, **select_attrs)
        if widget.attrs['multivalued']:
            attrs = {
                'type': 'hidden',
                'value': 'exists',
                'name_': "%s-exists" % widget.dottedpath,
                'id': cssid(widget, 'exists'),
            }
            rendered = select_exists_marker(widget, data) + rendered
        return rendered
    else:
        tags = []
        label_pos = widget.attrs['listing_label_position']
        listing_tag = widget.attrs['listing_tag']
        item_tag = listing_tag == 'div' and 'div' or 'li'
        if widget.attrs['multivalued']:
            tagtype = 'checkbox'
        else:
            tagtype = 'radio'
        for key, term in vocabulary(widget.attrs.get('vocabulary', [])):
            attrs = {
                'type': tagtype,
                'value': key,
                'checked': (key in value) and 'checked' or None,
                'name_': widget.dottedpath,
                'id': cssid(widget, 'input', key),
                'class_': cssclasses(widget, data),
            }
            if (disabled and disabled is not True and key in disabled) \
               or disabled is True:
                attrs['disabled'] = 'disabled'

            input = tag('input', **attrs)
            if label_pos == 'inner':
                item = tag('label', term, input, for_=attrs['id'])
            elif label_pos == 'after':
                item = input + tag('label', term, for_=attrs['id'])
            else:
                item = tag('label', term, for_=attrs['id']) + input
            tags.append(
                tag(item_tag, item, **{'id': cssid(widget, tagtype, key)}))
        return select_exists_marker(widget, data) + \
            tag(listing_tag, *tags, **{'id': cssid(widget, tagtype, 'wrapper')})
Ejemplo n.º 40
0
def _value(widget, data):
    """BBB
    """
    logging.warn("Deprecated usage of 'yafowil.common._value', please use "+\
                 "'yafowil.common.fetch_value' instead.") 
    return fetch_value(widget, data)   
Ejemplo n.º 41
0
def wysihtml5_display_renderer(widget, data):
    value = fetch_value(widget, data)
    if not value:
        value = ''
    return data.tag('div', value, **{'class': 'display-wysihtml5'})
Ejemplo n.º 42
0
def dict_edit_renderer(widget, data):
    widget['exists'] = factory('hidden', value='1')
    key_class = attr_value('key_class', widget, data)
    value_class = attr_value('value_class', widget, data)
    table = widget['table'] = factory(
        'table',
        props={
            'structural': True,
            'id': 'dictwidget_{}.entry'.format(widget.dottedpath),
            'class': ' '.join([
                attr_value('table_class', widget, data),
                'key-{0}'.format(key_class),
                'value-{0}'.format(value_class)
            ])
        })
    head = table['head'] = factory(
        'thead',
        props={
            'structural': True
        })
    row = head['row'] = factory(
        'tr',
        props={
            'structural': True
        })
    row['key'] = factory(
        'th',
        props={
            'structural': True,
            'label': key_label(widget, data)
        })
    row['value'] = factory(
        'th',
        props={
            'structural': True,
            'label': value_label(widget, data)
        })
    static = attr_value('static', widget, data)
    if not static:
        row['actions'] = factory(
            'th:dict_actions',
            props={
                'structural': True,
                'add': True,
                'class': 'actions'
            })
    body = table['body'] = factory(
        'tbody',
        props={
            'structural': True
        })
    value = fetch_value(widget, data)
    if not value:
        return
    i = 0
    for key, val in value.items():
        row = body['entry{}'.format(i)] = factory('tr')
        k_props = {
            'td.class': 'key',
            'text.class': key_class
        }
        if static:
            k_props['disabled'] = 'disabled'
        row['key'] = factory(
            'td:text',
            value=key,
            name='key',
            props=k_props
        )
        row['value'] = factory(
            'td:text',
            value=val,
            name='value',
            props={
                'td.class': 'value',
                'text.class': value_class
            })
        if not static:
            row['actions'] = factory(
                'td:dict_actions',
                props={
                    'add': True,
                    'remove': True,
                    'up': True,
                    'down': True,
                    'class': 'actions'
                })
        i += 1
Ejemplo n.º 43
0
def select_edit_renderer(widget, data):
    tag = data.tag
    value = fetch_value(widget, data)
    if isinstance(value, basestring) or not hasattr(value, '__iter__'):
        value = [value]
    if not widget.attrs['multivalued'] and len(value) > 1:
        raise ValueError(u"Multiple values for single selection.")
    disabled = widget.attrs.get('disabled', False)
    if widget.attrs['format'] == 'block':
        optiontags = []
        for key, term in vocabulary(widget.attrs.get('vocabulary', [])):
            attrs = {
                'selected': (key in value) and 'selected' or None,
                'value': key,
                'id': cssid(widget, 'input', key),
            }
            if disabled and disabled is not True and key in disabled:
                attrs['disabled'] = 'disabled'                 
            optiontags.append(tag('option', term, **attrs))            
        select_attrs = {
            'name_': widget.dottedpath,
            'id': cssid(widget, 'input'),
            'class_': cssclasses(widget, data),                        
            'multiple': widget.attrs['multivalued'] and 'multiple' or None,
            'placeholder': widget.attrs.get('placeholder') or None,
            'autofocus': widget.attrs.get('autofocus') and 'autofocus' or None,
            'required': widget.attrs.get('required') and 'required' or None,            
        }        
        if disabled is True:
            select_attrs['disabled'] = 'disabled'
        rendered = tag('select', *optiontags, **select_attrs)
        if widget.attrs['multivalued']:
            attrs = {
                'type': 'hidden',
                'value':  'exists',
                'name_': "%s-exists" % widget.dottedpath,
                'id': cssid(widget, 'exists'),
            }
            rendered = select_exists_marker(widget, data) + rendered
        return rendered
    else:
        tags = []
        label_pos = widget.attrs['listing_label_position']
        listing_tag = widget.attrs['listing_tag']
        item_tag = listing_tag == 'div' and 'div' or 'li'
        if widget.attrs['multivalued']:
            tagtype = 'checkbox'
        else:
            tagtype = 'radio'
        for key, term in vocabulary(widget.attrs.get('vocabulary', [])):
            attrs = {
                'type': tagtype,
                'value':  key,
                'checked': (key in value) and 'checked' or None,
                'name_': widget.dottedpath,
                'id': cssid(widget, 'input', key),    
                'class_': cssclasses(widget, data),
            }
            if (disabled and disabled is not True and key in disabled) \
               or disabled is True:
                attrs['disabled'] = 'disabled'                                 
            
            input = tag('input', **attrs)
            if label_pos == 'inner':
                item = tag('label', term, input, for_=attrs['id'])
            elif label_pos == 'after':
                item = input + tag('label', term, for_=attrs['id'])
            else:
                item = tag('label', term, for_=attrs['id']) + input
            tags.append(tag(item_tag, item,
                            **{'id': cssid(widget, tagtype, key)}))
        return select_exists_marker(widget, data) + \
            tag(listing_tag, *tags, **{'id': cssid(widget, tagtype, 'wrapper')})
Ejemplo n.º 44
0
    def test_fetch_value(self):
        dmarker = list()
        defaults = dict(default=dmarker)
        widget_no_return = Widget(
            'blueprint_names_goes_here', [], [], [], 'empty', defaults=defaults)  # noqa
        widget_with_value = Widget(
            'blueprint_names_goes_here',
            [], [], [],
            'value',
            value_or_getter='withvalue',
            defaults=defaults)
        widget_with_default = Widget(
            'blueprint_names_goes_here',
            [], [], [],
            'default',
            properties=dict(default='defaultvalue'),
            defaults=defaults)
        widget_with_both = Widget(
            'blueprint_names_goes_here',
            [], [], [],
            'both',
            value_or_getter='valueboth',
            properties=dict(default='defaultboth'),
            defaults=defaults)
        data_empty = RuntimeData()
        data_filled = RuntimeData()
        data_filled.extracted = 'extractedvalue'

        data_empty.value = widget_no_return.getter
        self.assertTrue(fetch_value(widget_no_return, data_empty) is dmarker)

        data_filled.value = widget_no_return.getter
        self.assertEqual(
            fetch_value(widget_no_return, data_filled),
            'extractedvalue'
        )

        data_empty.value = widget_with_value.getter
        self.assertEqual(
            fetch_value(widget_with_value, data_empty),
            'withvalue'
        )

        data_filled.value = widget_with_value.getter
        self.assertEqual(
            fetch_value(widget_with_value, data_filled),
            'extractedvalue'
        )

        data_empty.value = widget_with_default.getter
        self.assertEqual(
            fetch_value(widget_with_default, data_empty),
            'defaultvalue'
        )

        data_filled.value = widget_with_default.getter
        self.assertEqual(
            fetch_value(widget_with_default, data_filled),
            'extractedvalue'
        )

        data_empty.value = widget_with_both.getter
        self.assertEqual(
            fetch_value(widget_with_both, data_empty),
            'valueboth'
        )

        data_filled.value = widget_with_both.getter
        self.assertEqual(
            fetch_value(widget_with_default, data_filled),
            'extractedvalue'
        )
Ejemplo n.º 45
0
def cron_edit_renderer(widget, data):
    value = fetch_value(widget, data)
    if value is not UNSET and value is not attr_value('emptyvalue', widget,
                                                      data, EMPTY_VALUE):
        value = [it.strip() for it in value.split(' ') if it.strip()]
        if len(value) == 5:
            value.append('*')
        if len(value) < 6:
            raise ValueError('Invalid cron rule')
        value = {
            'minute': value[0],
            'hour': value[1],
            'dom': value[2],
            'month': value[3],
            'dow': value[4],
            'year': value[5]
        }
    container = widget['container'] = factory(
        'div',
        name='cron',
        value=value,
        props={
            'structural': True,
            'id': cssid(widget, 'input'),
            'class': cssclasses(widget, data),
            'data': {
                'lang': attr_value('lang', widget, data),
                'start_year': attr_value('start_year', widget, data),
                'end_year': attr_value('end_year', widget, data)
            }
        })
    container['minute'] = factory('div:cron_value_edit_action:hidden',
                                  props={
                                      'persist': False,
                                      'label': _('label_minute',
                                                 default='Minute'),
                                      'div.class': 'cron-value minute'
                                  })
    container['hour'] = factory('div:cron_value_edit_action:hidden',
                                props={
                                    'persist': False,
                                    'label': _('label_hour', default='Hour'),
                                    'div.class': 'cron-value hour'
                                })
    container['dom'] = factory('div:cron_value_edit_action:hidden',
                               props={
                                   'persist': False,
                                   'label': _('label_dom',
                                              default='Day of Month'),
                                   'div.class': 'cron-value dom'
                               })
    container['month'] = factory('div:cron_value_edit_action:hidden',
                                 props={
                                     'persist': False,
                                     'label': _('label_month',
                                                default='Month'),
                                     'div.class': 'cron-value month'
                                 })
    container['dow'] = factory('div:cron_value_edit_action:hidden',
                               props={
                                   'persist': False,
                                   'label': _('label_dow',
                                              default='Day of Week'),
                                   'div.class': 'cron-value dow'
                               })
    container['year'] = factory('div:cron_value_edit_action:hidden',
                                props={
                                    'persist': False,
                                    'label': _('label_year', default='Year'),
                                    'div.class': 'cron-value year'
                                })
    container['editarea'] = factory('div',
                                    props={
                                        'structural': True,
                                        'class': 'editarea',
                                    })