コード例 #1
0
ファイル: contentfeeds.py プロジェクト: amarandon/opencore
def _getInfo(profile, content, ifaces=None):
    ifaces = ifaces or find_events(content).supported_ctx_ifaces()
    context = find_supported_interface(content, ifaces)
    if context is None:
        context_name = context_url = context_creator = context_type = None
    else:
        context_name = context.title
        context_url = model_path(context)
        context_creator = context.creator
        context_type = get_content_type(context)
    tagger = find_tags(content)
    if tagger is not None:
        cloud = list(tagger.getCloud(items=(content.docid,)))
        tag_counts = sorted(cloud, key=lambda x: x[1], reverse=True)[:3]
        tags = [x[0] for x in tag_counts]
    else:
        tags = ()
    content_type = get_content_type(content)
    desc = getattr(content, 'description', '')
    short = len(desc) > 80 and '%s...' % desc[:80] or desc
    if IPosts.providedBy(content):
        comment_count = len(content.get('comments', ()))
    else:
        comment_count = False
    content_creator = profile.__name__
    if IComment.providedBy(content):
        # my content filter needs to know if a comment was made inside my post
        content_creator = content.__parent__.__parent__.creator

    if hasattr(content, 'likes'):
        likes = len(content.likes)
    else:
        likes = 0
        
    return {'content_type': content_type.getTaggedValue('name'),
            'userid': profile.__name__,
            'context_name': context_name,
            'context_url': context_url,
            'context_creator': context_creator,
             'context_type': context_type.getTaggedValue('name') if context_type else None, 
            'content_creator': content_creator,
            'url': model_path(content),
            'title': content.title,
            'description': desc,
            'short_description': short,
            'allowed':
                principals_allowed_by_permission(content, 'view'),
            'comment_count': comment_count,
            'tags': tags,                 #XXX
            'author': profile.title,
            'profile_url': '/profiles/%s' % profile.__name__,
            'thumbnail': '/profiles/%s/profile_thumbnail' % profile.__name__,
            'timestamp': _NOW(),
            'likes':likes
           }
コード例 #2
0
ファイル: panels.py プロジェクト: hj91/karl
def intranets_info(context, request):
    """Get information for the footer and intranets listing"""
    intranets_info = []
    intranets = find_intranets(context)
    if intranets:
        intranets_url = resource_url(intranets, request)
        for name, entry in intranets.items():
            try:
                content_iface = get_content_type(entry)
            except ValueError:
                continue
            if content_iface == ICommunity:
                if not has_permission('view', entry, request):
                    continue
                href = '%s%s/' % (intranets_url, quote_path_segment(name))
                intranets_info.append({
                    'title':
                    entry.title,
                    'intranet_href':
                    href,
                    'edit_href':
                    href + '/edit_intranet.html',
                })
        # Sort the list
        def intranet_sort(x, y):
            if x['title'] > y['title']:
                return 1
            else:
                return -1

        intranets_info.sort(intranet_sort)
    return intranets_info
コード例 #3
0
ファイル: evolve35.py プロジェクト: iotest3/new
def evolve(site):
    offices = site.get('offices')
    if offices is None:
        return

    for doc in postorder(offices):
        if hasattr(doc, '__custom_acl__'):
            continue

        try:
            ct = get_content_type(doc)
        except:
            continue

        if ct is None:
            continue

        wf = get_workflow(ct, 'security', doc)
        if wf is None:
            continue

        if wf.name != 'intranet-content':
            continue

        print 'Resetting workflow for', resource_path(doc)
        wf.reset(doc)

    _reindex(offices)
コード例 #4
0
ファイル: api.py プロジェクト: boothead/karl
    def intranets_info(self):
        """Get information for the footer and intranets listing"""
        if self._intranets_info is None:
            intranets_info = []
            intranets = find_intranets(self.context)
            if not intranets:
                # Maybe there aren't any intranets defined yet
                return []
            request = self.request
            intranets_url = model_url(intranets, request)
            for name, entry in intranets.items():
                try:
                    content_iface = get_content_type(entry)
                except ValueError:
                    continue
                href = "%s%s/" % (intranets_url, quote_path_segment(name))
                if content_iface == ICommunity:
                    intranets_info.append(
                        {"title": entry.title, "intranet_href": href, "edit_href": href + "/edit_intranet.html"}
                    )
            # Sort the list
            def intranet_sort(x, y):
                if x["title"] > y["title"]:
                    return 1
                else:
                    return -1

            self._intranets_info = sorted(intranets_info, intranet_sort)
        return self._intranets_info
