示例#1
0
    def listMessages(self):
        service = self.context
        request = self.request
        getPrincipal = getUtility(IAuthentication).getPrincipal

        for msgId in service:
            message = service.get(msgId)

            try:
                sender = getPrincipal(message.sender)
            except PrincipalLookupError:
                sender = None

            title = u''
            avatar = u''
            space = u''

            profile = IPersonalProfile(sender, None)
            if profile is not None:
                avatar = profile.avatarUrl(request)
                title = profile.title

                space = profile.space
                if space is not None:
                    space = '%s/'%absoluteURL(space, request)

            yield {'name': message.__name__,
                   'status': message.__status__,
                   'sender': title.strip(),
                   'profile': space,
                   'date': message.__date__,
                   'title': message.title,
                   'avatar': avatar}
示例#2
0
    def update(self):
        try:
            author = getUtility(IAuthentication).getPrincipal(
                self.context.author)
        except:
            author = None

        if author is not None:
            profile = IPersonalProfile(author)
            self.avatar = profile.avatarUrl(self.request)
            self.author = profile.title

            if profile.space is not None:
                self.url = absoluteURL(profile.space, self.request)
        else:
            self.avatar = u'%s/@@profile.avatar/0'%absoluteURL(
                getSite(), self.request)

        if author is not None or author == u'Unauthenticated User':
            if getattr(self.context, 'authorName'):
                self.author = self.context.authorName
                if 'social_avatar_url' in dir(self.context) and self.context.social_type:
                    self.social_avatar = self.context.social_avatar_url
                    if self.context.social_type==1:
                        self.social_name = 'Twitter'
                    elif self.context.social_type==2:
                        self.social_name = 'Facebook'

        self.comment = self.context.comment

        content = self.context.content
        self.postsAllowed = (
            IContentDiscussion(content).status in [1, 4] and
            checkPermission('zojax.AddComment', content))
示例#3
0
    def update(self):
        topic = self.context
        request = self.request
        formatter = getFormatter(request, 'fancyDatetime', 'medium')

        name = topic.__name__
        owner = IOwnership(topic).owner
        profile = IPersonalProfile(owner)
        space = getattr(profile, 'space', None)

        self.name = name
        self.replies = len(topic)-1
        self.owner = getattr(profile, 'title', '')
        self.avatar = profile is not None and profile.avatarUrl(request) or '#',
        self.personal = '%s/'%(space and absoluteURL(space, request) or '',)

        message = topic.lastMessage

        if message is not None:
            owner = IOwnership(message).owner
            profile = IPersonalProfile(owner, None)
            space = getattr(profile, 'space', None)

            self.lastmessage = {
                'date': formatter.format(IDCTimes(message).modified),
                'owner': getattr(profile, 'title', ''),
                'personal': '%s/'%(space and absoluteURL(space,request) or '',),
                'avatar': profile is not None and profile.avatarUrl(request) or '#',
                'url': '%s/%s/'%(name, message.__name__)}
示例#4
0
    def getMemberInfo(self, id):
        member = self.context[id]

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

        profile = IPersonalProfile(principal, None)
        if profile is None:
            return

        space = profile.space
        if space is None:
            return

        info = {
            'id': principal.id,
            'spaceid': space.__name__,
            'title': profile.title,
            'avatar': profile.avatarUrl(self.request),
            'joined': self.formatter.format(member.joined),
            'approved': member.approved and \
                _('Approved') or _('Not yet approved'),
            }

        return info
示例#5
0
    def listContents(self):
        data = super(ContentRecentContentPortlet, self).listContents()

        request = self.request

        for item in data:
            content = item['content']

            owner = getattr(IOwnership(content, None), 'owner', None)
            if owner is not None:
                profile = IPersonalProfile(owner)
                item['avatar'] = profile.avatarUrl(request)
                item['author'] = profile.title

                space = profile.space
                if space is not None:
                    item['profile'] = '%s/'%absoluteURL(space, request)
                else:
                    item['profile'] = u''
            else:
                item['avatar'] = u''
                item['author'] = u''
                item['profile'] = u''

        return data
 def registerPrincipal(self, principal, data):
     profile = IPersonalProfile(principal, None)
     fields = [field.__name__ for field in self.getFields()]
     if profile is not None:
         data = dict([(key, value)
                      for key, value in data.items() if key in fields])
         profile.setProfileData(data)
         notify(ObjectModifiedEvent(profile))
