Example #1
0
    def show(self):
        """ Removes all status messages (including HTML) and returns them 
            for display.
        """
        context = self.context
        annotations = IAnnotations(context)
        msgs = annotations.get(STATUSMESSAGEKEY,
                                context.cookies.get(STATUSMESSAGEKEY))
        msgs = msgs and adapter._decodeCookieValue(msgs) or []

        html_msgs = annotations.get(HTMLMESSAGEKEY,
                                context.cookies.get(HTMLMESSAGEKEY))
        html_msgs = html_msgs and adapter._decodeCookieValue(html_msgs) or []

        for msg in html_msgs:
            msg.message = literal(sanitize(msg.message, cleaner=msgcleaner, wrap=None))

        value = msgs + html_msgs
        
        # clear the existing cookie entries, except on responses that don't
        # actually render in the browser (really, these shouldn't render
        # anything so we shouldn't get to this message, but some templates
        # are sloppy).
        if self.context.response.getStatus() not in (301, 302, 304):
            context.cookies[STATUSMESSAGEKEY] = None
            context.response.expireCookie(STATUSMESSAGEKEY, path='/')
            annotations[STATUSMESSAGEKEY] = None

            context.cookies[HTMLMESSAGEKEY] = None
            context.response.expireCookie(HTMLMESSAGEKEY, path='/')
            annotations[HTMLMESSAGEKEY] = None
        
        return value
Example #2
0
    def __test_stats_url(self, context, country, period, year, rtype, format):
        tool = 'be/xxxx/xxxx/2010-08-05'
        view = getMultiAdapter((context, context.REQUEST),
                               name="show-statistics")
        report_period = ReportPeriod({
            'year': year,
            'period': period
        })
        data = {'countries': country,
                'report_period': report_period,
                'report_type': rtype,
                'tools': tool,
                'file_format': format,
                }
        # Without setting the statistics server URL in
        # site_props, the return url must be None
        url = view.getStatisticsServerURL(data)
        cookies = context.REQUEST.RESPONSE.cookies
        self.assertIsNone(url)
        self.assertTrue('statusmessages' in cookies)
        cookie = cookies.get('statusmessages')
        message = _decodeCookieValue(cookie['value'])[0]
        self.assertEqual(
            message.message,
            u'birt_report_url not set, please contact '
            u'an administrator'
        )
        self.assertEqual(message.type, u'error')

        # Now set the statistics server URL and test
        sprops = api.portal.get_tool(
            name='portal_properties').site_properties

        server_url = 'http://localhost'
        sprops._setProperty('birt_report_url',
                            server_url)
        url = view.getStatisticsServerURL(data)
        month = 0
        quarter = 0
        if period > 12:
            quarter = period % 12
        else:
            month = period
        filename = statistics.StatisticsMixin.filename[rtype]

        # Ugly but I'm in a rush
        test_url = "&".join([
            server_url,
            '__report=statistics/%s' % filename,
            rtype == 'country' and 'country=%s' % country or
            rtype == 'tool' and 'tool=%s' % tool or
            'sector=%25',
            'year=%d' % year,
            'month=%d' % month,
            'quarter=%d' % quarter,
            'testsessions=0',
            '__format=%s' % format
        ])
        self.assertEqual(url, test_url)
        sprops._delProperty('birt_report_url')
Example #3
0
 def issueAllPortalMessages(self):
     if hasattr(self.request.RESPONSE, 'cookies'):
         cookie = self.request.RESPONSE.cookies.get(STATUSMESSAGEKEY)
         if cookie:
             encodedstatusmessages = cookie['value']
             statusmessages = _decodeCookieValue(encodedstatusmessages)
         else:
             statusmessages = []
         for msg in statusmessages:
             self.getCommandSet('plone').issuePortalMessage(msg)
         self.request.RESPONSE.expireCookie(STATUSMESSAGEKEY, path='/')
Example #4
0
    def get_portal_messages(self):
        """ Portal message
        """
        statusmessages = []
        if hasattr(self.request.RESPONSE, 'cookies'):
            cookie = self.request.RESPONSE.cookies.get(STATUSMESSAGEKEY)
            if cookie:
                encodedstatusmessages = cookie['value']
                statusmessages = _decodeCookieValue(encodedstatusmessages)

        self.request.RESPONSE.expireCookie(STATUSMESSAGEKEY, path='/')
        return statusmessages
    def testExecute(self):
        e = NotifyAction()
        e.message = 'Hello world'
        e.message_type = 'info'

        ex = getMultiAdapter((self.folder, e, DummyEvent()), IExecutable)
        self.assertEqual(True, ex())

        new_cookies = self.request.RESPONSE.cookies[STATUSMESSAGEKEY]
        messages = _decodeCookieValue(new_cookies['value'])
        self.assertEqual(1, len(messages))
        self.assertEqual('Hello world', messages[0].message)
        self.assertEqual('info', messages[0].type)
Example #6
0
    def testExecute(self):
        e = NotifyAction()
        e.message = 'Hello world'
        e.message_type = 'info'

        ex = getMultiAdapter((self.folder, e, DummyEvent()), IExecutable)
        self.assertEqual(True, ex())

        new_cookies = self.request.RESPONSE.cookies[STATUSMESSAGEKEY]
        messages = _decodeCookieValue(new_cookies['value'])
        self.assertEqual(1, len(messages))
        self.assertEqual('Hello world', messages[0].message)
        self.assertEqual('info', messages[0].type)
Example #7
0
    def testNotFound(self):
        e = Action()
        e.app = 'badapp'
        e.block = 'rule'
        e.method = 'hello'

        ex = getMultiAdapter(
            (self.portal, e, DummyEvent(self.portal)), IExecutable)
        ex()
        new_cookies = self.request.RESPONSE.cookies[STATUSMESSAGEKEY]
        messages = _decodeCookieValue(new_cookies['value'])
        self.assertEquals(messages[0].message,
            u'Rapido application badapp cannot be found.')
 def test_good_cookie(self):
     view = self.get_view('bwtools', cookies={'_bw': '1|1|11|100001'})
     self.assertFloatDictEqual(
         view.cookiedict, {
             'bandwidth': 80000000.0,
             'delta0': 0.001,
             'delta100': 0.011,
             'size0': 8.0,
             'size100': 800008.0
         })
     view.show_and_redirect()
     value = view.request.response.cookies['statusmessages']['value']
     self.assertListEqual(
         [x.message for x in _decodeCookieValue(value)],
         [u'Estimated BW: 78125Kb/s. MDT 0.001s'],
     )
     self.assertEqual(view.quality, 1)