コード例 #5
0
ファイル: evolve35.py プロジェクト: cguardia/karl
def evolve(site):
    offices = site.get('offices')
    if offices is None:
        return

    for doc in postorder(offices):
        if hasattr(doc, '__custom_acl__'):
            continue

        try:
            ct = get_content_type(doc)
        except:
            continue

        if ct is None:
            continue

        wf = get_workflow(ct, 'security', doc)
        if wf is None:
            continue

        if wf.name != 'intranet-content':
            continue

        print 'Resetting workflow for', model_path(doc)
        wf.reset(doc)

    _reindex(offices)
コード例 #6
0
def intranets_info(context, request):
    """Get information for the footer and intranets listing"""
    intranets_info = []
    intranets = find_intranets(context)
    if intranets:
        intranets_url = resource_url(intranets, request)
        for name, entry in intranets.items():
            try:
                content_iface = get_content_type(entry)
            except ValueError:
                continue
            if content_iface == ICommunity:
                if not has_permission('view', entry, request):
                    continue
                href = '%s%s/' % (intranets_url, quote_path_segment(name))
                intranets_info.append({
                        'title': entry.title,
                        'intranet_href': href,
                        'edit_href': href + '/edit_intranet.html',
                        })
        # Sort the list
        def intranet_sort(x, y):
            if x['title'] > y['title']:
                return 1
            else:
                return -1
        intranets_info.sort(intranet_sort)
    return intranets_info
コード例 #7
0
ファイル: mvcontent.py プロジェクト: lslaz1/karl
def move_content(root, src, dst, wf_state):
    try:
        context = find_resource(root, src)
    except KeyError:
        print >> sys.stderr, "Source content not found: %s" % src
        sys.exit(-1)

    try:
        dest_folder = find_resource(root, dst)
    except KeyError:
        print >> sys.stderr, "Destination folder not found: %s" % dst
        sys.exit(-1)

    src_community = find_community(context)

    catalog = find_catalog(root)
    assert catalog is not None
    users = find_users(root)
    assert users is not None

    if src_community is not None:
        move_header = ('<p><em>This was originally authored '
                       'in the "%s" community.</em></p>' % src_community.title)
    else:
        move_header = ''

    src_folder = context.__parent__
    name = context.__name__

    log.info("Moving %s", resource_path(context))
    for obj in postorder(context):
        if hasattr(obj, 'docid'):
            docid = obj.docid
            catalog.document_map.remove_docid(docid)
            catalog.unindex_doc(docid)
    del src_folder[name]

    if (context.creator != 'admin'
            and users.get_by_id(context.creator) is None):
        # give the entry to the system admin
        log.warning("User %s not found; reassigning to admin", context.creator)
        context.creator = 'admin'

    if name in dest_folder:
        name = make_unique_name(dest_folder, context.title)

    dest_folder[name] = context
    for obj in postorder(context):
        if hasattr(obj, 'docid'):
            docid = obj.docid
            catalog.document_map.add(resource_path(obj), docid)
            catalog.index_doc(docid, obj)

    if wf_state is not None:
        wf = get_workflow(get_content_type(context), 'security', context)
        wf.transition_to_state(context, None, wf_state)

    if hasattr(context, 'text'):
        context.text = "%s\n%s" % (move_header, context.text)
コード例 #8
0
ファイル: acl.py プロジェクト: 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)
コード例 #9
0
ファイル: acl.py プロジェクト: 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)
コード例 #10
0
 def test_get_content_type_withcontent(self):
     self._setupContentTypes()
     from repoze.lemonade.tests.fixtureapp import content
     from repoze.lemonade.content import get_content_type
     from zope.interface import implements
     class Fred:
         implements(content.IBar)
     fred = Fred()
     type = get_content_type(fred)
     self.assertEqual(type, content.IBar)
コード例 #11
0
ファイル: test_content.py プロジェクト: py361/repoze.lemonade
    def test_get_content_type_withcontent(self):
        self._setupContentTypes()
        from repoze.lemonade.tests.fixtureapp import content
        from repoze.lemonade.content import get_content_type
        from zope.interface import implements

        class Fred:
            implements(content.IBar)

        fred = Fred()
        type = get_content_type(fred)
        self.assertEqual(type, content.IBar)
