Ejemplo n.º 1
0
    def _add(self, parent: IPool, resource: object, appstructs: dict,
             registry: Registry) -> str:
        """Add resource to parent pool.

        :raises substanced.folder.FolderKeyError:
        :raises ValueError:
        """
        name = ''
        if self.name_identifier in appstructs:
            name = appstructs[self.name_identifier]['name']
        if self.meta.use_autonaming:
            prefix = self.meta.autonaming_prefix
            name = parent.next_name(resource, prefix=prefix)
        elif self.meta.use_autonaming_random:
            name = generate_random_name()
        if name in parent:
            raise KeyError('Duplicate name: {}'.format(name))
        if IServicePool.providedBy(resource):
            name = self.meta.content_name
            parent.add_service(name, resource,
                               send_events=True,
                               registry=registry)
            return
        if name == '':
            raise KeyError('Empty name')
        parent.add(name, resource,
                   send_events=True,
                   registry=registry)
Ejemplo n.º 2
0
    def _add(self, parent: IPool, resource: object, appstructs: dict,
             registry: Registry) -> str:
        """Add resource to parent pool.

        :raises substanced.folder.FolderKeyError:
        :raises ValueError:
        """
        name = ''
        if self.name_identifier in appstructs:
            name = appstructs[self.name_identifier]['name']
        if self.meta.use_autonaming:
            prefix = self.meta.autonaming_prefix
            name = parent.next_name(resource, prefix=prefix)
        elif self.meta.use_autonaming_random:
            name = generate_random_name()
        if name in parent:
            raise KeyError('Duplicate name: {}'.format(name))
        if IServicePool.providedBy(resource):
            name = self.meta.content_name
            parent.add_service(name,
                               resource,
                               send_events=True,
                               registry=registry)
            return
        if name == '':
            raise KeyError('Empty name')
        parent.add(name, resource, send_events=True, registry=registry)
Ejemplo n.º 3
0
def do_transition_to_voteable(context: IPool, request: Request, **kwargs):
    """Do transition from state proposed to voteable for all children."""
    for child in context.values():
        _do_transition(child,
                       request,
                       from_state='proposed',
                       to_state='voteable')
Ejemplo n.º 4
0
    def test_create(self):
        from adhocracy_core.interfaces import IPool
        from zope.interface.verify import verifyObject

        inst = self._makeOne()
        assert verifyObject(IPool, inst)
        assert IPool.providedBy(inst)
Ejemplo n.º 5
0
 def _is_bplan_and_has_no_version_with_sheet_data(self,
                                                  meta: ResourceMetadata,
                                                  context: IPool) -> bool:
     is_bplan_version = meta.iresource.isOrExtends(IProposalVersion)
     if not is_bplan_version:
         return False
     versions_with_data = [x for x in context.values()
                           if IProposalVersion.providedBy(x)
                           and has_annotation_sheet_data(x)]
     return versions_with_data == []
Ejemplo n.º 6
0
 def _is_bplan_and_has_no_version_with_sheet_data(self,
                                                  meta: ResourceMetadata,
                                                  context: IPool) -> bool:
     is_bplan_version = meta.iresource.isOrExtends(IProposalVersion)
     if not is_bplan_version:
         return False
     versions_with_data = [
         x for x in context.values()
         if IProposalVersion.providedBy(x) and has_annotation_sheet_data(x)
     ]
     return versions_with_data == []
Ejemplo n.º 7
0
def do_transition_to_voteable(context: IPool, request: Request, **kwargs):
    """Do transition from state proposed to voteable for all children."""
    for child in context.values():
        _do_transition(child, request, from_state='proposed',
                       to_state='voteable')
Ejemplo n.º 8
0
 def test_create(self):
     from adhocracy_core.interfaces import IPool
     from zope.interface.verify import verifyObject
     inst = self._makeOne()
     assert verifyObject(IPool, inst)
     assert IPool.providedBy(inst)
Ejemplo n.º 9
0
def _remove_children(context: IPool, registry: Registry) -> None:
    child_names = [x for x in context.keys()]
    for child in child_names:
        context.remove(child, registry=registry)
Ejemplo n.º 10
0
def _remove_children(context: IPool, registry: Registry) -> None:
    child_names = [x for x in context.keys()]
    for child in child_names:
        context.remove(child, registry=registry)
Ejemplo n.º 11
0
def enabled_ordering(pool: IPool, registry: Registry, **kwargs):
    """Enabled ordering for `pool` children."""
    initial_order = list(pool.keys())
    if hasattr(pool, '__oid__'):  # ease testing
        pool.set_order(initial_order, reorderable=True)