コード例 #1
0
def forms_localization_check_reload(event):
    """Called once from forms_localization_init() and (if in DEVMODE)
    once_per_request on IBeforeTraverseEvent events (ui.publication).
    !+ note: switching descriptor on a type config requires restart!
    """
    # a cache of descriptor elems, to be able to update "re-used" descriptors
    DESC_ELEMS_MODIFIED_SINCE = {}
    # "sys" descriptors, if PATH_UI_FORMS_SYSTEM is modified (or not yet loaded)
    if capi.is_modified_since(PATH_UI_FORMS_SYSTEM):
        descriptor_doc = capi.schema.validate_file_rng("descriptor", PATH_UI_FORMS_SYSTEM)
        Field._roles[:] = roles.SYSTEM_ROLES + roles.CUSTOM_ROLES
        # reset global "constant" ROLES_DEFAULT
        global ROLES_DEFAULT
        ROLES_DEFAULT = " ".join(Field._roles)
        for edescriptor in descriptor_doc.findall("descriptor"):
            type_key = xas(edescriptor, "name")
            descriptor_cls = localize_descriptor(type_key, edescriptor)
            DESC_ELEMS_MODIFIED_SINCE[type_key] = edescriptor
    
    for type_key, ti in capi.iter_type_info(scope="custom"):
        # only check "dedicated" descriptor files
        if ti.descriptor_key == type_key:
            # ok, check if dedicated descriptor file has been modified (or not yet loaded)
            #!+get_descriptor_elem
            file_path = capi.get_path_for("forms", "%s.xml" % (type_key))
            if capi.is_modified_since(file_path):
                descriptor_elem = capi.schema.validate_file_rng("descriptor", file_path)
                descriptor_cls = localize_descriptor(type_key, descriptor_elem, scope="custom")
                DESC_ELEMS_MODIFIED_SINCE[type_key] = descriptor_elem
        else:
            # re-using another descriptor...
            if ti.descriptor_key in DESC_ELEMS_MODIFIED_SINCE:
                descriptor_elem = DESC_ELEMS_MODIFIED_SINCE[ti.descriptor_key]
                descriptor_cls = localize_descriptor(type_key, descriptor_elem, scope="custom")
    DESC_ELEMS_MODIFIED_SINCE.clear()
コード例 #2
0
def check_reload_localization(event):
    """Called once on IWSGIApplicationCreatedEvent and (if in DEVMODE)
    once_per_request on IBeforeTraverseEvent events (ui.publication).
    """
    is_init = (event is None)
    if capi.is_modified_since(PATH_UI_FORMS_SYSTEM):
        localize_descriptors(PATH_UI_FORMS_SYSTEM, is_init)
    for type_key, ti in capi.iter_type_info(scope="custom"):
        check_reload_descriptor_file(type_key, is_init)
コード例 #3
0
def check_reload_descriptor_file(type_key, is_init):
    """Check if a singel file has been modified and needs reloading.
    """
    #!+get_descriptor_elem
    file_path = capi.get_path_for("forms", "%s.xml" % (type_key))
    if capi.is_modified_since(file_path):
        descriptor_doc = capi.schema.validate_file_rng("descriptor", file_path)
        assert xas(descriptor_doc, "name") == type_key, type_key
        descriptor_cls = localize_descriptor(descriptor_doc, is_init, scope="custom")
コード例 #4
0
def check_reload_localization(event):
    """Called once on IWSGIApplicationCreatedEvent and (if in DEVMODE)
    once_per_request on IBeforeTraverseEvent events (ui.publication).
    """
    is_init = (event is None)
    if capi.is_modified_since(PATH_UI_FORMS_SYSTEM):
        localize_descriptors(PATH_UI_FORMS_SYSTEM, is_init)
    for type_key, ti in capi.iter_type_info(scope="custom"):
        check_reload_descriptor_file(type_key, is_init)
コード例 #5
0
def check_reload_descriptor_file(type_key, is_init):
    """Check if a singel file has been modified and needs reloading.
    """
    #!+get_descriptor_elem
    file_path = capi.get_path_for("forms", "%s.xml" % (type_key))
    if capi.is_modified_since(file_path):
        descriptor_doc = capi.schema.validate_file_rng("descriptor", file_path)
        assert xas(descriptor_doc, "name") == type_key, type_key
        descriptor_cls = localize_descriptor(descriptor_doc, is_init, scope="custom")