示例#7
0
    def update(self):
        queryObject = getUtility(IIntIds).queryObject
        self.categories = categories = []
        for uid in self.context.category:
            category = queryObject(uid)
            if category is not None:
                categories.append(category)
        categories.sort(key=attrgetter('title'))
        self.date = IZopeDublinCore(self.context).created
        self.autoplay = str(self.context.autoplay).lower()

        if self.context.mediaSource:
            self.mediaURL = None
        else:
            self.mediaURL = (self.context.mediaData is not None \
                             and self.context.mediaData.data) \
                            and '%s/view.html' % absoluteURL(self.context, self.request) \
                            or (self.context.mediaURL or '')
            if self.context.mediaURLList:
                self.mediaURL = self.context.mediaURLList[0]
                mediaURLList = self.context.mediaURLList
            else:
                mediaURLList = [self.mediaURL]
            urls = map(lambda x: r"""{\'url\':\'%s\', \'autoPlay\': %s}""" % (urllib.quote(x[1]), \
                                                                                 x[0]==0 and self.autoplay or 'true'), \
                                            enumerate(mediaURLList))
            self.mediaURLListEncoded = r"\'playlist\': [%s]" % ','.join(urls)
        discussion = IContentDiscussion(self.context, None)
        self.comments = discussion is not None and len(discussion)
        self.discussible = discussion is not None and discussion.status != 3
        self.addcomment = self.discussible and discussion.status != 2
        self.tags = IContentTags(self.context, None)
        self.tags = self.tags is not None and self.tags.tags or []
        self.url = absoluteURL(self.context, self.request)
        self.space = getSpace(self.context)
        self.container_url = absoluteURL(self.space, self.request)
        self.site_url = absoluteURL(getSite(), self.request)
        owner = IOwnership(self.context).owner
        space = IPersonalSpace(owner, None)
        profile = IPersonalProfile(owner, None)
        # author
        try:
            self.author = '%s %s'%(profile.firstname, profile.lastname)
            self.avatar_url = profile.avatarUrl(self.request)
        except AttributeError:
            self.author = getattr(owner,'title','')
            self.avatar_url = '#'

        if space is not None:
            self.profile_url = '%s/profile/'%absoluteURL(space, self.request)
        self.container_title = self.space.title
        include('jquery-plugins')
示例#8
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
示例#9
0
    def getMemberInfo(self, space):
        principal = space.principal
        if principal is None:
            return

        profile = IPersonalProfile(principal)
        avatar = profile.avatarUrl(self.request)

        info = {
            'id': principal.id,
            'spaceid': space.__name__,
            'title': profile.title,
            'avatar': avatar,
            'member': self.context.isMember(principal.id)}
        return info
示例#10
0
    def update(self):
        context = self.context
        request = self.request

        profile = IPersonalProfile(context, None)
        if profile is not None:
            space = profile.space
    
            if space:
                self.profile = '%s/'%absoluteURL(space, request)
    
            self.title = profile.title
            self.avatar = profile.avatarUrl(request)
        else:
            self.title = _(u'Unknown')
示例#11
0
    def update(self):
        super(AcknowledgementAddedNotification, self).update()

        context = self.context
        object = removeSecurityProxy(context.object)

        try:
            principal = getPrincipal(context.principal)
        except PrincipalLookupError:
            principal = ''

        profile = IPersonalProfile(principal, None)

        datetime = ''
        if context.date:
            datetime = context.date.strftime('%Y-%m-%d %H:%M UTC')

        self.info = {
            'title': object.title,
            'user': getattr(profile, 'title', 'NO NAME'),
            'datetime': datetime,
            'url': '%s/' % absoluteURL(
                object,
                self.request).replace('/++skin++JSONRPC.acknowledgement', '')
        }
