Esempio n. 1
0
    def cancel_button_handler(self, action):
        data, errors = self.extractData()

        if data.get("documents"):
            url = get_containg_document_tab_url(data.get("documents")[0])
        else:
            url = get_containg_document_tab_url(self.context)

        return self.request.RESPONSE.redirect(url)
Esempio n. 2
0
    def cancel_button_handler(self, action):
        data, errors = self.extractData()

        if data.get('documents'):
            url = get_containg_document_tab_url(data.get('documents')[0])
        else:
            url = get_containg_document_tab_url(self.context)

        return self.request.RESPONSE.redirect(url)
Esempio n. 3
0
    def cancel(self, action):
        # on a document? go back to the document
        if IDocumentSchema.providedBy(self.context):
            return self.request.RESPONSE.redirect(self.context.absolute_url())

        # otherwise to the dossier or task
        return get_containg_document_tab_url(self.context)
Esempio n. 4
0
    def __call__(self, *args, **kwargs):
        try:
            return layout.FormWrapper.__call__(self, *args, **kwargs)
        except NoItemsSelected:
            msg = _(u'You have not selected any documents')
            IStatusMessage(self.request).addStatusMessage(msg, type='error')

            return get_containg_document_tab_url(self.context)
Esempio n. 5
0
    def cancel(self, action):
        # on a document? go back to the document
        if IDocumentSchema.providedBy(self.context):
            return self.request.RESPONSE.redirect(
                self.context.absolute_url())

        # otherwise to the dossier or task
        return get_containg_document_tab_url(self.context)
Esempio n. 6
0
    def __call__(self, *args, **kwargs):
        try:
            return layout.FormWrapper.__call__(self, *args, **kwargs)
        except NoItemsSelected:
            msg = _(u'You have not selected any documents')
            IStatusMessage(self.request).addStatusMessage(
                msg, type='error')

            return get_containg_document_tab_url(self.context)
Esempio n. 7
0
    def test_without_required_permission_function_returns_context_url(self):
        document_url = 'http://nohost/plone/dossier-1/task-1/document'
        document = self.mock_obj(document_url)
        dossier = self.mock_obj()
        self.mock_finder(dossier)
        self.mock_membership_tool(permission_granted=False)
        self.replay()

        url = get_containg_document_tab_url(document)
        self.assertEqual(url, document_url)
Esempio n. 8
0
    def test_given_required_permission_function_returns_tab_url(self):
        dossier_url = 'http://nohost/plone/dossier-1'
        dossier = self.mock_obj(dossier_url)
        document = self.mock_obj()
        self.mock_finder(dossier)
        self.mock_membership_tool(permission_granted=True)
        self.replay()

        url = get_containg_document_tab_url(document)
        self.assertEqual(url, '%s#documents' % dossier_url)
Esempio n. 9
0
    def send_button_handler(self, action):
        """ create and Send the Email """
        data, errors = self.extractData()

        if len(errors) == 0:
            mh = getToolByName(self.context, 'MailHost')
            contact_info = getUtility(IContactInformation)
            userid = self.context.portal_membership.getAuthenticatedMember()
            userid = userid.getId()
            intern_receiver = []
            for receiver in data.get('intern_receiver', []):
                # cut away the username
                intern_receiver.append(receiver.split(':')[0])

            extern_receiver = data.get('extern_receiver') or []
            addresses = intern_receiver + extern_receiver

            # create the mail
            msg = self.create_mail(
                data.get('message'),
                data.get('documents'),
                only_links=data.get('documents_as_links'))

            msg['Subject'] = Header(data.get('subject'), CHARSET)
            sender_address = contact_info.get_email(userid)
            if not sender_address:
                portal = self.context.portal_url.getPortalObject()
                sender_address = portal.email_from_address

            mail_from = '%s <%s>' % (
                    contact_info.describe(userid).encode(CHARSET),
                    sender_address.encode(CHARSET))

            msg['From'] = Header(mail_from, CHARSET)

            header_to = Header(','.join(addresses), CHARSET)
            msg['To'] = header_to

            # send it
            mh.send(msg, mfrom=mail_from, mto=','.join(addresses))

            # let the user know that the mail was sent
            info = _(u'info_mails_sent', 'Mails sent')
            notify(DocumentSent(
                    self.context, userid, header_to, data.get('subject'),
                    data.get('message'), data.get('documents')))

            IStatusMessage(self.request).addStatusMessage(info, type='info')
            # and redirect to default view / tab
            return self.request.RESPONSE.redirect(
                get_containg_document_tab_url(data.get('documents')[0]))
