Exemplo n.º 1
0
def localize_descriptors():
    """Localizes descriptors from {bungeni_custom}/forms/ui.xml.
    Called when .localize is imported.
    """
    #for d in localizable_descriptor_classes(descriptor_module): ...
    xml = elementtree.ElementTree.fromstring(read_custom())
    for descriptor_elem in xml.findall("descriptor"):
        dname = descriptor_elem.get("name")
        cls = get_localizable_descriptor_class(DESCRIPTOR_MODULE, dname)
        field_elems = descriptor_elem.findall("field")
        field_by_name = {}
        reorder_fields(cls, [f.get("name") for f in field_elems], field_by_name)
        for f_elem in field_elems:
            fname = f_elem.get("name")
            f = field_by_name[fname]
            bungeni_localizable_modes = [ rlm for rlm in f._localizable_modes ]
            clocs = []
            for cloc_elem in f_elem.getchildren():
                modes = cloc_elem.get("modes", None)
                roles = cloc_elem.get("roles", None) # ROLES_DEFAULT
                if cloc_elem.tag == "show":
                    clocs.append(show(modes=modes, roles=roles))
                elif cloc_elem.tag == "hide":
                    clocs.append(hide(modes=modes, roles=roles))
                else:
                    assert False, "Unknown directive [%s/%s] %s" % (
                        dname, fname, cloc_elem.tag)
            if clocs:
                f.localizable[:] = clocs
                f.validate_localizable(
                    reference_localizable_modes=bungeni_localizable_modes)
Exemplo n.º 2
0
def localize_descriptors():
    """Localizes descriptors from {bungeni_custom}/forms/ui.xml.
    """
    start_time = time()
    #for d in localizable_descriptor_classes(descriptor_module): ...
    xml = elementtree.ElementTree.fromstring(read_custom())
    # make the value of <ui.@roles> as *the* bungeni default list of roles
    global ROLES_DEFAULT
    Field._roles[:] = xml.get("roles", ROLES_DEFAULT).split()
    # and reset global "constant"
    ROLES_DEFAULT = " ".join(Field._roles)
    
    STALE_INFO = False
    for descriptor_elem in xml.findall("descriptor"):
        dname = descriptor_elem.get("name")
        cls = get_localizable_descriptor_class(DESCRIPTOR_MODULE, dname)
        field_elems = descriptor_elem.findall("field")
        field_by_name = {}
        reorder_fields(cls, 
            [fe.get("name") for fe in field_elems], field_by_name)
        for f_elem in field_elems:
            fname = f_elem.get("name")
            f = field_by_name[fname]
            
            # check if info-only field attributes are out of sync with bungeni
            # @displayable, from f.modes:tuple
            c_displayable_modes = f_elem.get("displayable").split()
            if is_stale_info(set(f.modes), set(c_displayable_modes),
                "STALE INFO ATTR [%s.%s.modes]\n B: %s\n C: %s" % (
                    dname, fname, f.modes, c_displayable_modes)):
                f._SERIALIZE_modes = f.modes[:]
                STALE_INFO = True
            # @localizable, from f._localizable_modes:set
            c_localizable_modes = set(f_elem.get("localizable", "").split())
            if is_stale_info(f._localizable_modes, c_localizable_modes,
                "STALE INFO ATTR [%s.%s.localizable]\n B: %s\n C: %s" % (
                    dname, fname, f._localizable_modes, c_localizable_modes)):
                f._SERIALIZE_localizable_modes = list(f._localizable_modes)
                STALE_INFO = True
            
            clocs = [] # custom_localizable_directives
            for cloc_elem in f_elem.getchildren():
                modes = cloc_elem.get("modes", None)
                roles = cloc_elem.get("roles", None) # ROLES_DEFAULT
                if cloc_elem.tag == "show":
                    clocs.append(show(modes=modes, roles=roles))
                elif cloc_elem.tag == "hide":
                    clocs.append(hide(modes=modes, roles=roles))
                else:
                    assert False, "Unknown directive [%s/%s] %s" % (
                        dname, fname, cloc_elem.tag)
            if clocs:
                f.localizable[:] = clocs
                try: 
                    f.validate_localizable(
                        reference_localizable_modes=list(c_localizable_modes))
                except Exception, e:
                    # make error message more useful
                    raise e.__class__("Descriptor [%s] %s" % (dname, e.message))
Exemplo n.º 3
0
def localize_descriptors():
    """Localizes descriptors from {bungeni_custom}/forms/ui.xml.
    """
    start_time = time()
    #for d in localizable_descriptor_classes(descriptor_module): ...
    xml = elementtree.ElementTree.fromstring(read_custom())
    # make the value of <ui.@roles> as *the* bungeni default list of roles
    global ROLES_DEFAULT
    Field._roles[:] = xml.get("roles", ROLES_DEFAULT).split()
    # and reset global "constant"
    ROLES_DEFAULT = " ".join(Field._roles)

    STALE_INFO = False
    for descriptor_elem in xml.findall("descriptor"):
        dname = descriptor_elem.get("name")
        cls = get_localizable_descriptor_class(DESCRIPTOR_MODULE, dname)
        field_elems = descriptor_elem.findall("field")
        field_by_name = {}
        reorder_fields(cls, [fe.get("name") for fe in field_elems],
                       field_by_name)
        for f_elem in field_elems:
            fname = f_elem.get("name")
            f = field_by_name[fname]

            # check if info-only field attributes are out of sync with bungeni
            # @displayable, from f.modes:tuple
            c_displayable_modes = f_elem.get("displayable").split()
            if is_stale_info(
                    set(f.modes), set(c_displayable_modes),
                    "STALE INFO ATTR [%s.%s.modes]\n B: %s\n C: %s" %
                (dname, fname, f.modes, c_displayable_modes)):
                f._SERIALIZE_modes = f.modes[:]
                STALE_INFO = True
            # @localizable, from f._localizable_modes:set
            c_localizable_modes = set(f_elem.get("localizable", "").split())
            if is_stale_info(
                    f._localizable_modes, c_localizable_modes,
                    "STALE INFO ATTR [%s.%s.localizable]\n B: %s\n C: %s" %
                (dname, fname, f._localizable_modes, c_localizable_modes)):
                f._SERIALIZE_localizable_modes = list(f._localizable_modes)
                STALE_INFO = True

            clocs = []  # custom_localizable_directives
            for cloc_elem in f_elem.getchildren():
                modes = cloc_elem.get("modes", None)
                roles = cloc_elem.get("roles", None)  # ROLES_DEFAULT
                if cloc_elem.tag == "show":
                    clocs.append(show(modes=modes, roles=roles))
                elif cloc_elem.tag == "hide":
                    clocs.append(hide(modes=modes, roles=roles))
                else:
                    assert False, "Unknown directive [%s/%s] %s" % (
                        dname, fname, cloc_elem.tag)
            if clocs:
                f.localizable[:] = clocs
                try:
                    f.validate_localizable(
                        reference_localizable_modes=list(c_localizable_modes))
                except Exception, e:
                    # make error message more useful
                    raise e.__class__("Descriptor [%s] %s" %
                                      (dname, e.message))