Exemplo n.º 1
0
def get_title_from_context(context):
    title = None
    if IAlchemistContent.providedBy(context):
        if IDCDescriptiveProperties.providedBy(context):
            title = context.title
        else:
            props = IDCDescriptiveProperties(context, None)
            if props is not None:
                title = props.title
            else:
                title = context.short_name
    elif IAlchemistContainer.providedBy(context):
        domain_model = context._class
        try:
            descriptor = queryModelDescriptor(domain_model)
        except:
            descriptor = None
            name = ""
        if descriptor:
            name = getattr(descriptor, 'container_name', None)
            if name is None:
                name = getattr(descriptor, 'display_name', None)
        if not name:
            name = getattr(context, '__name__', None)
        title = name
    elif ILocation.providedBy(context) and \
         IDCDescriptiveProperties.providedBy(context):
        title = context.title
    return title
Exemplo n.º 2
0
def get_title_from_context(context):
    title = None
    if IAlchemistContent.providedBy(context):
        if IDCDescriptiveProperties.providedBy(context):
            title = context.title
        else:
            props = IDCDescriptiveProperties(context, None)
            if props is not None:
                title = props.title
            else:
                title = context.short_name
    elif IAlchemistContainer.providedBy(context):
        domain_model = context._class 
        try:
            descriptor = queryModelDescriptor(domain_model)
        except:
            descriptor = None
            name = ""
        if descriptor:
            name = getattr(descriptor, 'container_name', None)
            if name is None:
                name = getattr(descriptor, 'display_name', None)
        if not name:
            name = getattr(context, '__name__', None)
        title = name
    elif ILocation.providedBy(context) and \
         IDCDescriptiveProperties.providedBy(context):
        title = context.title
    return title
Exemplo n.º 3
0
 def form_name(self):
     # play nice w/ containers or content views, or content
     domain_model = getattr(self.context, "domain_model", None)
     if domain_model is None:
         domain_model = getattr(self, "domain_model", None)
         if domain_model is None and IAlchemistContent.providedBy(self.context):
             domain_model = self.context.__class__
     if domain_model is None:
         return self.mode.title()
     return "%s %s" % (self.mode.title(), domain_model.__name__)
Exemplo n.º 4
0
 def form_name( self ):
     # play nice w/ containers or content views, or content
     domain_model = getattr( self.context, 'domain_model', None)
     if domain_model is None:
         domain_model = getattr( self, 'domain_model', None)
         if domain_model is None and IAlchemistContent.providedBy( self.context ):
             domain_model = self.context.__class__
     if domain_model is None:
         return self.mode.title()
     return "%s %s"%(self.mode.title(), domain_model.__name__)
Exemplo n.º 5
0
 def __call__(self, context):
     if IAlchemistContent.providedBy(context):
         ctx = context
     elif  IAlchemistContainer.providedBy(context):
         domain_model = removeSecurityProxy( context.domain_model )
         ctx = domain_model()
     wf = interfaces.IWorkflow(ctx)
     items=[]
     for state in wf.workflow.states.keys():
         items.append(SimpleTerm(wf.workflow.states[state].id,
                     wf.workflow.states[state].id,
                     _(wf.workflow.states[state].title)))
     return SimpleVocabulary(items)
Exemplo n.º 6
0
 def __call__(self, context):
     if IAlchemistContent.providedBy(context):
         ctx = context
     elif  IAlchemistContainer.providedBy(context):
         domain_model = removeSecurityProxy(context.domain_model)
         ctx = domain_model()
     wf = interfaces.IWorkflow(ctx)
     items = []
     for state in wf.workflow.states.keys():
         items.append(SimpleTerm(wf.workflow.states[state].id,
                     wf.workflow.states[state].id,
                     _(wf.workflow.states[state].title)))
     return SimpleVocabulary(items)
Exemplo n.º 7
0
    def form_name(self):
        parent = self.context.__parent__
        if IAlchemistContainer.providedBy(parent):
            descriptor = queryModelDescriptor(parent.domain_model)
        elif IAlchemistContent.providedBy(self.context):
            descriptor = queryModelDescriptor(self.context.__class__)
        else:
            raise RuntimeError("Unsupported object: %s." % repr(self.context))

        if descriptor:
            name = getattr(descriptor, 'display_name', None)

        if name is None:
            name = self.context.__class__.__name__

        return name
