コード例 #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'})
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
ファイル: expires.py プロジェクト: bluedynamics/cone.ugm
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')
コード例 #5
0
def render_time_input(widget, data, value, postfix=None, css_class=False):
    tag = data.tag
    widgetname = widget.dottedpath
    if postfix:
        widgetname = '%s.%s' % (widgetname, postfix)
    if value is True:
        value = ''
    if not value and data.request:
        value = data.request.get(widgetname)
    disabled = attr_value('disabled', widget, data) and 'disabled' or None
    attrs = {
        'type': 'text',
        'value': value,
        'name_': widgetname,
        'id': cssid(widget, 'input', postfix),
        'size': 5,
        'disabled': disabled,
    }
    class_ = ''
    timepicker = attr_value('timepicker', widget, data)
    if timepicker and not disabled:
        class_ = attr_value('timepicker_class', widget, data)
    if css_class:
        additional = class_ and [class_] or list()
        attrs['class_'] = cssclasses(widget, data, additional=additional)
    elif class_:
        attrs['class_'] = class_
    return tag('input', **attrs)
コード例 #6
0
def reference_renderer(widget, data):
    """Properties:
    
    multivalued
        flag whether reference field is multivalued
    
    target
        ajax target for reference browser triggering
    """
    if widget.attrs.get('multivalued'):
        return wrap_ajax_target(select_edit_renderer(widget, data), widget)
    value = ['', '']
    if data.extracted is not UNSET:
        value = [data.extracted, data.request.get(widget.dottedpath)]
    elif data.request.get('%s.uid' % widget.dottedpath):
        value = [
            data.request.get('%s.uid' % widget.dottedpath),
            data.request.get(widget.dottedpath),
        ]
    elif data.value is not UNSET and data.value is not None:
        value = data.value
    text_attrs = {
        'type': 'text',
        'value': value[1],
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),    
    }
    hidden_attrs = {
        'type': 'hidden',
        'value': value[0],
        'name_': '%s.uid' % widget.dottedpath,
    }
    return wrap_ajax_target(
        tag('input', **text_attrs) + tag('input', **hidden_attrs), widget)
コード例 #7
0
def reference_renderer(widget, data):
    if widget.attrs.get('multivalued'):
        return select_renderer(widget, data)
    value = ['', '']
    if data.extracted is not UNSET:
        value = [data.extracted, data.request.get(widget.dottedpath)]
    elif data.request.get('%s.uid' % widget.dottedpath):
        value = [
            data.request.get('%s.uid' % widget.dottedpath),
            data.request.get(widget.dottedpath),
        ]
    elif data.value is not UNSET and data.value is not None:
        value = data.value
    text_attrs = {
        'type': 'text',
        'value': value[1],
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),    
    }
    hidden_attrs = {
        'type': 'hidden',
        'value': value[0],
        'name_': '%s.uid' % widget.dottedpath,
    }
    return tag('input', **text_attrs) + tag('input', **hidden_attrs)
コード例 #8
0
def render_time_input(widget, data, value, postfix=None, css_class=False):
    tag = data.tag
    widgetname = widget.dottedpath
    if postfix:
        widgetname = '{}.{}'.format(widgetname, postfix)
    if value is True:
        value = ''
    if not value and data.request:
        value = data.request.get(widgetname)
    disabled = 'disabled' if attr_value('disabled', widget, data) else None
    attrs = {
        'type': 'text',
        'value': value,
        'name_': widgetname,
        'id': cssid(widget, 'input', postfix),
        'size': 5,
        'disabled': disabled,
    }
    class_ = [attr_value('timeinput_class', widget, data)]
    timepicker = attr_value('timepicker', widget, data)
    if timepicker and not disabled:
        class_.append(attr_value('timepicker_class', widget, data))
    if css_class:
        attrs['class_'] = cssclasses(widget, data, additional=class_)
    else:
        attrs['class_'] = ' '.join(class_)
    return tag('input', **attrs)
コード例 #9
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')
コード例 #10
0
ファイル: expires.py プロジェクト: bluedynamics/cone.ugm
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")
コード例 #11
0
ファイル: mode.py プロジェクト: attilaolah/yafowil
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)
コード例 #12
0
ファイル: compound.py プロジェクト: AnneGilles/yafowil
def fieldset_renderer(widget, data):
    fs_attrs = {
        'id': cssid(widget, 'fieldset'),
        'class_': cssclasses(widget, data)
    }
    rendered = data.rendered
    if widget.attrs['legend']:
        rendered = data.tag('legend', widget.attrs['legend']) + rendered
    return data.tag('fieldset', rendered, **fs_attrs)