コード例 #12
0
ファイル: contentfeeds.py プロジェクト: hathawsh/karl
def _getInfo(profile, content):
    community = context = find_community(content)
    if context is None:
        # try for content inside a profile
        context = find_interface(content, IProfile)
    if context is None:
        context_name = context_url = None
    else:
        context_name = context.title
        context_url = resource_path(context)
    tagger = find_tags(content)
    if tagger is not None:
        cloud = list(tagger.getCloud(items=(content.docid,)))
        tag_counts = sorted(cloud, key=lambda x: x[1], reverse=True)[:3]
        tags = [x[0] for x in tag_counts]
    else:
        tags = ()
    content_type = get_content_type(content)
    desc = getattr(content, "description", "")
    short = len(desc) > 80 and "%s..." % desc[:80] or desc
    if IPosts.providedBy(content):
        comment_count = len(content.get("comments", ()))
    else:
        comment_count = False
    content_creator = profile.__name__
    if IComment.providedBy(content):
        # my content filter needs to know if a comment was made inside my post
        content_creator = content.__parent__.__parent__.creator
    return {
        "content_type": content_type.getTaggedValue("name"),
        "userid": profile.__name__,
        "context_name": context_name,
        "context_url": context_url,
        "content_creator": content_creator,
        "url": resource_path(content),
        "title": content.title,
        "description": desc,
        "short_description": short,
        "allowed": principals_allowed_by_permission(content, "view"),
        "comment_count": comment_count,
        "tags": tags,  # XXX
        "author": profile.title,
        "profile_url": "/profiles/%s" % profile.__name__,
        "thumbnail": "/profiles/%s/profile_thumbnail" % profile.__name__,
        "timestamp": _NOW(),
    }
コード例 #13
0
ファイル: contentfeeds.py プロジェクト: iotest3/new
def _getInfo(profile, content):
    community = context = find_community(content)
    if context is None:
        # try for content inside a profile
        context = find_interface(content, IProfile)
    if context is None:
        context_name = context_url = None
    else:
        context_name = context.title
        context_url = resource_path(context)
    tagger = find_tags(content)
    if tagger is not None:
        cloud = list(tagger.getCloud(items=(content.docid,)))
        tag_counts = sorted(cloud, key=lambda x: x[1], reverse=True)[:3]
        tags = [x[0] for x in tag_counts]
    else:
        tags = ()
    content_type = get_content_type(content)
    desc = getattr(content, 'description', '')
    short = len(desc) > 256 and '%s...' % desc[:256] or desc
    if IPosts.providedBy(content):
        comment_count = len(content.get('comments', ()))
    else:
        comment_count = False
    content_creator = profile.__name__
    if IComment.providedBy(content):
        # my content filter needs to know if a comment was made inside my post
        content_creator = content.__parent__.__parent__.creator
    return {'content_type': content_type.getTaggedValue('name'),
            'userid': profile.__name__,
            'context_name': context_name,
            'context_url': context_url,
            'content_creator': content_creator,
            'url': resource_path(content),
            'title': content.title,
            'description': desc,
            'short_description': short,
            'allowed':
                principals_allowed_by_permission(content, 'view'),
            'comment_count': comment_count,
            'tags': tags,                 #XXX
            'author': profile.title,
            'profile_url': '/profiles/%s' % profile.__name__,
            'thumbnail': '/profiles/%s/profile_thumbnail' % profile.__name__,
            'timestamp': _NOW(),
           }
コード例 #14
0
ファイル: workflow.py プロジェクト: lslaz1/karl
def reset_security_workflow(root, output=None):
    count = 0
    for node in postorder(root):
        if IContent.providedBy(node):
            if has_custom_acl(node):
                continue  # don't mess with objects customized via edit_acl
            content_type = get_content_type(node)
            workflow = get_workflow(content_type, 'security', node)
            if workflow is not None:
                try:
                    state, msg = workflow.reset(node)
                except:
                    if output is not None:
                        output('Error while resetting %s' % resource_path(node))
                    raise
                if output is not None:
                    if msg:
                        output(msg)
                count += 1
    if output is not None:
        output('updated %d content objects' % count)