Exemplo n.º 8
0
    def form_name( self ):
        parent = self.context.__parent__
        if IAlchemistContainer.providedBy(parent):
            descriptor = queryModelDescriptor(parent.domain_model)
        elif IAlchemistContent.providedBy(self.context):
            descriptor = queryModelDescriptor(self.context.__class__)
        else:
            raise RuntimeError("Unsupported object: %s." % repr(self.context))
        
        if descriptor:
            name = getattr(descriptor, 'display_name', None)

        if name is None:
            name = self.context.__class__.__name__

        return name
Exemplo n.º 9
0
def filterFields(context, form_fields):
    omit_names = []
    if IAlchemistContent.providedBy(context):
        md = queryModelDescriptor(context.__class__)
        for field in form_fields:
            try:
                can_write = security.canWrite(context, field.__name__)
                can_read = security.canAccess(context, field.__name__)
            except AttributeError:
                can_write = can_read = False
            if can_write:
                continue
            if can_read:
                field.for_display = True
                field.custom_widget = md.get(field.__name__).view_widget
            else:
                omit_names.append(field.__name__)
    elif not IAlchemistContainer.providedBy(context):
        ctx = getattr(context, 'context', None)
        if ctx:
            filterFields(ctx, form_fields)
        else:
            raise NotImplementedError
    return form_fields.omit(*omit_names)
Exemplo n.º 10
0
def filterFields(context, form_fields):
    omit_names = []
    if IAlchemistContent.providedBy(context):
        md = queryModelDescriptor(context.__class__)
        for field in form_fields:
            try:
                can_write = security.canWrite( context, field.__name__)
                can_read = security.canAccess( context, field.__name__)
            except AttributeError:
                can_write = can_read = False
            if can_write:
                continue
            if can_read:
                field.for_display = True
                field.custom_widget = md.get(field.__name__).view_widget
            else:
                omit_names.append(field.__name__)
    elif not IAlchemistContainer.providedBy(context):
        ctx=getattr(context, 'context', None)
        if ctx:
            filterFields(ctx, form_fields)
        else:
            raise NotImplementedError
    return form_fields.omit(*omit_names)
Exemplo n.º 11
0
    def expand(self, chain, include_siblings=True):
        if len(chain) == 0:
            return ()

        context = chain.pop()
        items = []

        if IApplication.providedBy(context):
            items.extend(self.expand(chain))

        elif IAlchemistContent.providedBy(context):
            _url = url.absoluteURL(context, self.request)
            if IDCDescriptiveProperties.providedBy(context):
                title = context.title
            else:
                props = IDCDescriptiveProperties(context, None)
                if props is not None:
                    title = props.title
                else:
                    title = context.short_name

            selected = len(chain) == 0

            if chain:
                nodes = self.expand(chain)
            else:
                kls = context.__class__
                containers = [(key, getattr(context, key))
                              for key, value in kls.__dict__.items()
                              if isinstance(value, ManagedContainerDescriptor)]
                nodes = []
                self.expand_containers(nodes, containers, _url, chain, None)

            items.append({
                'title': title,
                'url': _url,
                'current': True,
                'selected': selected,
                'kind': 'content',
                'nodes': nodes,
            })

        elif IAlchemistContainer.providedBy(context):
            # loop through all managed containers of the parent
            # object, and include the present container as the
            # 'current' node.
            parent = context.__parent__
            assert parent is not None
            _url = url.absoluteURL(parent, self.request)

            # append managed containers as child nodes
            kls = type(proxy.removeSecurityProxy(parent))

            if include_siblings is True:
                if IApplication.providedBy(parent):
                    containers = [
                        (name, parent[name]) for name in
                        location.model_to_container_name_mapping.values()
                        if name in parent
                    ]
                elif IReadContainer.providedBy(parent):
                    containers = list(parent.items())
                else:
                    containers = [
                        (key, getattr(parent, key))
                        for key, value in kls.__dict__.items()
                        if isinstance(value, ManagedContainerDescriptor)
                    ]
            else:
                containers = [(context.__name__, context)]

            self.expand_containers(items, containers, _url, chain, context)

        elif ILocation.providedBy(context):
            _url = url.absoluteURL(context, self.request)
            #props = IDCDescriptiveProperties.providedBy(context) and \
            #    context or IDCDescriptiveProperties(context)
            if IDCDescriptiveProperties.providedBy(context):
                props = IDCDescriptiveProperties(context)
            else:
                props = context
            props = proxy.removeSecurityProxy(props)

            selected = len(chain) == 0
            if selected and IReadContainer.providedBy(context):
                nodes = []
                try:
                    self.expand_containers(nodes, context.items(), _url, chain,
                                           context)
                except:
                    pass
            else:
                nodes = self.expand(chain)
            i_id = getattr(props, 'id', 'N/A')
            items.append({
                'title': getattr(props, 'title', i_id),
                'url': _url,
                'current': True,
                'selected': selected,
                'kind': 'location',
                'nodes': nodes,
            })

        elif IReadContainer.providedBy(context):
            items.extend(self.expand(chain))

        return items