コード例 #13
0
ファイル: compound.py プロジェクト: AnneGilles/yafowil
def fieldset_renderer(widget, data):
    fs_attrs = {
        'id': cssid(widget, 'fieldset'),
        'class_': cssclasses(widget, data)
    }
    rendered = data.rendered
    if widget.attrs['legend']:
        rendered = data.tag('legend', widget.attrs['legend']) + rendered
    return data.tag('fieldset', rendered, **fs_attrs)   
コード例 #14
0
def fieldset_renderer(widget, data):
    fs_attrs = {
        'id': cssid(widget, 'fieldset'),
        'class_': cssclasses(widget, data)
    }
    rendered = data.rendered
    legend = attr_value('legend', widget, data)
    if legend:
        rendered = data.tag('legend', legend) + rendered
    return data.tag('fieldset', rendered, **fs_attrs)
コード例 #15
0
def time_display_renderer(widget, data):
    format, unit = time_data_defs(widget, data)
    value = data.value
    if not value:
        return u''
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % attr_value('class', widget, data)
    }
    return data.tag('div', time_value(format, unit, value), **attrs)
コード例 #16
0
def recaptcha_edit_renderer(widget, data):
    recaptcha_attrs = {
        'id': cssid(widget, 'recaptcha'),
        'class': ' '.join([cssclasses(widget, data)]),
    }
    data_attrs = ['theme', 'lang', 'public_key']
    recaptcha_attrs.update(data_attrs_helper(widget, data, data_attrs))
    recaptcha = data.tag('div', ' ', **recaptcha_attrs)
    public_key = attr_value('public_key', widget, data)
    return recaptcha + NO_SCRIPT_TEMPLATE.format(public_key=public_key)
コード例 #17
0
def reference_display_renderer(widget, data):
    if widget.attrs.get('multivalued'):
        prepare_vocab_property(widget, data)
        return select_display_renderer(widget, data)
    label = fetch_reference_label(widget, data)
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-{}'.format(widget.attrs['class'] or 'generic')
    }
    return data.tag('div', label, **attrs)
コード例 #18
0
def time_display_renderer(widget, data):
    format, unit = time_data_defs(widget, data)
    value = data.value
    if not value:
        return u''
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-{}'.format(attr_value('class', widget, data))
    }
    return data.tag('div', time_value(format, unit, value), **attrs)
コード例 #19
0
def fieldset_renderer(widget, data):
    fs_attrs = {
        'id': cssid(widget, 'fieldset'),
        'class_': cssclasses(widget, data)
    }
    rendered = data.rendered
    legend = attr_value('legend', widget, data)
    if legend:
        rendered = data.tag('legend', legend) + rendered
    return data.tag('fieldset', rendered, **fs_attrs)
コード例 #20
0
ファイル: test_utils.py プロジェクト: 2silver/yafowil
    def test_cssid(self):
        # Test CSS id
        @plumbing(Nodespaces, Attributes)
        class CSSTestNode(OrderedNode):
            @property
            def dottedpath(self):
                return u'.'.join([it for it in self.path if it])

        widget = CSSTestNode(name='form')

        widget.attrs['structural'] = True
        self.assertEqual(cssid(widget, 'PREFIX'), None)

        child = widget['child'] = CSSTestNode()
        self.assertEqual(cssid(child, 'PREFIX'), 'PREFIX-form-child')
        self.assertEqual(cssid(child, 'PREFIX', postfix='POSTFIX'),
                         'PREFIX-form-child-POSTFIX')

        child = widget[u'Hällo Wörld'] = CSSTestNode()
        self.assertEqual(cssid(child, 'PREFIX'), 'PREFIX-form-Hallo_World')