コード例 #15
0
ファイル: textindex.py プロジェクト: iotest3/new
def _get_content_params(obj):
    community = find_community(obj)
    if community is not None:
        community = getattr(community, 'docid', None)

    try:
        content_type = get_content_type(obj)
        content_type = content_type.getName()
    except ValueError:
        content_type = obj.__class__.__name__

    try:
        creation_date = obj.created.isoformat()
    except AttributeError:
        creation_date = None

    try:
        modification_date = obj.modified.isoformat()
    except AttributeError:
        modification_date = None

    return [community, content_type, creation_date, modification_date]
コード例 #16
0
ファイル: textindex.py プロジェクト: karlproject/karl
def _get_content_params(obj):
    community = find_community(obj)
    if community is not None:
        community = getattr(community, 'docid', None)

    try:
        content_type = get_content_type(obj)
        content_type = content_type.getName()
    except ValueError:
        content_type = obj.__class__.__name__

    try:
        creation_date = obj.created.isoformat()
    except AttributeError:
        creation_date = None

    try:
        modification_date = obj.modified.isoformat()
    except AttributeError:
        modification_date = None

    return [community, content_type, creation_date, modification_date]
コード例 #17
0
def reset_security_workflow(root, output=None):
    count = 0
    for node in postorder(root):
        if IContent.providedBy(node):
            if has_custom_acl(node):
                continue  # don't mess with objects customized via edit_acl
            content_type = get_content_type(node)
            workflow = get_workflow(content_type, 'security', node)
            if workflow is not None:
                try:
                    state, msg = workflow.reset(node)
                except:
                    if output is not None:
                        output('Error while resetting %s' %
                               resource_path(node))
                    raise
                if output is not None:
                    if msg:
                        output(msg)
                count += 1
    if output is not None:
        output('updated %d content objects' % count)
コード例 #18
0
def get_content_type_name_and_icon(resource):
    content_iface = get_content_type(resource)
    return (content_iface.getTaggedValue('name'),
            content_iface.queryTaggedValue('icon', 'blue-document.png'))
コード例 #19
0
def get_content_type_name(resource):
    content_iface = get_content_type(resource)
    return content_iface.getTaggedValue('name')
コード例 #20
0
ファイル: utils.py プロジェクト: hj91/karl
def get_content_type_name_and_icon(resource):
    content_iface = get_content_type(resource)
    return (content_iface.getTaggedValue('name'),
            content_iface.queryTaggedValue('icon', 'blue-document.png'))
コード例 #21
0
ファイル: utils.py プロジェクト: hj91/karl
def get_content_type_name(resource):
    content_iface = get_content_type(resource)
    return content_iface.getTaggedValue('name')
コード例 #22
0
ファイル: mvcontent.py プロジェクト: lslaz1/karl
def move_content(root, src, dst, wf_state):
    try:
        context = find_resource(root, src)
    except KeyError:
        print >>sys.stderr, "Source content not found: %s" % src
        sys.exit(-1)

    try:
        dest_folder = find_resource(root, dst)
    except KeyError:
        print >>sys.stderr, "Destination folder not found: %s" % dst
        sys.exit(-1)

    src_community = find_community(context)

    catalog = find_catalog(root)
    assert catalog is not None
    users = find_users(root)
    assert users is not None

    if src_community is not None:
        move_header = ('<p><em>This was originally authored '
                       'in the "%s" community.</em></p>' %
                       src_community.title)
    else:
        move_header = ''

    src_folder = context.__parent__
    name = context.__name__

    log.info("Moving %s", resource_path(context))
    for obj in postorder(context):
        if hasattr(obj, 'docid'):
            docid = obj.docid
            catalog.document_map.remove_docid(docid)
            catalog.unindex_doc(docid)
    del src_folder[name]

    if (context.creator != 'admin'
            and users.get_by_id(context.creator) is None):
        # give the entry to the system admin
        log.warning(
            "User %s not found; reassigning to admin", context.creator)
        context.creator = 'admin'

    if name in dest_folder:
        name = make_unique_name(dest_folder, context.title)

    dest_folder[name] = context
    for obj in postorder(context):
        if hasattr(obj, 'docid'):
            docid = obj.docid
            catalog.document_map.add(resource_path(obj), docid)
            catalog.index_doc(docid, obj)

    if wf_state is not None:
        wf = get_workflow(get_content_type(context), 'security', context)
        wf.transition_to_state(context, None, wf_state)

    if hasattr(context, 'text'):
        context.text = "%s\n%s" % (move_header, context.text)