def friendly_type_name(obj): """Index for the friendly name of any content type. :param obj: The Plone content object to index :type obj: IContentish :return: Friendly content type name :rtype: str """ default_name = obj.Type() # If the object is a file get the friendly name of the mime type if IFile.providedBy(obj): mtr = api.portal.get_tool(name='mimetypes_registry') primary_field_info = IPrimaryFieldInfo(obj) if not primary_field_info.value: return default_name if hasattr(primary_field_info.value, 'contentType'): contenttype = primary_field_info.value.contentType try: mimetypeitem = mtr.lookup(contenttype) except MimeTypeException as msg: logger.warn('mimetype lookup failed for %s. Error: %s', obj.absolute_url(), str(msg)) return default_name mimetype_name = mimetypeitem[0].name() if mimetype_name != contenttype: return mimetype_name elif IUserProfile.providedBy(obj): return 'Person' return default_name
def get_statusupdates(self): ''' This will return all the StatusUpdates which are not comments The activity are sorted by reverse chronological order ''' container = piapi.microblog.get_microblog() if self.microblog_context: # support ploneintranet.workspace integration statusupdates = container.context_values( self.microblog_context, limit=self.count, tag=self.tag ) elif IUserProfile.providedBy(self.context): # Get the updates for this user statusupdates = container.user_values( self.context.username, limit=self.count, tag=self.tag ) else: # default implementation statusupdates = container.values( limit=self.count, tag=self.tag ) statusupdates = self.filter_statusupdates(statusupdates) return statusupdates
def get_statusupdates(self): ''' This will return all the StatusUpdates which are not comments The activity are sorted by reverse chronological order ''' container = piapi.microblog.get_microblog() post_id = self.request.get('post_id') if post_id: try: return [container.get(post_id)] except KeyError: return [] if self.microblog_context: # support ploneintranet.workspace integration statusupdates = container.context_values( self.microblog_context, max=self.next_max, limit=self.count, ) elif IUserProfile.providedBy(self.context): # Get the updates for this user statusupdates = container.user_values( self.context.username, max=self.next_max, limit=self.count, ) elif self.stream_filter == 'network': # Only activities from people and things I follow graph = api.portal.get_tool("ploneintranet_network") users = graph.unpack(graph.get_following(u'user')) users.append(api.user.get_current().id) # show own updates also tags = graph.unpack(graph.get_following(u'tag')) statusupdates = container.values(max=self.next_max, limit=self.count, users=users, tags=tags) elif self.stream_filter == 'content': # show only content updates and replies to those statusupdates = container.is_content_values( max=self.next_max, limit=self.count, ) elif self.stream_filter == 'human': # exclude auto-created content updates without replies statusupdates = container.is_human_values( max=self.next_max, limit=self.count, ) elif self.stream_filter in ('interactions', 'posted', 'likes'): raise NotImplementedError("unsupported stream filter: %s" % self.stream_filter) else: # default implementation: all activities statusupdates = container.values(max=self.next_max, limit=self.count, tags=self.tag) return statusupdates
def get_statusupdates(self): ''' This will return all the StatusUpdates which are not comments The activity are sorted by reverse chronological order ''' container = piapi.microblog.get_microblog() stream_filter = self.request.get('stream_filter') if self.microblog_context: # support ploneintranet.workspace integration statusupdates = container.context_values(self.microblog_context, max=self.next_max, limit=self.count, tag=self.tag) elif IUserProfile.providedBy(self.context): # Get the updates for this user statusupdates = container.user_values(self.context.username, max=self.next_max, limit=self.count, tag=self.tag) elif stream_filter == 'network': # Only activities from people I follow graph = api.portal.get_tool("ploneintranet_network") userid = api.user.get_current().id following = graph.unpack(graph.get_following(u'user', userid)) following.append(userid) # show own updates, as well statusupdates = container.user_values(following, max=self.next_max, limit=self.count, tag=self.tag) elif stream_filter in ('interactions', 'posted', 'likes'): raise NotImplementedError("unsupported stream filter: %s" % stream_filter) else: # default implementation: all activities statusupdates = container.values(max=self.next_max, limit=self.count, tag=self.tag) statusupdates = self.filter_statusupdates(statusupdates) return statusupdates
def friendly_type_name(obj): """ Index for the friendly name of any content type :param obj: The Plone content object to index :type obj: IContentish :return: Friendly content type name :rtype: str """ default_name = obj.Type() # If the object is a file get the friendly name of the mime type if IFile.providedBy(obj): mtr = api.portal.get_tool(name='mimetypes_registry') primary_field_info = IPrimaryFieldInfo(obj) if not primary_field_info.value: return default_name if hasattr(primary_field_info.value, "contentType"): contenttype = primary_field_info.value.contentType try: mimetypeitem = mtr.lookup(contenttype) except MimeTypeException as msg: logger.warn( 'mimetype lookup failed for %s. Error: %s', obj.absolute_url(), str(msg) ) return default_name mimetype_name = mimetypeitem[0].name() if mimetype_name != contenttype: return mimetype_name elif IUserProfile.providedBy(obj): return 'Person' return default_name