class ProfileView(PageletDisplayForm):

    mode = DISPLAY_MODE

    def getContent(self):
        return self.profile.getProfileData()

    def updateForms(self):
        super(ProfileView, self).updateForms()
        ids = getUtility(IIntIds)
        fields = getUtility(IProfileFields).getFields()

        content = self.profile.getProfileData()
        category = getUtility(IProfilesCategory)
        quickInfo = category.quickInfoFields
        fieldCategories = category.fieldCategories

        default = []
        categories = {}
        for field in fields:
            name = field.__name__
            if not field.visible or ids.getId(field) in quickInfo:
                continue

            value = content.get(name, field.missing_value)
            if value is field.missing_value or value is None:
                continue

            if field.category not in fieldCategories:
                default.append(field)
            else:
                categories.setdefault(field.category, []).append(field)

        self.groups = list(self.groups)

        if default:
            group = Category(self.context, self.request, self, u'', default)
            group.update()
            self.groups.append(group)

        for key in fieldCategories:
            if key not in categories:
                continue
            fields = categories[key]
            if fields:
                group = Category(self.context, self.request, self, key, fields)
                group.update()
                self.groups.append(group)

    def update(self):
        self.profile = IPersonalProfile(self.context.__principal__)
        self.title = self.profile.title
        self.photoUrl = self.profile.photoUrl(self.request)

        super(ProfileView, self).update()
Exemple #2
0
    def getMemberInfo(self, id):
        member = self.context[id]

        try:
            principal = self.auth.getPrincipal(member.__name__)
        except PrincipalLookupError:
            principal = None

        try:
            profile = IPersonalProfile(principal)
        except:
            return

        image = profile.profileImage
        if image and IImage.providedBy(image):
            w, h = image.width, image.height
            if w > 128:
                xscale = 128.0/w
            else:
                xscale = 1.0
            if h > 128:
                yscale = 120.0/h
            else:
                yscale = 1.0
            scale = xscale < yscale and xscale or yscale
            image = (int(round(w*scale)), int(round(h*scale)))
            default = False
        else:
            image = (128, 97)
            default = True

        info = {
            'id': id,
            'title': getattr(profile, 'title', _(u'Unknown')),
            'description': getattr(principal, 'description', u''),
            'manager': u'',
            'personalspace': u'',
            'joined': member.joined,
            'imagex': image[0],
            'imagey': image[1],
            'default': default,
            'photo': profile.photoUrl(self.request)}

        space = profile.space
        if space is not None:
            info['manager'] = space.title
            info['personalspace'] = absoluteURL(space, self.request)

        return info
Exemple #3
0
    def getMemberInfo(self, hf):
        if IPersonalSpace.providedBy(hf):
            principal = hf.principal
        else:
            principal = getattr(IOwnership(hf, None), 'owner', None)
            if principal is None:
                return
        try:
            profile = IPersonalProfile(principal)
        except TypeError:
            return

        image = profile.profileImage
        if IImage.providedBy(image) and image:
            w, h = image.width, image.height
            if w > 128:
                xscale = 128.0/w
            else:
                xscale = 1.0
            if h > 120:
                yscale = 120.0/h
            else:
                yscale = 1.0
            scale = xscale < yscale and xscale or yscale
            image = (int(round(w*scale)), int(round(h*scale)))
            default = False
        else:
            image = (128, 98)
            default = True

        info = {
            'id': hf.__name__,
            'title': profile.title,
            'description': principal.description,
            'manager': hf.title,
            'joined': profile.registered,
            'imagex': image[0],
            'imagey': image[1],
            'default': default,
            'photo': profile.photoUrl(self.request)}
        return info