Exemple #1
0
def new_descriptor_fields(edescriptor):
    """(Re-)build (in desired order) all fields from newly loaded 
    descriptor configuration.
    # !+ what about "removed" fields from a sys-descriptor config?
    """
    type_key = xas(edescriptor, "name")
    fields = []
    for f_elem in edescriptor.findall("field"):
        name = xas(f_elem, "name")
        # custom_localizable_directives
        clocs = []
        for cloc_elem in f_elem.getchildren():
            modes = xas(cloc_elem, "modes")
            roles = capi.schema.qualified_roles(
                xas(cloc_elem, "roles", ROLES_DEFAULT))
            tag = cloc_elem.tag
            if tag == "show":
                clocs.append(show(modes=modes, roles=roles))
            elif tag == "hide":
                clocs.append(hide(modes=modes, roles=roles))
            elif isinstance(tag, basestring):
                raise ValueError(
                    "Unknown directive %r in field %r in descriptor %r" %
                    (cloc_elem.tag, name, type_key))
            else:
                pass  # xml comment, ...

        fields.append(
            field.F(
                name=name,
                label=xas(f_elem, "label"),
                description=xas(f_elem, "description"),
                required=xab(f_elem, "required"),
                localizable=clocs,
                value_type=xas(f_elem, "value_type"),
                render_type=xas(f_elem, "render_type"),
                vocabulary=xas(f_elem, "vocabulary"),
                extended=xas(f_elem, "extended"),
                derived=xas(f_elem, "derived"),
            ))
    return fields
def new_descriptor_fields(edescriptor):
    """(Re-)build (in desired order) all fields from newly loaded 
    descriptor configuration.
    # !+ what about "removed" fields from a sys-descriptor config?
    """
    type_key = xas(edescriptor, "name")
    fields = []
    for f_elem in edescriptor.findall("field"):
        name = xas(f_elem, "name")
        # custom_localizable_directives
        clocs = []
        for cloc_elem in f_elem.getchildren():
            modes = xas(cloc_elem, "modes")
            roles = capi.schema.qualified_roles(xas(cloc_elem, "roles", ROLES_DEFAULT).split())
            tag = cloc_elem.tag
            if tag == "show":
                clocs.append(show(modes=modes, roles=roles))
            elif tag == "hide":
                clocs.append(hide(modes=modes, roles=roles))
            elif isinstance(tag, basestring):
                raise ValueError(
                    "Unknown directive %r in field %r in descriptor %r" % (
                        cloc_elem.tag, name, type_key))
            else:
                pass # xml comment, ...
        
        fields.append(field.F(
                name=name,
                label=xas(f_elem, "label"),
                description=xas(f_elem, "description"),
                required=xab(f_elem, "required"),
                localizable=clocs,
                value_type=xas(f_elem, "value_type"),
                render_type=xas(f_elem, "render_type"),
                vocabulary=xas(f_elem, "vocabulary"),
                extended=xas(f_elem, "extended"),
                derived=xas(f_elem, "derived"),
            ))
    return fields