Exemplo n.º 12
0
    def expand(self, chain, include_siblings=True):
        if len(chain) == 0:
            return ()

        context = chain.pop()
        items = []

        if IApplication.providedBy(context):
            items.extend(self.expand(chain))

        elif IAlchemistContent.providedBy(context):
            _url = url.absoluteURL(context, self.request)
            if IDCDescriptiveProperties.providedBy(context):
                title = context.title
            else:
                props = IDCDescriptiveProperties(context, None)
                if props is not None:
                    title = props.title
                else:
                    title = context.short_name

            selected = len(chain) == 0
            
            if chain:
                nodes = self.expand(chain)
            else:
                kls = context.__class__
                containers = [
                    (key, getattr(context, key))
                    for key, value in kls.__dict__.items()
                    if isinstance(value, ManagedContainerDescriptor)]
                nodes = []
                self.expand_containers(nodes, containers, _url, chain, None)

            items.append(
                {'title': title,
                 'url': _url,
                 'current': True,
                 'selected': selected,
                 'kind': 'content',
                 'nodes': nodes,
                 })

        elif IAlchemistContainer.providedBy(context):
            # loop through all managed containers of the parent
            # object, and include the present container as the
            # 'current' node.
            parent = context.__parent__
            assert parent is not None
            _url = url.absoluteURL(parent, self.request)

            # append managed containers as child nodes
            kls = type(proxy.removeSecurityProxy(parent))

            if include_siblings is True:
                if IApplication.providedBy(parent):
                    containers = [
                        (name, parent[name])
                        for name in location.model_to_container_name_mapping.values()
                        if name in parent]
                elif IReadContainer.providedBy(parent):
                    containers = list(parent.items())
                else:
                    containers = [
                        (key, getattr(parent, key))
                        for key, value in kls.__dict__.items()
                        if isinstance(value, ManagedContainerDescriptor)]
            else:
                containers = [(context.__name__, context)]
                
            self.expand_containers(items, containers, _url, chain, context)

        elif ILocation.providedBy(context):
            _url = url.absoluteURL(context, self.request)
            #props = IDCDescriptiveProperties.providedBy(context) and \
            #    context or IDCDescriptiveProperties(context)
            if IDCDescriptiveProperties.providedBy(context):
                props = IDCDescriptiveProperties(context)
            else:
                props = context
            props = proxy.removeSecurityProxy(props)

            selected = len(chain) == 0
            if selected and IReadContainer.providedBy(context):
                nodes = []
                try:
                    self.expand_containers(nodes, context.items(), _url, chain, context)
                except:
                    pass
            else:
                nodes = self.expand(chain)
            i_id = getattr(props, 'id','N/A')
            items.append(
                {'title': getattr(props, 'title', i_id),
                 'url': _url,
                 'current': True,
                 'selected': selected,
                 'kind': 'location',
                 'nodes': nodes,
                 })

        elif IReadContainer.providedBy(context):
            items.extend(self.expand(chain))

        return items