예제 #1
0
def invitationAcceptedHandler(invitation, event):
    owner = IOwnership(invitation).owner
    if owner is None:
        return

    messaging = IMessageStorage(owner, None)
    if messaging is None:
        return

    interaction = queryInteraction()

    if interaction is not None:
        for request in interaction.participations:
            principal = invitation.principal

            view = queryMultiAdapter(
                (principal, request), IPagelet, 'personal.message')
            if view is None:
                return

            view.update()

            data = {'title': u'Your invitation has been accepted',
                    'text': view.render(),
                    'sender': unicode(principal.id)}
            messaging.create(SERVICE_ID, **data)
예제 #2
0
    def update(self):
        request = self.request
        context = removeAllProxies(self.context)
        context.__status__ = False

        try:
            sender = getUtility(IAuthentication).getPrincipal(context.sender)
        except PrincipalLookupError:
            sender = None

        self.replyTo = sender
        self.messaging = IMessageStorage(self.replyTo, None)

        if sender is not None:
            profile = IPersonalProfile(sender, None)
            self.sender = getattr(profile, 'title', sender.title)

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

        oldcontext = self.context

        self.context = context
        super(MessageView, self).update()
        self.context = oldcontext
예제 #3
0
class MessageView(PageletForm):

    label = _(u'Reply')
    fields = Fields(IMessage)

    def getContent(self):
        context = self.context
        if not context.title.startswith(u'Re:'):
            return {'title': u'Re: %s'%context.title,
                    'body': u'<blockquote>%s</blockquote><br />'%context.text}
        else:
            return {'title': u'',
                    'body': u'<blockquote>%s</blockquote><br />'%context.text}

    def update(self):
        request = self.request
        context = removeAllProxies(self.context)
        context.__status__ = False

        try:
            sender = getUtility(IAuthentication).getPrincipal(context.sender)
        except PrincipalLookupError:
            sender = None

        self.replyTo = sender
        self.messaging = IMessageStorage(self.replyTo, None)

        if sender is not None:
            profile = IPersonalProfile(sender, None)
            self.sender = getattr(profile, 'title', sender.title)

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

        oldcontext = self.context

        self.context = context
        super(MessageView, self).update()
        self.context = oldcontext

    @button.buttonAndHandler(_(u'Send reply'), provides=interfaces.IAddButton)
    def handleReply(self, action):
        data, errors = self.extractData()

        if errors:
            IStatusMessage(self.request).add(self.formErrorsMessage, 'error')
        else:
            data['text'] = data['body'].cooked
            data['sender'] = unicode(
                self.context.__parent__.__parent__.principalId)
            data['replyto'] = unicode(self.context.__uid__)

            self.messaging.create(SERVICE_ID, **data)

            IStatusMessage(self.request).add(_(u'Message has been sent.'))
            self.redirect('../')