Пример #1
0
    def __new__(mcs, name, bases, attributes):
        """A pre-processor for the components.

        On the moment this meta class does two things, first it adds all functions with the '_bind' property
        to the ``bound_methods`` dictionary for binding them later to the constructed class. Second, it sets the
        ``name`` attribute to the template class name if there is no ``name`` attribute defined.
        """
        result = super().__new__(mcs, name, bases, attributes)

        result.component_type = mcs._resolve_attribute(bases, attributes, '_component_type')
        result.bound_methods = mcs._get_bound_methods(bases, attributes)
        result.subcomponents = mcs._get_subcomponents(attributes)
        result.name = mcs._get_component_name_attribute(name, bases, attributes)

        mcs._apply_merge_dicts(result, bases, attributes)

        if len(_component_loading) == 1:
            try:
                if result.component_type is not None and result.name:
                    from mdt.lib.components import add_template_component
                    add_template_component(result)
            except ValueError:
                pass

        _component_loading.pop()
        return result
Пример #2
0
 def __init__(self, *args, **kwargs):
     with temporary_component_updates():
         for component in subcomponents:
             add_template_component(component)
         super().__init__(*args, **kwargs)