示例#12
0
    def __call__(self, nextURL):
        profile = IPersonalProfile(self.principal)

        if not profile.isComplete() and checkPermission('zojax.PersonalSpace', getSite()):
            if profile.firstname and profile.lastname:
                profile.modified = parseDatetimetz(str(datetime.datetime.now()))

            space = profile.space
            if space is not None:
                self.request.response.redirect(
                    u'%s/profile/profile/'%absoluteURL(space, self.request))

                IStatusMessage(self.request).add(
                    _('You successfully logged in to portal. Please complete your profile.'))

                return True

        return False
示例#13
0
 def getUser(self, uid):
     principal = getPrincipal(uid)
     try:
         profile = IPersonalProfile(principal)
         return dict(title=profile.title,
                     url=profile.space is not None
                     and u'%s/' % absoluteURL(profile.space, self.request))
     except TypeError:
         return dict(title='Deleted Member', url='#')
示例#14
0
    def update(self):
        request = self.request
        context = self.context

        profile = IPersonalProfile(context)

        self.author = profile.title
        self.avatar = profile.avatarUrl(request)

        space = profile.space
        if space is not None:
            self.profile = '%s/'%absoluteURL(space, request)
        else:
            self.profile = None

        self.content = profile.getProfileData()

        super(PrincipalView, self).update()
示例#15
0
    def update(self):
        self.date = IZopeDublinCore(self.context).created
        self.site_url = absoluteURL(getSite(), self.request)
        self.space = getSpace(self.context)
        owner = IOwnership(self.context).owner
        space = IPersonalSpace(owner, None)
        profile = IPersonalProfile(owner, None)
        self.container_url = absoluteURL(self.space, self.request)
        # author
        try:
            self.author = '%s %s'%(profile.firstname, profile.lastname)
            self.avatar_url = profile.avatarUrl(self.request)
        except AttributeError:
            self.author = getattr(owner,'title','')
            self.avatar_url = '#'

        if space is not None:
            self.profile_url = '%s/profile/'%absoluteURL(space, self.request)
        self.container_title = self.space.title
示例#16
0
    def query(self, default=None):
        principal = self.getPrincipal(self.content)

        if principal is not None:
            request = self.request
            profile = IPersonalProfile(principal)

            info = {'avatar': profile.avatarUrl(request),
                    'title': profile.title,
                    'profile': ''}

            space = profile.space
            if space is not None:
                info['profile'] = '%s/'%absoluteURL(space, request)

            return info
        return {'avatar': '',
                'title': _('Unknown'),
                'profile': ''}
示例#17
0
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()
示例#18
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
示例#19
0
    def query(self, default=None):
        forum = self.content
        url = absoluteURL(self.context, self.request)
        siteUrl = absoluteURL(getSite(), self.request)
        formatter = getFormatter(self.request, 'fancyDatetime', 'medium')

        topic = forum.lastTopic
        if topic is not None:
            message = topic.lastMessage
            owner = IOwnership(message).owner
            profile = IPersonalProfile(owner)
            space = profile.space

            return {
                'date': formatter.format(
                    ICMFDublinCore(message).modified),
                'owner': profile.title,
                'profile': '%s/'%(space is not None and absoluteURL(space, self.request) or siteURL),
                'avatar': profile.avatarUrl(self.request),
                'title': topic.title,
                'url': '%s/%s/%s/%s/'%(
                    url, forum.__name__, topic.__name__, message.__name__)}
    def update(self):
        record = self.context
        request = self.request

        content = record.object
        formatter = getFormatter(request, 'humanDatetime', 'medium')

        view = queryMultiAdapter((content, request), IContentViewView)
        try:
            if view is not None:
                url = '%s/%s'%(absoluteURL(content, request), view.name)
            else:
                url = '%s/'%absoluteURL(content, request)
        except:
            url = u''

        self.url = url
        self.title = getattr(content, 'title', content.__name__)
        self.description = getattr(content, 'description', u'')
        self.date = formatter.format(record.date)
        self.content = content

        auth = getUtility(IAuthentication)
        try:
            principal = auth.getPrincipal(record.principal)
        except:
            principal = None

        if principal is not None:
            profile = IPersonalProfile(principal)
            self.avatar = profile.avatarUrl(request)
            self.author = profile.title

            space = profile.space
            if space is not None:
                self.profile = '%s/'%absoluteURL(space, request)
        else:
            self.author = _('Unknown')