コード例 #21
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
コード例 #22
0
ファイル: common.py プロジェクト: syslabcom/yafowil.plone
def plone_label_renderer(widget, data):
    tag = data.tag
    label_text = widget.attrs.get('label', widget.__name__)
    if callable(label_text):
        label_text = label_text()
    label_attrs = {'class_': 'formQuestion'}
    help_text = widget.attrs['help']
    if callable(help_text):
        help_text = help_text()
    if data.tag.translate:
        label_text = data.tag.translate(label_text)
        help_text = data.tag.translate(help_text)
    if data.mode == 'edit':
        for_path = widget.attrs['for']
        if for_path:
            for_widget = widget.root
            for name in for_path.split('.'):
                for_widget = for_widget[name]
            label_attrs['for_'] = cssid(for_widget, 'input')
        else:
            label_attrs['for_'] = cssid(widget, 'input')
        if widget.attrs['title']:
            label_attrs['title'] = widget.attrs['title']
    label_contents = [label_text]
    if widget.attrs.get(widget.attrs['required_bullet_trigger'])\
            and data.mode == 'edit':
        label_contents.append(
            data.tag('span',
                     ' ',
                     class_='required',
                     title=_('required', 'Required')))
    label_contents.append(data.tag('span', help_text, class_='formHelp'))
    rendered = data.rendered is not UNSET and data.rendered or u''
    position = widget.attrs['position']
    if callable(position):
        position = position(widget, data)
    combined_label = u' '.join(label_contents)
    return generic_positional_rendering_helper('label', combined_label,
                                               label_attrs, rendered, position,
                                               tag)
コード例 #23
0
ファイル: test_utils.py プロジェクト: bluedynamics/yafowil
    def test_cssid(self):
        # Test CSS id
        @plumbing(Nodespaces, Attributes)
        class CSSTestNode(OrderedNode):
            @property
            def dottedpath(self):
                return u'.'.join([it for it in self.path if it])

        widget = CSSTestNode(name='form')

        widget.attrs['structural'] = True
        self.assertEqual(cssid(widget, 'PREFIX'), None)

        child = widget['child'] = CSSTestNode()
        self.assertEqual(cssid(child, 'PREFIX'), 'PREFIX-form-child')
        self.assertEqual(
            cssid(child, 'PREFIX', postfix='POSTFIX'),
            'PREFIX-form-child-POSTFIX'
        )

        child = widget[u'Hällo Wörld'] = CSSTestNode()
        self.assertEqual(cssid(child, 'PREFIX'), 'PREFIX-form-Hallo_World')
コード例 #24
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'})
コード例 #25
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)
コード例 #26
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)
コード例 #27
0
ファイル: common.py プロジェクト: bluedynamics/yafowil.plone
def plone_label_renderer(widget, data):
    tag = data.tag
    label_text = widget.attrs.get('label', widget.__name__)
    if callable(label_text):
        label_text = label_text()
    label_attrs = {'class_': 'formQuestion'}
    help_text = widget.attrs['help']
    if callable(help_text):
        help_text = help_text()
    if data.tag.translate:
        label_text = data.tag.translate(label_text)
        help_text = data.tag.translate(help_text)
    if data.mode == 'edit':
        for_path = widget.attrs['for']
        if for_path:
            for_widget = widget.root
            for name in for_path.split('.'):
                for_widget = for_widget[name]
            label_attrs['for_'] = cssid(for_widget, 'input')
        else:
            label_attrs['for_'] = cssid(widget, 'input')
        if widget.attrs['title']:
            label_attrs['title'] = widget.attrs['title']
    label_contents = [label_text]
    if widget.attrs.get(widget.attrs['required_bullet_trigger'])\
            and data.mode == 'edit':
        label_contents.append(data.tag(
            'span', ' ',
            class_='required',
            title=_('required', 'Required')))
    label_contents.append(data.tag('span', help_text, class_='formHelp'))
    rendered = data.rendered is not UNSET and data.rendered or u''
    position = widget.attrs['position']
    if callable(position):
        position = position(widget, data)
    combined_label = u' '.join(label_contents)
    return generic_positional_rendering_helper(
        'label', combined_label, label_attrs, rendered, position, tag)
コード例 #28
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)
コード例 #29
0
def reference_edit_renderer(widget, data):
    """Properties:

    multivalued
        flag whether reference field is multivalued.

    vocabulary
        if multivalued, provide a vocabulary mapping uids to node names.

    target
        ajax target for reference browser triggering.

    root
        path of reference browser root. Defaults to '/'

    referencable
        list of node info names which are referencable.  Defaults to '',
        which means all objects are referencable, given they provide
        ``IUUIDAware`` and a node info.
    """
    if widget.attrs.get('multivalued'):
        rendered = select_edit_renderer(widget, data)
        return wrap_ajax_target(rendered, widget, data)
    value = ['', '']
    if data.extracted is not UNSET:
        value = [data.extracted, data.request.get(widget.dottedpath)]
    elif data.request.get('%s.uid' % widget.dottedpath):
        value = [
            data.request.get('%s.uid' % widget.dottedpath),
            data.request.get(widget.dottedpath),
        ]
    elif data.value is not UNSET and data.value is not None:
        value = data.value
    text_attrs = {
        'type': 'text',
        'value': value[1],
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),
        'readonly': 'readonly',
    }
    hidden_attrs = {
        'type': 'hidden',
        'value': value[0],
        'name_': '%s.uid' % widget.dottedpath,
    }
    rendered = tag('input', **text_attrs) + tag('input', **hidden_attrs)
    return wrap_ajax_target(rendered, widget, data)
