コード例 #1
0
 def test_06_searchcloud_displays_when_approved_data_present(self):
     #Put some data into the cloud
     searchcloud.generate_unapproved_list(model.Session, days=30)
     latest_rows = searchcloud.get_latest(model.Session)
     self.assert_equal(latest_rows, [[u'Health', 3L], [u"Water<>&\"{}'", 2L], [u'Tax\u6c49\u5b57\u6f22\u5b57', 1L]])
     searchcloud.update_approved(model.Session, latest_rows)
     approved_rows = searchcloud.get_approved(model.Session)
     self.assert_equal(latest_rows, approved_rows)
     #We'll use this test data later, so save it.
     model.Session.commit()
     # Test that the JSON text is what we expect.
     self.assert_equal(
         expected_json,
         searchcloud.approved_to_json(approved_rows)
     )
     # Now we should get a cloud
     home_url = tests.url_for('home')
     res = self.app.get(home_url)
     self.assert_equal(
         'var word_array = '+(cgi.escape(expected_json)) in res,
         True,
     )
     self.assert_equal('Popular terms' in res, True)
     self.assert_equal('jqcloud-1.0.4.min.js' in res, True)
     self.assert_equal('jqcloud.css' in res, True)
     self.assert_equal('<div id="searchcloud"' in res, True)
コード例 #2
0
                return tk.render('searchcloud/error.html')
            else:
                tk.c.json = searchcloud.approved_to_json(rows)
                tk.c.data = data
                return tk.render('searchcloud/preview.html')

    def save(self):
        self._sysadmin_or_abort()
        data = tk.request.POST['searchcloud']
        try:
            rows = self._parse_json(data)
        except SearchCloudException, e:
            tk.c.error = str(e)
            return tk.render('searchcloud/error.html')
        else:
            searchcloud.update_approved(model.Session, rows)
            # Save our changes
            model.Session.commit()
            return tk.render('searchcloud/saved.html')

    def download(self):
        self._sysadmin_or_abort()
        data = searchcloud.get_latest(model.Session)
        # We don't know when the script is run, so let's assume just
        # after midnight and use today's date
        date = datetime.datetime.now().strftime('%Y-%m-%d')
        response.charset = 'utf8'
        response.content_type = 'application/json'
        response.headers['Content-Disposition'] = \
            'attachment; filename="ecodp-searchcloud-latest-%s.json"' % date
        return json.dumps(data, indent=4)