src/pyams_content/component/paragraph/container.py
changeset 930 814f7c5e04d1
parent 928 de7b111fee8a
child 959 0d42d6bc3fb9
equal deleted inserted replaced
929:1440d627e103 930:814f7c5e04d1
    40     def append(self, value):
    40     def append(self, value):
    41         key = str(self.last_id)
    41         key = str(self.last_id)
    42         self[key] = value
    42         self[key] = value
    43         self.last_id += 1
    43         self.last_id += 1
    44 
    44 
    45     def get_visible_paragraphs(self, anchors_only=False, factories=None):
    45     def get_visible_paragraphs(self, names=None, anchors_only=False, factories=None):
    46         for paragraph in self.values():
    46         if names:
    47             if not paragraph.visible:
    47             for name in names:
    48                 continue
    48                 paragraph = self.get(name)
    49             if anchors_only and not paragraph.anchor:
    49                 if (paragraph is not None) and paragraph.visible:
    50                 continue
    50                     yield paragraph
    51             if factories:
    51         else:
    52                 registry = get_global_registry()
    52             for paragraph in self.values():
    53                 has_factory = False
    53                 if not paragraph.visible:
    54                 for factory_name in factories:
       
    55                     factory = registry.queryUtility(IParagraphFactory, name=factory_name)
       
    56                     has_factory = (factory is not None) and isinstance(paragraph, factory.content_type)
       
    57                     if has_factory:
       
    58                         break
       
    59                 if not has_factory:
       
    60                     continue
    54                     continue
    61             yield paragraph
    55                 if anchors_only and not paragraph.anchor:
       
    56                     continue
       
    57                 if factories:
       
    58                     registry = get_global_registry()
       
    59                     has_factory = False
       
    60                     for factory_name in factories:
       
    61                         factory = registry.queryUtility(IParagraphFactory, name=factory_name)
       
    62                         has_factory = (factory is not None) and isinstance(paragraph, factory.content_type)
       
    63                         if has_factory:
       
    64                             break
       
    65                     if not has_factory:
       
    66                         continue
       
    67                 yield paragraph
    62 
    68 
    63 
    69 
    64 @adapter_config(context=IParagraphContainerTarget, provides=IParagraphContainer)
    70 @adapter_config(context=IParagraphContainerTarget, provides=IParagraphContainer)
    65 def paragraph_container_factory(target):
    71 def paragraph_container_factory(target):
    66     """Paragraphs container factory"""
    72     """Paragraphs container factory"""