Python IUserProfile Example

说明

python iuserprofile示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Python

命名空间/包名称: ploneintranetuserprofilecontentuserprofile

示例#1
文件: stream.py项目: mingtak/ploneintranet

    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

示例#2
文件: indexers.py项目: smcmahon/ploneintranet

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

展开阅读全文