Ejemplo n.º 1
0
 def test_iscontent(self):
     from zope.interface import implements
     from repoze.lemonade.interfaces import IContent
     from repoze.lemonade.content import is_content
     class Content:
         implements(IContent)
     content = Content()
     self.failUnless(is_content(content))
     self.failIf(is_content(None))
Ejemplo n.º 2
0
    def test_iscontent(self):
        from zope.interface import implements
        from repoze.lemonade.interfaces import IContent
        from repoze.lemonade.content import is_content

        class Content:
            implements(IContent)

        content = Content()
        self.failUnless(is_content(content))
        self.failIf(is_content(None))
Ejemplo n.º 3
0
Archivo: acl.py Proyecto: Falmarri/karl
def get_context_workflow(context):
    """
    If context is content and part of a workflow will return the workflow.
    Otherwise returns None.
    """
    if is_content(context):
        content_type = get_content_type(context)
        return get_workflow(content_type, 'security', context)
Ejemplo n.º 4
0
Archivo: acl.py Proyecto: zagy/karl
def get_context_workflow(context):
    """
    If context is content and part of a workflow will return the workflow.
    Otherwise returns None.
    """
    if is_content(context):
        content_type = get_content_type(context)
        return get_workflow(content_type, 'security', context)
Ejemplo n.º 5
0
def set_created(object, event):
    """ Add modified and created attributes to nodes which do not yet
    have them (recursively); an IObjectWillBeAddedEvent subscriber"""
    now = datetime.datetime.now()
    for node in postorder(object):
        if is_content(object):
            if not getattr(node, 'modified', None):
                node.modified = now
            if not getattr(node, 'created', None):
                node.created = now
Ejemplo n.º 6
0
def set_modified(obj, event):
    """ Set the modified date on a single piece of content.
    
    This subscriber is non-recursive.
    
    Intended use is as an IObjectModified event subscriber.
    """
    if is_content(obj):
        now = _now()
        obj.modified = now
        _modify_community(obj, now)
Ejemplo n.º 7
0
def index_content(obj, event):
    """ Index content (an IObjectAddedEvent subscriber) """
    catalog = find_catalog(obj)
    if catalog is not None:
        for node in postorder(obj):
            if is_content(obj):
                path = resource_path(node)
                docid = getattr(node, 'docid', None)
                if docid is None:
                    docid = node.docid = catalog.document_map.add(path)
                else:
                    catalog.document_map.add(path, docid)
                catalog.index_doc(docid, node)
Ejemplo n.º 8
0
def index_content(obj, event):
    """ Index content (an IObjectAddedEvent subscriber) """
    catalog = find_catalog(obj)
    if catalog is not None:
        for node in postorder(obj):
            if is_content(obj):
                path = resource_path(node)
                docid = getattr(node, 'docid', None)
                if docid is None:
                    docid = node.docid = catalog.document_map.add(path)
                else:
                    catalog.document_map.add(path, docid)
                catalog.index_doc(docid, node)
Ejemplo n.º 9
0
def set_created(obj, event):
    """ Add modified and created attributes to nodes which do not yet
    have them (recursively); an IObjectWillBeAddedEvent subscriber"""
    now = datetime.now()
    for node in postorder(obj):
        if is_content(obj):
            if not getattr(node, 'modified', None):
                node.modified = now
            if not getattr(node, 'created', None):
                node.created = now
    parent = getattr(event, 'parent', None)
    if parent is not None:
        _modify_community(parent, now)
Ejemplo n.º 10
0
def index_content(object, event):
    """ Index content (an IObjectAddedEvent subscriber) """
    catalog = find_catalog(object)
    if catalog is not None:
        for node in postorder(object):
            if is_content(object):
                path = resource_path(node)
                docid = catalog.document_map.add(path)
                catalog.index_doc(docid, node)
                adapter = queryAdapter(node, IMetadata)
                if adapter is not None:
                    metadata = adapter()
                    catalog.document_map.add_metadata(docid, metadata)
Ejemplo n.º 11
0
def set_created(obj, event):
    """ Add modified and created attributes to obj and children.

    Only add to content objects which do not yet have them (recursively)

    Intended use is as an IObjectWillBeAddedEvent subscriber.
    """
    now = _now()
    for node in postorder(obj):
        if is_content(obj):
            if not getattr(node, 'modified', None):
                node.modified = now
            if not getattr(node, 'created', None):
                node.created = now
    parent = getattr(event, 'parent', None)
    if parent is not None:
        _modify_community(parent, now)
Ejemplo n.º 12
0
def set_created(obj, event):
    """ Add modified and created attributes to obj and children.

    Only add to content objects which do not yet have them (recursively)

    Intended use is as an IObjectWillBeAddedEvent subscriber.
    """
    now = _now()
    for node in postorder(obj):
        if is_content(obj):
            if not getattr(node, 'modified', None):
                node.modified = now
            if not getattr(node, 'created', None):
                node.created = now
    parent = getattr(event, 'parent', None)
    if parent is not None:
        _modify_community(parent, now)
Ejemplo n.º 13
0
def set_modified(obj, event):
    """ Set the modified date on a single piece of content.

    This subscriber is non-recursive.

    Intended use is as an IObjectModified event subscriber.
    """
    if is_content(obj):
        now = _now()
        obj.modified = now
        _modify_community(obj, now)
        repo = find_repo(obj)
        if repo is not None:
            adapter = queryAdapter(obj, IObjectVersion)
            if adapter is not None:
                repo.archive(adapter)
                if adapter.comment is None:
                    adapter.comment = 'Content modified.'
Ejemplo n.º 14
0
def set_modified(obj, event):
    """ Set the modified date on a single piece of content.

    This subscriber is non-recursive.

    Intended use is as an IObjectModified event subscriber.
    """
    if is_content(obj):
        now = _now()
        obj.modified = now
        _modify_community(obj, now)
        repo = find_repo(obj)
        if repo is not None:
            adapter = queryAdapter(obj, IObjectVersion)
            if adapter is not None:
                repo.archive(adapter)
                if adapter.comment is None:
                    adapter.comment = 'Content modified.'