Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def chosen_edit_renderer(widget, data):
    custom_attrs = data_attrs_helper(widget, data, chosen_options)
    return select_edit_renderer(widget, data, custom_attrs=custom_attrs)