def test_computed_multiple_files_access(self): portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'column_files': "%s\n%s" % (portal.file1.UID(), portal.file2.UID())}) configuration = tp.getPageColumns() configuration[-1]['vocabulary'] = "python:row['column_files'][1].Title()" field = self._getField() self.assertEquals(field.render_view('foo', 0).strip(), 'Another file')
def test_computed_general_tal_access(self): portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'simple_column': 'Lorem ipsum'}) configuration = tp.getPageColumns() configuration[-1]['vocabulary'] = 'portal/title' field = self._getField() self.assertEquals(field.render_view('foo', 0).strip(), 'Plone site')
def test_computed_file_access(self): portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'column_file': portal.file1.UID()}) configuration = tp.getPageColumns() configuration[-1]['vocabulary'] = 'row/column_file/Title' field = self._getField() self.assertEquals(field.render_view('foo', 0).strip(), 'One file')
def test_template_override_icon(self): portal = self.layer['portal'] tp = portal.table_page tp.edit(pageColumns=[{'id': 'link', 'label': 'Link', 'description': '', 'type': 'Link', 'vocabulary': 'icon:src-to-an-icon', 'options': []}]) storage = IDataStorage(tp) storage.add({'__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa'}) output = tp() self.assertTrue(u'<img src="src-to-an-icon" alt="A d\xf2cument to reference" />' in output)
def test_reference_document_edit(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa'}) request.form['row-index'] = 0 view = getMultiAdapter((tp, request), name=u'edit-record') self.assertTrue('value="%s"' % portal.document.Title().decode('utf-8') in view())
def test_url_edit(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': TEST_USER_NAME, 'link': 'http://foo.com/', '__uuid__': 'aaa'}) request.form['row-index'] = 0 view = getMultiAdapter((tp, request), name=u'edit-record') self.assertTrue('http://foo.com/' in view())
def test_template_override_text(self): portal = self.layer['portal'] tp = portal.table_page tp.edit(pageColumns=[{'id': 'link', 'label': 'Link', 'description': '', 'type': 'Link', 'vocabulary': 'title:Lorèm ipsum', 'options': []}]) storage = IDataStorage(tp) storage.add({'__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa'}) output = tp() self.assertTrue(u'Lor\xe8m ipsum' in output)
def test_view_forbidden_attachment(self): """Although attachment is not accessible, normal table visitor can see the link""" portal = self.layer['portal'] tp = portal.table_page folder = portal.folder tp.manage_setLocalRoles('user0', ('Contributor',)) storage = IDataStorage(tp) storage.add({'__creator__': 'user0', 'att': folder.attachment.UID(), '__uuid__': 'aaa'}) logout() self.assertTrue('An ancient attachment' in tp())
def test_modify_his_row(self): """user2 can't modify other user's data""" portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'foo data from user1', '__uuid__': 'aaa'}) login(portal, 'user2') view = tp.restrictedTraverse('@@edit-record') view.request.form['row-index'] = 0 self.assertRaises(Unauthorized, view)
def test_computed_link_access(self): portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'column_link': portal.document.UID()}) storage.add({'column_link': 'http://plone.org/'}) configuration = tp.getPageColumns() configuration[-1]['vocabulary'] = "row/column_link/Title|row/column_link" field = self._getField() self.assertEquals(field.render_view('foo', 0).strip(), 'A document to reference') self.assertEquals(field.render_view('foo', 1).strip(), 'http://plone.org/')
def test_editor_modify_his_row(self): """user3 can modify other user's data""" portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'foo data from user1', '__uuid__': 'aaa'}) login(portal, 'user3') view = tp.restrictedTraverse('@@edit-record') view.request.form['row-index'] = 0 self.assertTrue('Edit row' in view()) self.assertTrue('foo data from user1' in view())
def test_delete_my_row(self): """Owners can delete proper rows""" portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'foo data from user1', '__uuid__': 'aaa'}) login(portal, 'user1') view = tp.restrictedTraverse('@@delete-record') view.request.form['row-index'] = 0 view() self.assertEqual(len(storage), 0)
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'col_a', 'label': 'Col A', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}]) storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'Lorem', '__uuid__': 'aaa'}) storage.add({'__creator__': 'user1', 'col_a': 'Ipsum', '__uuid__': 'bbb'}) storage.add({'__creator__': 'user1', 'col_a': 'Sit', '__uuid__': 'ccc'}) self.tp_catalog = getToolByName(portal, 'tablepage_catalog')
def test_frontend_url(self): """We will have resolveuid URL in backend, but real URL on table view""" tp = self.tp request = self.layer['request'] portal = self.layer['portal'] storage = IDataStorage(tp) storage.add({'__creator__': 'user0', 'att': portal.folder.attachment1.UID(), '__uuid__': 'aaa'}) view = getMultiAdapter((tp, request), name='tablepage-edit') self.assertTrue('href="resolveuid/%s/at_download/file"' % \ portal.folder.attachment1.UID() in view()) self.assertTrue('href="http://nohost/plone/folder/attachment1/at_download/file"' in tp())
def test_rows_var_access(self): portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'simple_column': 'Lorem ipsum'}) configuration = tp.getPageColumns() configuration[-1]['vocabulary'] = "python:rows.get(0)['simple_column']" field = self._getField() self.assertEquals(field.render_view('foo', 0).strip(), 'Lorem ipsum') storage.add({'simple_column': 'dolor sit amet'}) field = self._getField() self.assertEquals(field.render_view('foo', 1).strip(), 'Lorem ipsum')
def test_editor_move_his_row(self): """Editor can move rows""" portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'foo data from user1', '__uuid__': 'aaa'}) storage.add({'__creator__': 'user1', 'col_a': 'some other futile data', '__uuid__': 'bbb'}) login(portal, 'user3') view = tp.restrictedTraverse('@@move-record') view.request.form['row-index'] = 0 view.request.form['direction'] = 'down' view() self.assertEqual(storage[0].get('col_a'), 'some other futile data')
def test_delete_old_data(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': 'user0', 'att': portal.folder.attachment.UID(), '__uuid__': 'aaa'}) request.form['row-index'] = 0 request.form['form.submitted'] = "1" request.form['existing_att'] = '' view = getMultiAdapter((tp, request), name='edit-record') view() self.assertFalse(storage[0]['att']==portal.folder.attachment.UID()) self.assertEqual(storage[0]['att'], '')
def test_add_begin_of_group_2(self): # When the first row is a label, always add after it portal = self.layer['portal'] tp = portal.table_page tp.setInsertType('prepend') storage = IDataStorage(tp) storage.add({'__label__': 'New label'}, 0) # 0 login(portal, 'user2') view = tp.restrictedTraverse('@@edit-record') view.request.form['addRow'] = '1' view.request.form['form.submitted'] = '1' view.request.form['row-index'] = 0 view.request.form['col_a'] = 'Added by me!' view() self.assertEqual(storage[1].get('col_a'), 'Added by me!')
def test_delete_old_data(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa'}) request.form['row-index'] = 0 request.form['form.submitted'] = '1' request.form['external_link'] = '' request.form['internal_link'] = '' view = getMultiAdapter((tp, request), name=u'edit-record') view() self.assertFalse(storage[0]['link']==portal.document.UID()) self.assertEqual(storage[0]['link'], '')
def test_noturl_edit(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({ '__creator__': TEST_USER_NAME, 'link': 'foo bar baz', '__uuid__': 'aaa' }) request.form['row-index'] = 0 view = getMultiAdapter((tp, request), name=u'edit-record') self.assertTrue('foo bar baz' not in view()) self.assertTrue('value="%s"' % portal.document.Title().decode('utf-8') not in view())
def setUp(self): portal = self.layer['portal'] request = self.layer['request'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") portal.table_page.edit(pageColumns=[{'id': 'col_a', 'label': 'Col A', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}, {'id': 'col_b', 'label': 'Col B', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}, {'id': 'col_c', 'label': 'Col C', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []} ]) self.tp_catalog = portal.tablepage_catalog self.storage = IDataStorage(portal.table_page) request.set('ACTUAL_URL', 'http://nohost/plone/table_page')
def test_encoding(self): """Be sure that we have no problems with non-ASCII chars""" portal = self.layer['portal'] portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(textBefore='<p>L\xc3\xb2r\xc3\xa8m Ips\xc3\xb9m</p>', pageColumns=[{'id': 'col_a', 'label': 'Col A', 'description': 'Th\xc3\xacs data is futile', 'type': 'String', 'vocabulary': '', 'options': []}]) storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'F\xc3\xb2\xc3\xb2 data from user1', '__uuid__': 'aaa'}) try: tp.getText() except UnicodeDecodeError: self.fail("getText() raised UnicodeDecodeError unexpectedly!")
def __call__(self, *args, **kwargs): context = self.context request = self.request catalog = getToolByName(context, config.CATALOG_ID) storage = IDataStorage(context) # now we load the tabel view and rebuild all rows by using the ignore_cache parameter table_view = getMultiAdapter((context, request), name=u'view-table') table_view.rows(ignore_cache=True) for index, row in enumerate(storage): uuid = row.get('__uuid__') if not uuid: # this should not happen logger.warning( "Row without an uuid! index %d, document at %s" % (index, context.absolute_url_path())) continue catalog.reindex_rows(context, uuid, storage) if index and index % 100 == 0: logger.info("Refreshing catalog (%d)" % index) transaction.savepoint() logger.info("Refreshing catalog and caches: done") getToolByName(context, 'plone_utils').addPortalMessage( _('reindex_performed_message', u'$count rows has been updated', mapping={'count': index + 1})) request.response.redirect('%s/edit-table' % context.absolute_url())
def test_size_option(self): portal = self.layer['portal'] portal.invokeFactory(type_name='Image', id='image', title="An image") tp = portal.table_page tp.edit(textBefore='<p>Lorem Ipsum</p>', pageColumns=[{'id': 'att', 'label': 'Attachment', 'description': '', 'type': 'Image', 'vocabulary': 'size:icon', 'options': []}], attachmentStorage=portal.folder.UID()) storage = IDataStorage(tp) storage.add({'__creator__': TEST_USER_NAME, 'att': portal.image.UID(), '__uuid__': 'aaa'}) output = tp() self.assertTrue(u'<img src="resolveuid/' + portal.image.UID() + u'/image_icon"' in output)
def test_file_creation_2(self): """When title is not provided, file id is used and we can't add multiple files (same as Plone)""" portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page folder = portal.folder tp.manage_setLocalRoles('user0', ('Contributor', )) with open(__file__) as f: file = StringIO(f.read()) filename = os.path.basename(__file__) file.filename = filename request.form['att'] = file request.form['form.submitted'] = "1" view = getMultiAdapter((tp, request), name='edit-record') view() file_content = folder[filename] self.assertTrue(file_content.getId() in folder.objectIds()) self.assertEqual(len(folder.objectIds()), 2) file.seek(0) request.form['att'] = file request.form['form.submitted'] = "1" view() # we still have two files self.assertEqual(len(folder.objectIds()), 2) storage = IDataStorage(tp) self.assertEqual(storage[0]['att'], storage[1]['att'])
def _get_row_data(self, row): """Return a dict of data taken from other row values""" # First of all: if this is a catalog brain, let's load the "real object" # BBB: can't check for ICatalogBrain until Plone 3.3 support will be dropped if isinstance(row, AbstractCatalogBrain): storage = IDataStorage(self.context) row = storage[row.getObjPositionInParent - 1] results = {} utils = {} configuration = self.context.getPageColumns() for col_index, conf in enumerate(configuration): col_type = conf['type'] # let's cache (or use cached) utility cache = IAnnotations(self.request) cached = cache.get('colum-handle-%s' % col_type) if not cached: try: utils[col_type] = getUtility(IComputedColumnHandler, name=col_type) except ComponentLookupError: utils[col_type] = getUtility(IComputedColumnHandler) cache['colum-handle-%s' % col_type] = utils[col_type] else: utils[col_type] = cached if not col_type or col_type == 'Computed': continue id = configuration[col_index]['id'] data = row.get(id) or None results[id] = utils[col_type](data) return results
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{ 'id': 'the_text_data', 'label': 'A text', 'description': '', 'type': 'String', 'vocabulary': '', 'options': [] }]) self.storage = IDataStorage(tp)
def add_rows(self): portal = self.layer['portal'] storage = IDataStorage(portal.table_page1) data = {'__creator__': 'user1', 'col_a': 'Lorem ipsum', '__uuid__': 'aaa'} storage.add(data) self.tp_catalog.catalog_row(portal.table_page1, data) data = {'__creator__': 'user1', 'col_a': 'dolor sit amet', '__uuid__': 'bbb'} storage.add(data) self.tp_catalog.catalog_row(portal.table_page1, data) # another TP storage = IDataStorage(portal.table_page2) data = {'__creator__': 'user1', 'col_a': 'consectetur adipisicing elit', '__uuid__': 'ccc'} storage.add(data) self.tp_catalog.catalog_row(portal.table_page2, data) data = {'__creator__': 'user1', 'col_a': 'sed do eiusmod tempor', '__uuid__': 'ddd'} storage.add(data) self.tp_catalog.catalog_row(portal.table_page2, data)
def test_frontend_url(self): """We will have resolveuid URL in backend, but real URL on table view""" tp = self.tp request = self.layer['request'] portal = self.layer['portal'] storage = IDataStorage(tp) storage.add({ '__creator__': 'user0', 'att': portal.folder.attachment1.UID(), '__uuid__': 'aaa' }) view = getMultiAdapter((tp, request), name='tablepage-edit') self.assertTrue('href="resolveuid/%s/at_download/file"' % \ portal.folder.attachment1.UID() in view()) self.assertTrue( 'href="http://nohost/plone/folder/attachment1/at_download/file"' in tp())
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") portal.invokeFactory(type_name='File', id='file1', title="Attachment 1") portal.invokeFactory(type_name='File', id='file2', title="Attachment 2") portal.invokeFactory(type_name='Document', id='document1', title="Page 1") self.tp_catalog = portal.tablepage_catalog self.storage = IDataStorage(portal.table_page)
def test_delete_old_data(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({ '__creator__': 'user0', 'att': portal.folder.attachment.UID(), '__uuid__': 'aaa' }) request.form['row-index'] = 0 request.form['form.submitted'] = "1" request.form['existing_att'] = '' view = getMultiAdapter((tp, request), name='edit-record') view() self.assertFalse(storage[0]['att'] == portal.folder.attachment.UID()) self.assertEqual(storage[0]['att'], '')
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") portal.invokeFactory(type_name='File', id='file1', title="Attachment 1") portal.invokeFactory(type_name='File', id='file2', title="Attachment 2") portal.invokeFactory(type_name='Document', id='document1', title="Page 1") self.storage = IDataStorage(portal.table_page)
class CachingTestCase(unittest.TestCase): layer = TABLE_PAGE_INTEGRATION_TESTING def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'the_text_data', 'label': 'A text', 'description': '', 'type': 'Text', 'vocabulary': '', 'options': []} ]) self.storage = IDataStorage(tp) def test_cache_miss(self): portal = self.layer['portal'] request = self.layer['request'] request.form['form.submitted'] = '1' request.form['the_text_data'] = 'Lorem ipsum' tp = portal.table_page view = getMultiAdapter((tp, request), name='edit-record') view() self.assertEqual(self.storage[0]['__cache__']['the_text_data']['data'], '<p>Lorem ipsum</p>\n') self.assertTrue(self.storage[0]['__cache__']['the_text_data']['timestamp'] < DateTime().millis()) def test_cache_hit(self): portal = self.layer['portal'] tomorrow = DateTime() + 1 self.storage.add({'__creator__': 'foo', 'the_text_data': 'foo bar baz', '__uuid__': 'aaa', '__cache__': {'the_text_data': {'data': 'In cache we believe', 'timestamp': tomorrow.millis()}}}) output = portal.table_page() self.assertTrue('In cache we believe' in output) self.assertFalse('foo bar baz' in output) def test_cache_miss_timestamp_expired(self): portal = self.layer['portal'] self.storage.add({'__creator__': 'foo', 'the_text_data': 'foo bar baz', '__uuid__': 'aaa', '__cache__': {'the_text_data': {'data': 'In cache we believe', 'timestamp': 0}}}) output = portal.table_page() self.assertFalse('In cache we believe' in output) self.assertTrue('<p>foo bar baz</p>' in output)
def test_catalog_reindex_rows(self): portal = self.layer['portal'] self.add_rows() tp = portal.table_page1 storage = IDataStorage(tp) portal = self.layer['portal'] data = { '__creator__': 'user1', 'col_a': 'Proin elementum', '__uuid__': 'ccc' } storage.add(data) self.tp_catalog.catalog_row(tp, data) self.assertEqual(len(list(self.tp_catalog.searchTablePage(tp))), 3) self.assertEqual( self.tp_catalog.searchTablePage(tp)[0]._unrestrictedGetObject() ['col_a'], 'Lorem ipsum') self.assertEqual( self.tp_catalog.searchTablePage(tp)[1]._unrestrictedGetObject() ['col_a'], 'dolor sit amet') self.assertEqual( self.tp_catalog.searchTablePage(tp)[2]._unrestrictedGetObject() ['col_a'], 'Proin elementum') data = storage.get('bbb') del storage['bbb'] storage.add(data, 2) self.tp_catalog.reindex_rows(tp, ['bbb', 'ccc']) self.assertEqual( self.tp_catalog.searchTablePage(tp)[1]._unrestrictedGetObject() ['col_a'], 'Proin elementum') self.assertEqual( self.tp_catalog.searchTablePage(tp)[2]._unrestrictedGetObject() ['col_a'], 'dolor sit amet')
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'the_text_data', 'label': 'A text', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []} ]) self.storage = IDataStorage(tp)
def test_delete_old_data(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page storage = IDataStorage(tp) storage.add({ '__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa' }) request.form['row-index'] = 0 request.form['form.submitted'] = '1' request.form['external_link'] = '' request.form['internal_link'] = '' view = getMultiAdapter((tp, request), name=u'edit-record') view() self.assertFalse(storage[0]['link'] == portal.document.UID()) self.assertEqual(storage[0]['link'], '')
def test_url_save(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page request.form['external_link'] = 'http://mycompany.com/' request.form['form.submitted'] = '1' view = getMultiAdapter((tp, request), name=u'edit-record') view() storage = IDataStorage(tp) self.assertEqual(storage[0]['link'], 'http://mycompany.com/')
def test_template_override_text(self): portal = self.layer['portal'] tp = portal.table_page tp.edit(pageColumns=[{ 'id': 'link', 'label': 'Link', 'description': '', 'type': 'Link', 'vocabulary': 'title:Lorèm ipsum', 'options': [] }]) storage = IDataStorage(tp) storage.add({ '__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa' }) output = tp() self.assertTrue(u'Lor\xe8m ipsum' in output)
def test_reference_save(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page request.form['internal_link'] = portal.document.UID() request.form['form.submitted'] = '1' view = getMultiAdapter((tp, request), name=u'edit-record') view() storage = IDataStorage(tp) self.assertEqual(storage[0]['link'], portal.document.UID())
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'foo', 'label': 'Select one', 'description': '', 'type': 'Select', 'vocabulary': 'Lorem\nIpsum\ndolor\nsit\n amet', 'options': []} ]) self.storage = IDataStorage(tp)
def test_sort_no_values(self): portal = self.layer['portal'] request = self.layer['request'] portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'col_a', 'label': 'Col A', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}, {'id': 'col_b', 'label': 'Col B', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}]) view = getMultiAdapter((tp, request), name='view-table') self.assertEqual(view.sort_by(), None) self.assertEqual(view.sort_order(), 'asc') storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'Lorem', 'col_b': 'Lorem', '__uuid__': 'aaa'}) storage.add({'__creator__': 'user1', 'col_a': 'Ipsum', 'col_b': 'Ipsum', '__uuid__': 'bbb'}) storage.add({'__creator__': 'user1', 'col_a': 'Sit', 'col_b': 'Sit', '__uuid__': 'ccc'}) out = view() self.assertNotIn('data-sort-by', out) self.assertIn('data-sort-order="asc"', out)
def test_view_forbidden_attachment(self): """Although attachment is not accessible, normal table visitor can see the link""" portal = self.layer['portal'] tp = portal.table_page folder = portal.folder tp.manage_setLocalRoles('user0', ('Contributor', )) storage = IDataStorage(tp) storage.add({ '__creator__': 'user0', 'att': '\n'.join([folder.attachment1.UID(), folder.attachment2.UID()]), '__uuid__': 'aaa' }) logout() self.assertTrue('An attachment' in tp()) self.assertTrue('Another attachment' in tp())
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'col_a', 'label': 'Col A', 'description': 'Th\xc3\xacs data is futile', 'type': 'String', 'vocabulary': '', 'options': []}]) storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'F\xc3\xb2\xc3\xb2 data from user1', '__uuid__': 'aaa'}) storage.add({'__label__': 'A label'}) storage.add({'__creator__': 'user1', 'col_a': 'Other data from user1', '__uuid__': 'bbb'}) storage.add({'__creator__': 'user1', 'col_a': 'Again data from user1', '__uuid__': 'ccc'}) self.storage = storage
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'foo_field', 'label': 'Foo field', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}, ], batchSize=10) self.tp = tp self.storage = IDataStorage(tp)
def setUp(self): portal = self.layer['portal'] login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[ { 'id': 'foo_field', 'label': 'Foo field', 'description': '', 'type': 'String', 'vocabulary': '', 'options': [] }, ], batchSize=10) self.tp = tp self.storage = IDataStorage(tp)
def test_catalog_rows_on_add(self): portal = self.layer['portal'] self.add_rows() storage = IDataStorage(portal.table_page1) self.assertEqual(len(self.tp_catalog()), 4) self.assertEqual( len(list(self.tp_catalog.searchTablePage(portal.table_page1))), 2) self.assertEqual( self.tp_catalog.searchTablePage( portal.table_page1)[0]._unrestrictedGetObject()['col_a'], storage[0]['col_a'])
def test_template_override_icon(self): portal = self.layer['portal'] tp = portal.table_page tp.edit(pageColumns=[{ 'id': 'link', 'label': 'Link', 'description': '', 'type': 'Link', 'vocabulary': 'icon:src-to-an-icon', 'options': [] }]) storage = IDataStorage(tp) storage.add({ '__creator__': TEST_USER_NAME, 'link': portal.document.UID(), '__uuid__': 'aaa' }) output = tp() self.assertTrue( u'<img src="src-to-an-icon" alt="A d\xf2cument to reference" />' in output)
def setUp(self): portal = self.layer['portal'] self.tp_catalog = portal.tablepage_catalog login(portal, TEST_USER_NAME) portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(pageColumns=[{'id': 'foo_field', 'label': 'Foo field', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}, ], batchSize=10) tp.edit(searchConfig=[{'id': 'foo_field', 'label': '', 'description': '', 'additionalConfiguration': ['SearchableText']}]) self.tp = tp self.storage = IDataStorage(tp) self._addRows(35) # now adding another tablepage: this must be always ignored by searches portal.invokeFactory(type_name='TablePage', id='table_page2', title="Another Table Document") portal.table_page2.edit(pageColumns=[{'id': 'foo_field', 'label': 'Foo field', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}, ], batchSize=10) storage2 = IDataStorage(portal.table_page2) storage2.add({'__label__': 'A Label', '__uuid__': 'l2l2l2'}) storage2.add({'foo_field': 'aa001', '__uuid__': '010'}) portal.portal_workflow.doActionFor(tp, 'publish') self.tp_catalog.clearFindAndRebuild() logout()
def test_foo_data_saved_however(self): portal = self.layer['portal'] request = self.layer['request'] tp = portal.table_page request.form['external_link'] = 'this is not an url' request.form['internal_link'] = 'this is not an uid' request.form['form.submitted'] = '1' view = getMultiAdapter((tp, request), name=u'edit-record') view() storage = IDataStorage(tp) self.assertEqual(storage[0]['link'], 'this is not an uid') output = tp() self.assertFalse('this is not an uid' in output)
def test_rebuild_catalog(self): portal = self.layer['portal'] request = self.layer['request'] self.add_rows() tp = portal.table_page1 storage = IDataStorage(tp) storage[1]['col_a'] = 'foo bar baz' self.tp_catalog.manage_catalogReindex(request, request.response, self.tp_catalog.absolute_url()) self.assertEqual(len(list(self.tp_catalog())), 4) self.assertEqual(len(self.tp_catalog.searchTablePage(tp)), 2) self.assertEqual( self.tp_catalog.searchTablePage(tp)[1]._unrestrictedGetObject() ['col_a'], 'foo bar baz')
def test_sort(self): self.portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = self.portal.table_page tp.edit(pageColumns=[{ 'id': 'col_a', 'label': 'Col A', 'description': '', 'type': 'String', 'vocabulary': '', 'options': [] }, { 'id': 'col_b', 'label': 'Col B', 'description': '', 'type': 'String', 'vocabulary': '', 'options': [] }], sortBy='col_b', sortOrder='desc') view = self._get_view(tp) self.assertEqual(view.sort_by(), 1) self.assertEqual(view.sort_order(), 'desc') storage = IDataStorage(tp) storage.add({ '__creator__': 'user1', 'col_a': 'Lorem', 'col_b': 'Lorem', '__uuid__': 'aaa' }) storage.add({ '__creator__': 'user1', 'col_a': 'Ipsum', 'col_b': 'Ipsum', '__uuid__': 'bbb' }) storage.add({ '__creator__': 'user1', 'col_a': 'Sit', 'col_b': 'Sit', '__uuid__': 'ccc' }) out = view() self.assertIn('data-sort-by="1"', out) self.assertIn('data-sort-order="desc"', out)
def _uuid_all(context): logger.info("Generating uuids info for old rows") catalog = getToolByName(context, 'portal_catalog') results = catalog(object_provides=ITablePage.__identifier__) for brain in results: logger.info("Checking %s" % brain.getPath()) obj = brain.getObject() storage = IDataStorage(obj) for row in storage: if not row.get('__uuid__'): new_uid = str(uuid.uuid4()) logger.info(new_uid) row['__uuid__'] = new_uid logger.info("Done for %s" % brain.getPath()) logger.info("uuid generation done")
def eval_mappings(self, index, storage=None): """Compute mappings for TAL evaluation""" if storage is None: storage = IDataStorage(self.context) portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state') current_row = self._get_row_data(storage[index]) return { 'row': current_row, 'rows': storage, 'index': index, 'portal': portal_state.portal(), 'context': self.context, 'request': self.request, }
def reindex_rows(self, context, uids, storage=None): """Reindex one of more rows using uuid information""" if isinstance(uids, basestring): uids = [uids] storage = storage or IDataStorage(context) for uid in uids: path = '%s/row-%s' % ('/'.join(context.getPhysicalPath()), uid) data = storage.get(uid) self.uncatalog_object(path) if data.get('__label__'): self.catalog_object(CatalogDictLabelWrapper( data, context, path), uid=path) else: self.catalog_object(CatalogDictWrapper(data, context, path), uid=path)
def resolve_path(self, path): # Override of original method: return the fake object # /Plone/path/to/tpage/row-uuid try: path_elements = path.split('/') tp_path = '/'.join(path_elements[:-1]) uuid = path_elements[-1][4:] tp = self.unrestrictedTraverse(tp_path) storage = IDataStorage(tp) data = storage[uuid] if data.get('__label__'): CatalogDictLabelWrapper(data, tp, path) return CatalogDictWrapper(storage[uuid], tp, path) except Exception: # Very ugly, but Plone code does the same... pass
def clearFindAndRebuild(self): """Empties catalog, then finds all tablepage objects and reindexes all rows. This may take some time. """ self.manage_catalogClear() portal = aq_parent(aq_inner(self)) catalog = portal.portal_catalog pages = catalog(object_provides=ITablePage.__identifier__) for page in pages: obj = page.getObject() storage = IDataStorage(obj) for row in storage: if row.get('__label__'): self.catalog_label_row(obj, row) else: self.catalog_row(obj, row)
def setUp(self): portal = self.layer['portal'] wtool = portal.portal_workflow login(portal, 'user1') portal.invokeFactory(type_name='TablePage', id='table_page', title="The Table Document") tp = portal.table_page tp.edit(textBefore='<p>Lorem Ipsum</p>', pageColumns=[{'id': 'col_a', 'label': 'Col A', 'description': '', 'type': 'String', 'vocabulary': '', 'options': []}]) login(portal, TEST_USER_NAME) wtool.doActionFor(tp, 'publish') storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'foo', '__uuid__': 'aaa'}) # 0 storage.add({'__creator__': 'user1', 'col_a': 'bar', '__uuid__': 'bbb'}) # 1 storage.add({'__label__': 'A label', '__uuid__': 'ccc'}) # 2 storage.add({'__label__': 'B label', '__uuid__': 'ddd'}) # 3 storage.add({'__creator__': 'user1', 'col_a': 'baz', '__uuid__': 'eee'}) # 4 storage.add({'__creator__': 'user1', 'col_a': 'qux', '__uuid__': 'fff'}) # 5
def test_move_my_row(self): """Owners normally can't move rows""" portal = self.layer['portal'] tp = portal.table_page storage = IDataStorage(tp) storage.add({'__creator__': 'user1', 'col_a': 'foo data from user1', '__uuid__': 'aaa'}) storage.add({'__creator__': 'user1', 'col_a': 'some other futile data', '__uuid__': 'bbb'}) login(portal, 'user1') self.assertRaises(Unauthorized, tp.restrictedTraverse, '@@move-record')