def count(node): from repoze.bfg.traversal import model_path if IWikiPage.providedBy(node): stats['wiki_pages'] += 1 elif IBlogEntry.providedBy(node): stats['blog_entries'] += 1 elif IComment.providedBy(node): stats['comments'] += 1 elif ICommunityFile.providedBy(node): stats['files'] += 1 elif ICalendarEvent.providedBy(node): stats['calendar_events'] += 1 created = getattr(node, 'created', None) if created is not None and now - created < THIRTY_DAYS: creator = getattr(node, 'creator', None) if creator is not None: if creator not in active_users: active_users[creator] = 1 else: active_users[creator] += 1 if hasattr(node, '__getitem__') and hasattr(node, 'values'): for child in node.values(): count(child) if hasattr(node, '_p_deactivate'): node._p_deactivate()
def count(node): from pyramid.traversal import resource_path if IWikiPage.providedBy(node): stats['wiki_pages'] += 1 elif IBlogEntry.providedBy(node): stats['blog_entries'] += 1 elif IComment.providedBy(node): stats['comments'] += 1 elif ICommunityFile.providedBy(node): stats['files'] += 1 elif ICalendarEvent.providedBy(node): stats['calendar_events'] += 1 created = getattr(node, 'created', None) if created is not None and now - created < THIRTY_DAYS: creator = getattr(node, 'creator', None) if creator is not None: if creator not in active_users: active_users[creator] = 1 else: active_users[creator] += 1 if hasattr(node, '__getitem__') and hasattr(node, 'values'): for child in node.values(): count(child) if hasattr(node, '_p_deactivate'): node._p_deactivate()
def url(self): if self._url is None: if IComment.providedBy(self.context): # show the comment in context of its grandparent. # (its parent is a comments folder.) parent = self.context.__parent__.__parent__ self._url = "%s#comment-%s" % (resource_url(parent, self.request), self.context.__name__) else: self._url = resource_url(self.context, self.request) return self._url
def url(self): if self._url is None: if IComment.providedBy(self.context): # show the comment in context of its grandparent. # (its parent is a comments folder.) parent = self.context.__parent__.__parent__ self._url = '%s#comment-%s' % (resource_url( parent, self.request), self.context.__name__) else: self._url = resource_url(self.context, self.request) return self._url
def __init__(self, context, profile, request): super(CommentAlert, self).__init__(context, profile, request) assert IComment.providedBy(context) self.alert = None if find_interface(self.context, IBlogEntry) or find_interface(context, IForumTopic): # noqa # it is a blog alert self.alert = CommentBlogEntryAlert(self.context, self.profile, self.request) else: if find_interface(self.context, ICommunityFile): self.alert = CommunityFileCommentAlert(self.context, self.profile, self.request)
def __init__(self, context, profile, request): super(CommentAlert, self).__init__(context, profile, request) assert IComment.providedBy(context) self.alert = None if find_interface(self.context, IBlogEntry) or find_interface( context, IForumTopic): # noqa # it is a blog alert self.alert = CommentBlogEntryAlert(self.context, self.profile, self.request) else: if find_interface(self.context, ICommunityFile): self.alert = CommunityFileCommentAlert(self.context, self.profile, self.request)
def visit(self, context): if ICommunity.providedBy(context): self.community = context self.row = { 'community': context.title, 'id': context.__name__, 'is_private': is_private(context), 'members': len(context.member_names), 'moderators': len(context.moderator_names), 'last_activity': context.content_modified, 'create_date': context.created, 'wiki_pages': 0, 'blog_entries': 0, 'blog_comments': 0, 'files': 0, 'calendar_events': 0, 'community_tags': set(), 'hits_this_month': 'Unknown', 'percent_engaged': 'Unknown' } elif self.community is None: return else: last_activity = getattr(context, 'content_modified', None) if (last_activity is not None and last_activity > self.row['last_activity']): self.row['last_activity'] = last_activity if IWikiPage.providedBy(context): self.row['wiki_pages'] += 1 elif IBlogEntry.providedBy(context): self.row['blog_entries'] += 1 elif IComment.providedBy(context): self.row['blog_comments'] += 1 elif ICommunityFile.providedBy(context): self.row['files'] += 1 elif ICalendarEvent.providedBy(context): self.row['calendar_events'] += 1 tags = find_tags(context) docid = getattr(context, 'docid', None) if docid is not None: for tag in tags.getTags([docid,]): self.row['community_tags'].add(tag)
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(), }
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(), }
def __init__(self, context, profile, request): super(BlogCommentAlert, self).__init__(context, profile, request) assert IComment.providedBy(context)
def __init__(self, context, profile, request): BlogAlert.__init__(self, context, profile, request) assert IComment.providedBy(context)