示例#21
0
    def update(self):
        context = self.context
        while not IProfileWorkspace.providedBy(context):
            context = context.__parent__

        self.workspace = context
        self.profile = IPersonalProfile(context.__principal__)
        self.content = self.profile.getProfileData()

        self.timezone = self.profile.timezone
        self.registered = self.profile.registered
        self.lastLoginTime = self.profile.lastLoginTime

        super(QuickInfo, self).update()
示例#22
0
    def getMemberInfo(self, id):
        member = self.context[id]

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

        profile = IPersonalProfile(principal, None)
        if profile is None:
            return

        space = profile.space
        if space is None:
            return

        info = {
            'id': principal.id,
            'spaceid': space.__name__,
            'title': profile.title,
            'avatar': profile.avatarUrl(self.request),
            'member': self.context.isMember(principal.id)}
        return info
示例#23
0
    def getMemberInfo(self, id):
        try:
            principal = self.auth.getPrincipal(id)
        except PrincipalLookupError:
            return

        profile = IPersonalProfile(principal)

        space = profile.space
        if space is not None:
            space = u"%s/profile/" % absoluteURL(space, self.request)

        info = {"id": principal.id, "space": space, "title": profile.title, "avatar": profile.avatarUrl(self.request)}
        return info
示例#24
0
    def update(self):
        context = self.context
        request = self.request

        principal = context.principal

        if principal.id != request.principal.id:
            profile = IPersonalProfile(principal)
            self.principal_title = profile.title

        results = getUtility(IAcknowledgements).search(
            principal={'any_of': (context.principalId,)})

        self.batch = Batch(
            results, size=20, prefix='acknowledgements',
            context=context, request=request)
示例#25
0
    def prepare(self):
        results = getUtility(IAcknowledgements).search(object=self.context)

        acknowledged = [i.principal for i in results]
        allusers = searchPrincipals(
            type=('user',),
            principalSubscribed={'any_of': (True,)})

        members = []
        bannedusers = getUtility(IBanPrincipalConfiglet)
        rolemanager = IPrincipalRoleManager(getSite())
        checkroles = ['zope.Anonymous', ]

        portal_roles = getUtility(IPortalRoles)
        if 'site.member' in portal_roles:
            checkroles.append(portal_roles['site.member'].id)

        for pid in [i.id for i in allusers if i.id not in acknowledged]:
            # Note: skip banned users
            if pid in bannedusers.banned:
                continue

            try:
                principal = getPrincipal(pid)
            except PrincipalLookupError:
                continue

            # Note: skip users with Deny roles
            nextitem = False
            for role, setting in rolemanager.getRolesForPrincipal(pid):
                if role == 'zope.Manager':
                    continue
                if role in checkroles and setting == Deny:
                    nextitem = True
                    break
            if nextitem:
                continue

            profile = IPersonalProfile(principal, None)
            if profile is None:
                continue

            members.append(profile)

        return self.export(members)
示例#26
0
    def prepare(self):
        results = getUtility(IAcknowledgements).search(object=self.context)

        if len(results) > 0:
            members = []
            # localtz = tz.tzlocal()
            bannedusers = getUtility(IBanPrincipalConfiglet)
            rolemanager = IPrincipalRoleManager(getSite())
            checkroles = ['zope.Anonymous', ]

            portal_roles = getUtility(IPortalRoles)
            if 'site.member' in portal_roles:
                checkroles.append(portal_roles['site.member'].id)

            for pid, ack_date in [(i.principal, i.date) for i in results]:
                # Note: skip banned users
                if pid in bannedusers.banned:
                    continue

                try:
                    principal = getPrincipal(pid)
                except PrincipalLookupError:
                    continue

                # Note: skip users with Deny roles
                nextitem = False
                for role, setting in rolemanager.getRolesForPrincipal(pid):
                    if role == 'zope.Manager':
                        continue
                    if role in checkroles and setting == Deny:
                        nextitem = True
                        break
                if nextitem:
                    continue

                profile = IPersonalProfile(principal, None)
                if profile is None:
                    continue
                members.append(
                    (profile, ack_date.strftime('%Y-%m-%d %H:%M UTC')))
                # NOTE: convert date to local time zone
                # .replace(tzinfo=utc).astimezone(localtz).strftime('%Y-%m-%d %H:%M %Z')

            return self.export(members)
