Beispiel #1
0
 def __init__(self, meta, context, registry=None):
     """Initialize self."""
     super().__init__(meta, context, registry)
     error_msg = '{0} is not a sub type of {1}.'
     if not meta.isheet.isOrExtends(IWorkflowAssignment):
         msg = error_msg.format(str(meta.isheet), str(IWorkflowAssignment))
         raise RuntimeConfigurationError(msg)
     if not isinstance(self.schema, WorkflowAssignmentSchema):
         msg = error_msg.format(str(meta.schema_class),
                                str(WorkflowAssignmentSchema))
         raise RuntimeConfigurationError(msg)
Beispiel #2
0
def _get_post_pool(context: IPool, iresource_or_service_name) -> IResource:
    if IInterface.providedBy(iresource_or_service_name):
        post_pool = find_interface(context, iresource_or_service_name)
    else:
        post_pool = find_service(context, iresource_or_service_name)
    if post_pool is None:
        context_path = resource_path(context)
        post_pool_type = str(iresource_or_service_name)
        msg = 'Cannot find post_pool with interface or service name {}'\
              ' for context {}.'.format(post_pool_type, context_path)
        raise RuntimeConfigurationError(msg)
    return post_pool
Beispiel #3
0
    def get_sheet(self, context: object, isheet: IInterface) -> ISheet:
        """Get sheet for `context` and set the 'context' attribute.

        :raise adhocracy_core.exceptions.RuntimeConfigurationError:
           if there is no `isheet` sheet registered for context.
        """
        if not isheet.providedBy(context):
            msg = 'Sheet {0} is not provided by resource {1}'\
                .format(isheet.__identifier__, resource_path(context))
            raise RuntimeConfigurationError(msg)
        meta = self.sheets_meta[isheet]
        sheet = meta.sheet_class(meta, context, self.registry)
        return sheet
Beispiel #4
0
    def get_workflow(self, context: object) -> IWorkflow:
        """Get workflow of `context` or None.

        :raises RuntimeConfigurationError: if workflow is not registered
        """
        iresource = get_iresource(context)
        try:
            name = self.resources_meta[iresource].workflow_name
        except KeyError:  # ease testing
            return None
        if name == '':
            return None
        try:
            workflow = self.workflows[name]
        except KeyError:
            msg = 'Workflow name is not registered: {0}'.format(name)
            raise RuntimeConfigurationError(msg)
        return workflow
Beispiel #5
0
    def get_sheet(self,
                  context: object,
                  isheet: IInterface,
                  request: Request = None,
                  creating: ResourceMetadata = None) -> IResourceSheet:
        """Get sheet for `context` and set the 'context' attribute.

        :raise adhocracy_core.exceptions.RuntimeConfigurationError:
           if there is no `isheet` sheet registered for context.
        """
        if not creating and not isheet.providedBy(context):
            msg = 'Sheet {0} is not provided by resource {1}'\
                .format(isheet.__identifier__, resource_path(context))
            raise RuntimeConfigurationError(msg)
        meta = self.sheets_meta[isheet]
        sheet = self._create_sheet(meta, context, request=request)
        sheet.context = context
        sheet.request = request
        sheet.registry = self.registry
        sheet.creating = creating
        return sheet
Beispiel #6
0
 def _get_asset_file_in_lineage(self, registry) -> File:
     asset = find_interface(self, IAssetData)
     if asset is None:
         msg = 'No IAssetData in lineage of {}'.format(self)
         raise RuntimeConfigurationError(details=msg)
     return registry.content.get_sheet_field(asset, IAssetData, 'data')