コード例 #30
0
def reference_edit_renderer(widget, data):
    """Properties:

    multivalued
        flag whether reference field is multivalued.

    vocabulary
        if multivalued, provide a vocabulary mapping uids to node names.

    target
        ajax target for reference browser triggering.

    root
        path of reference browser root. Defaults to '/'

    referencable
        list of node info names which are referencable.  Defaults to '',
        which means all objects are referencable, given they provide
        ``IUUIDAware`` and a node info.
    """
    if widget.attrs.get('multivalued'):
        rendered = select_edit_renderer(widget, data)
        return wrap_ajax_target(rendered, widget, data)
    value = ['', '']
    if data.extracted is not UNSET:
        value = [data.extracted, data.request.get(widget.dottedpath)]
    elif data.request.get('{}.uid'.format(widget.dottedpath)):
        value = [
            data.request.get('{}.uid'.format(widget.dottedpath)),
            data.request.get(widget.dottedpath),
        ]
    elif data.value is not UNSET and data.value is not None:
        value = data.value
    text_attrs = {
        'type': 'text',
        'value': value[1],
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),
        'readonly': 'readonly',
    }
    hidden_attrs = {
        'type': 'hidden',
        'value': value[0],
        'name_': '{}.uid'.format(widget.dottedpath),
    }
    rendered = tag('input', **text_attrs) + tag('input', **hidden_attrs)
    return wrap_ajax_target(rendered, widget, data)
コード例 #31
0
def array_wrapper_renderer(widget, data):
    add_css = ''
    if not widget.attrs['static']:
        for attr in ['add', 'remove', 'sort']:
            if widget.attrs[attr]:
                add_css += ' array-%s' % attr
    else:
        add_css += ' array-static'
    kw = {
        'id': cssid(widget, 'array'),
        'class': cssclasses(widget, data) + add_css,
    }
    if not 'array' in kw['class'].split(' '):
        kw['class'] = 'array %s' % kw['class']
    rendered = data.rendered
    return data.tag('div', rendered, **kw)
コード例 #32
0
ファイル: expires.py プロジェクト: bluedynamics/cone.ugm
def expiration_display_renderer(widget, data):
    tag = data.tag
    active_attrs = dict()
    active_attrs["id"] = cssid(widget, "checkbox")
    active_attrs["type"] = "checkbox"
    active_attrs["disabled"] = "disabled"
    value = data.value
    if value != 0:
        active_attrs["checked"] = "checked"
    active = tag("input", **active_attrs)
    until = tag("label", u"until")
    if value not in [0, UNSET]:
        value = datetime.fromtimestamp(value)
    expires = datetime_display_renderer(widget, data, value)
    if expires:
        expires = until + expires
    return tag("div", active + expires, class_="expiration-widget")
コード例 #33
0
def expiration_display_renderer(widget, data):
    tag = data.tag
    active_attrs = dict()
    active_attrs['id'] = cssid(widget, 'checkbox')
    active_attrs['type'] = 'checkbox'
    active_attrs['disabled'] = 'disabled'
    value = data.value
    if value != 0:
        active_attrs['checked'] = 'checked'
    active = tag('input', **active_attrs)
    until = tag('label', u'until')
    if value not in [0, UNSET]:
        value = datetime.fromtimestamp(value)
    expires = datetime_display_renderer(widget, data, value)
    if expires:
        expires = until + expires
    return tag('div', active + expires, class_='expiration-widget')
コード例 #34
0
ファイル: expires.py プロジェクト: bluedynamics/cone.ugm
def expiration_display_renderer(widget, data):
    tag = data.tag
    active_attrs = dict()
    active_attrs['id'] = cssid(widget, 'checkbox')
    active_attrs['type'] = 'checkbox'
    active_attrs['disabled'] = 'disabled'
    value = data.value
    if value != 0:
        active_attrs['checked'] = 'checked'
    active = tag('input', **active_attrs)
    until = tag('label', u'until')
    if value not in [0, UNSET]:
        value = datetime.fromtimestamp(value)
    expires = datetime_display_renderer(widget, data, value)
    if expires:
        expires = until + expires
    return tag('div', active + expires, class_='expiration-widget')