Esempio n. 10
0
    def send_button_handler(self, action):
        """ create and Send the Email """
        data, errors = self.extractData()

        if len(errors) == 0:
            mh = getToolByName(self.context, 'MailHost')
            contact_info = getUtility(IContactInformation)
            userid = self.context.portal_membership.getAuthenticatedMember()
            userid = userid.getId()
            intern_receiver = []
            for receiver in data.get('intern_receiver', []):
                # cut away the username
                intern_receiver.append(receiver.split(':')[0])

            extern_receiver = data.get('extern_receiver') or []
            addresses = intern_receiver + extern_receiver

            # create the mail
            msg = self.create_mail(data.get('message'),
                                   data.get('documents'),
                                   only_links=data.get('documents_as_links'))

            msg['Subject'] = Header(data.get('subject'), CHARSET)
            sender_address = contact_info.get_user(userid).email
            if not sender_address:
                portal = self.context.portal_url.getPortalObject()
                sender_address = portal.email_from_address

            mail_from = '%s <%s>' % (contact_info.describe(userid).encode(
                CHARSET), sender_address.encode(CHARSET))

            msg['From'] = Header(mail_from, CHARSET)

            header_to = Header(','.join(addresses), CHARSET)
            msg['To'] = header_to

            # send it
            mh.send(msg, mfrom=mail_from, mto=','.join(addresses))

            # let the user know that the mail was sent
            info = _(u'info_mails_sent', 'Mails sent')
            notify(
                DocumentSent(self.context, userid, header_to,
                             data.get('subject'), data.get('message'),
                             data.get('documents')))

            IStatusMessage(self.request).addStatusMessage(info, type='info')
            # and redirect to default view / tab
            return self.request.RESPONSE.redirect(
                get_containg_document_tab_url(data.get('documents')[0]))
Esempio n. 11
0
    def checkin_button_handler(self, action):
        """Handle checkin
        """

        data, errors = self.extractData()

        if len(errors) == 0:
            # check in each document
            for obj in self.objects:
                if IDocumentSchema.providedBy(obj):
                    manager = getMultiAdapter((obj, obj.REQUEST),
                                              ICheckinCheckoutManager)

                    if not manager.is_checkin_allowed():
                        msg = _(
                            u'Could not check in document ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='error')

                    else:
                        manager.checkin(data['comment'])
                        msg = _(
                            u'Checked in: ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='info')

                else:
                    title = obj.Title()
                    if not isinstance(title, unicode):
                        title = title.decode('utf-8')
                    msg = _(
                        u'Could not check in ${title}, it is not a document.',
                        mapping=dict(title=title))
                    IStatusMessage(self.request).addStatusMessage(msg,
                                                                  type='error')

            # redirect to dossier
            return self.request.RESPONSE.redirect(
                get_containg_document_tab_url(self.context))
Esempio n. 12
0
    def checkin_button_handler(self, action):
        """Handle checkin
        """

        data, errors = self.extractData()

        if len(errors) == 0:
            # check in each document
            for obj in self.objects:
                if IDocumentSchema.providedBy(obj):
                    manager = getMultiAdapter((obj, obj.REQUEST),
                                              ICheckinCheckoutManager)

                    if not manager.is_checkin_allowed():
                        msg = _(
                            u'Could not check in document ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='error')

                    else:
                        manager.checkin(data['comment'])
                        msg = _(
                            u'Checked in: ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='info')

                else:
                    title = obj.Title()
                    if not isinstance(title, unicode):
                        title = title.decode('utf-8')
                    msg = _(
                        u'Could not check in ${title}, it is not a document.',
                        mapping=dict(title=title))
                    IStatusMessage(self.request).addStatusMessage(
                        msg, type='error')

            # redirect to dossier
            return self.request.RESPONSE.redirect(
                get_containg_document_tab_url(self.context))