示例#27
0
class QuickInfo(PageletDisplayForm):

    @property
    def fields(self):
        content = self.content
        configlet = getUtility(IProfilesCategory)
        ids = getUtility(IIntIds)
        configletFields = configlet['default'].getFields()

        fields = []
        for id in configlet.quickInfoFields:
            field = ids.getObject(id)
            name = field.__name__
            if field in configletFields and field.visible:
                if content.get(name, field.missing_value) is not \
                        field.missing_value:
                    fields.append(field)

        return Fields(*fields)

    def update(self):
        context = self.context
        while not IProfileWorkspace.providedBy(context):
            context = context.__parent__

        self.workspace = context
        self.profile = IPersonalProfile(context.__principal__)
        self.content = self.profile.getProfileData()

        self.timezone = self.profile.timezone
        self.registered = self.profile.registered
        self.lastLoginTime = self.profile.lastLoginTime

        super(QuickInfo, self).update()

    def getContent(self):
        return self.content
示例#28
0
    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()
示例#29
0
    def update(self):
        super(BasePostView, self).update()

        post = removeAllProxies(self.context)
        request = self.request
        owner = IOwnership(post).owner
        profile = IPersonalProfile(owner, None)
        space = getattr(profile, 'space', None)
        profileData = profile.getProfileData()

        self.post = post
        self.postUrl = absoluteURL(post, request)
        self.text = getattr(self.context.text, 'cooked', '')
        self.biography = profileData.get('about', False)
        self.jobtitle = profileData.get('jobtitle', False)
        if self.biography:
            self.biography = re.sub('<[^>]*>', '', self.biography.text)
            if len(self.biography) >= 240:
                self.biography = self.biography[:240].rsplit(' ', 1)[0].strip() + '...'

        # blog
        if IDraftedContent.providedBy(post):
            blog = post.__parent__
            location = blog.getLocation()
            if location is not None:
                blog = location.get('blog')
            else:
                blog = None
        else:
            blog = post.__parent__

        if IBlog.providedBy(blog):
            self.blog = blog
            self.blog_title = blog.title
            self.blog_url = absoluteURL(blog, request)
            self.tags_list = blog['tags'].listTags(post)

        # author
        try:
            self.author = profile.title
            self.avatar_url = profile.avatarUrl(request)
        except AttributeError:
            self.author = getattr(owner, 'title', '')
            self.avatar_url = '#'

        if space is not None:
            self.profile_url = '%s/profile/' % absoluteURL(space, request)

        # discussion
        discussion = IContentDiscussion(post, None)
        self.comments = discussion is not None and len(discussion)
        self.discussible = discussion is not None and discussion.status != 3
        self.footer_discussion = self.discussible and self.comments_num

        # categories
        categories = []
        ids = getUtility(IIntIds)

        for cId in post.category:
            category = ids.queryObject(cId)
            if category is not None:
                categories.append(
                    (category.title, {'name': category.__name__,
                                      'title': category.title}))

        categories.sort()
        self.categories = [info for t, info in categories]

        self.footer = self.categories or \
            self.tags_list or self.footer_discussion
示例#30
0
    def getContent(self):
        crumb = getMultiAdapter((getSite(), self.request), IBreadcrumb)

        title = IPersonalProfile(self.request.principal).title
        return {'subject': u'%s invites you to join %s site'%(title.strip(), crumb.name),
                'message': u'Hello,\n\nJoin the site %s!'%crumb.name}