コード例 #35
0
def image_edit_renderer(widget, data):
    src = attr_value('src', widget, data)
    if not src:
        return data.rendered
    if src.find('?') > -1:
        src = src + '&nocache=%i' % time.time()
    else:
        src = src + '?nocache=%i' % time.time()
    tag = data.tag
    img_attrs = {
        'src': src,
        'alt': attr_value('alt', widget, data),
        'id': cssid(widget, 'image-preview'),
        'class': 'image-preview',
    }
    img = tag('img', **img_attrs)
    return img + data.rendered
コード例 #36
0
def datetime_display_renderer(widget, data, value=None):
    """Note: This renderer function optionally accepts value as parameter,
    which is used in favor of data.value if defined. Thus it can be used as
    utility function inside custom blueprints with the need of datetime
    display rendering.
    """
    value = value if value else data.value
    if not value:
        return u''
    format = widget.attrs['format']
    if callable(format):
        value = format(widget, data)
    else:
        value = value.strftime(format)
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-{}'.format(attr_value('class', widget, data))
    }
    return data.tag('div', value, **attrs)
コード例 #37
0
def datetime_display_renderer(widget, data, value=None):
    """Note: This renderer function optionally accepts value as parameter,
    which is used in favor of data.value if defined. Thus it can be used as
    utility function inside custom blueprints with the need of datetime
    display rendering.
    """
    value = value and value or data.value
    if not value:
        return u''
    format = widget.attrs['format']
    if callable(format):
        value = format(widget, data)
    else:
        value = value.strftime(format)
    attrs = {
        'id': cssid(widget, 'display'),
        'class_': 'display-%s' % attr_value('class', widget, data)
    }
    return data.tag('div', value, **attrs)
コード例 #38
0
def render_datetime_input(widget, data, date, time):
    tag = data.tag
    timeinput = ''
    if time:
        timeinput = render_time_input(widget, data, time, postfix='time')
    additional_classes = [attr_value('dateinput_class', widget, data)]
    datepicker = attr_value('datepicker', widget, data)
    disabled = attr_value('disabled', widget, data)
    if datepicker and not disabled:
        datepicker_class = attr_value('datepicker_class', widget, data)
        additional_classes.append(datepicker_class)
    attrs = {
        'type': 'text',
        'value': date,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data, additional=additional_classes),
        'size': 10,
        'disabled': 'disabled' if disabled else None,
    }
    return tag('input', **attrs) + timeinput
コード例 #39
0
def render_datetime_input(widget, data, date, time):
    tag = data.tag
    timeinput = ''
    if time:
        timeinput = render_time_input(widget, data, time, 'time')
    additional_classes = []
    datepicker = attr_value('datepicker', widget, data)
    disabled = attr_value('disabled', widget, data)
    if datepicker and not disabled:
        datepicker_class = attr_value('datepicker_class', widget, data)
        additional_classes.append(datepicker_class)
    attrs = {
        'type': 'text',
        'value':  date,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data, additional=additional_classes),
        'size': 10,
        'disabled': disabled and 'disabled' or None,
    }
    return tag('input', **attrs) + timeinput
コード例 #40
0
def reference_edit_renderer(widget, data):
    if widget.attrs.get('multivalued'):
        prepare_vocab_property(widget, data)
        rendered = select_edit_renderer(widget, data)
        trigger = reference_trigger_renderer(widget, data)
        return wrap_ajax_target(rendered + trigger, widget, data)
    label = fetch_reference_label(widget, data)
    value = fetch_reference_value(widget, data)
    text_attrs = {
        'type': 'text',
        'value': label,
        'name_': widget.dottedpath,
        'id': cssid(widget, 'input'),
        'class_': cssclasses(widget, data),
        'readonly': 'readonly',
    }
    hidden_attrs = {
        'type': 'hidden',
        'value': value if value else '',
        'name_': '{}.uid'.format(widget.dottedpath),
    }
    rendered = tag('input', **text_attrs) + tag('input', **hidden_attrs)
    trigger = reference_trigger_renderer(widget, data)
    return wrap_ajax_target(rendered + trigger, widget, data)
コード例 #41
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',
                                    })