Esempio n. 1
0
def newest_feed_items(context, request):

    principals, created_by = _get_criteria(request)
    events = find_events(context)

    # Check to see if we're asking for most recent
    newer_than = request.params.get('newer_than')

    if newer_than:
        last_gen, last_index = newer_than.split(':')
        last_gen = long(last_gen)
        last_index = int(last_index)
        latest = list(events.newer(last_gen, last_index,
                                   principals, created_by))
    else:
        last_gen = -1L
        last_index = -1
        latest = list(islice(events.checked(principals, created_by), 20))

    if not latest:
        return (last_gen, last_index, last_gen, last_index, ())

    last_gen, last_index, ignored = latest[0]
    earliest_gen, earliest_index, ignored = latest[-1]

    feed_items = _update_feed_items(latest, request.application_url)

    return last_gen, last_index, earliest_gen, earliest_index, feed_items
Esempio n. 2
0
def user_tagged_content(event):
    if ITagAddedEvent.providedBy(event):
        request = get_current_request()
        context = getattr(request, 'context', None)
        if context is None:
            return
        events = find_events(context)
        if not events:
            return
        site = find_site(context)
        catalog = find_catalog(context)
        path = catalog.document_map.address_for_docid(event.item)
        tagged = find_model(site, path)
        if tagged is None:
            return
        profile_id = event.user
        if profile_id in (None, 'None'):
            return
        profile = site['profiles'][profile_id]
        info = _getInfo(profile, tagged)
        if info is None:
            return
        if info['content_type'] == 'Community':
            info['flavor'] = 'tagged_community'
        elif info['content_type'] == 'Profile':
            info['flavor'] = 'tagged_profile'
        else:
            info['flavor'] = 'tagged_other'
        info['operation'] = 'tagged'
        info['tagname'] = event.name
        events.push(**info)
Esempio n. 3
0
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
           }
Esempio n. 4
0
def user_left_community(event):
    if IUserRemovedGroup.providedBy(event):
        delta = event.old_groups - event.groups
        left = [x for x in delta if x.startswith(MEMBER_PREFIX)]
        events = find_events(event.site)
        if not events or not left:
            return
        profile = event.site['profiles'][event.id]
        for group in left:
            community_id, gtype = group[len(MEMBER_PREFIX):].split(':')
            if gtype == 'members':
                community = event.site.communities().get(community_id)
                if community is None:
                    continue
                info = _getInfo(profile, community)
                info['flavor'] = 'joined_left'
                info['operation'] = 'left'
                events.push(**info)
Esempio n. 5
0
def user_modified_content(modified, event):
    if IObjectModifiedEvent.providedBy(event):
        events = find_events(modified)
        if not events:
            return
        site = find_site(modified)
        profile_id = getattr(modified, 'modified_by', None)
        if profile_id in (None, 'None'):
            return
        profile = site['profiles'][profile_id]
        info = _getInfo(profile, modified)
        if info is None:
            return
        if info['content_type'] == 'Community':
            info['flavor'] = 'added_edited_community'
        elif info['content_type'] == 'Profile':
            info['flavor'] = 'added_edited_profile'
        else:
            info['flavor'] = 'added_edited_other'
        info['operation'] = 'edited'
        events.push(**info)
Esempio n. 6
0
def user_added_content(added, event):
    log.debug('user_added_content: added=%s, event=%s' % (str(added), event))
    if IObjectAddedEvent.providedBy(event):
        events = find_events(added)
        if not events:
            return
        site = find_site(added)
        profile_id = getattr(added, 'creator', None)
        if profile_id in (None, 'None', ''):
            return
        profile = site['profiles'][profile_id]
        info = _getInfo(profile, added)
        if info is None:
            return
        log.debug("user_added_content: info['content_type']=%s" % info['content_type'])
        if info['content_type'] == 'Community':
            info['flavor'] = 'added_edited_community'
        elif info['content_type'] == 'Profile':
            info['flavor'] = 'added_edited_profile'
        else:
            info['flavor'] = 'added_edited_other'
        info['operation'] = 'added'
        events.push(**info)
Esempio n. 7
0
def older_feed_items(context, request):
    older_than = request.params.get('older_than')

    # If we don't have params, bail out.
    if older_than is None:
        return -1, -1, ()

    principals, created_by = _get_criteria(request)
    events = find_events(context)

    earliest_gen, earliest_index = older_than.split(':')
    earliest_gen = long(earliest_gen)
    earliest_index = int(earliest_index)
    older = list(islice(events.older(earliest_gen, earliest_index,
                                principals, created_by), 20))

    if not older:
        return (earliest_gen, earliest_index, ())

    earliest_gen, earliest_index, ignored = older[-1]

    feed_items = _update_feed_items(older, request.application_url)

    return earliest_gen, earliest_index, feed_items