def __init__(self, profile, eventinfo): super(CommentAlert, self).__init__(profile, eventinfo) assert IComment.providedBy(self.content) self._mfrom = self.sent_from if find_interface(self.content, IProfile): # set the community to profile for now self._template = "templates/email_profile_comment_alert.pt" self.is_profile_alert = True
def status_response(self, msg): location = model_url(self.parent, self.request) if IComment.providedBy(self.context): # for comment replies we need the location of the real container # like forum topic or profile or community log.debug('commenting status_response: reply context=%s, grandparent=%s' % (self.context, self.parent.__parent__)) location = model_url(self.parent.__parent__, self.request) location = '%s?status_message=%s' % (location, urllib.quote(msg)) return HTTPFound(location=location)
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 }
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' % ( model_url(parent, self.request), self.context.__name__) else: self._url = model_url(self.context, self.request) return self._url
def is_reply(self): return IComment.providedBy(self.__parent__.__parent__)