Commit 914d58f5 authored by Sebastien Robin's avatar Sebastien Robin

core: fix export of categories

parent fcaa4499
......@@ -15,7 +15,7 @@ for base_cat_id in context.REQUEST['category_list']:
for cat in context.portal_catalog(portal_type='Category',
sort_on=(('path', 'ascending'),),# This sorting is not enough.
limit=None,
**{'default_%s_uid' % (base_cat.getId(),): base_cat.getUid()}):
relative_url="%s/%%" % base_cat.getRelativeUrl()):
  • Beware of unescaped underscores !

    Also, it would be more efficient to use path here, as it is already used for sorting: then the query becomes a range search in the index on path columns, plus ad-hoc checking of portal type on each row (not a big deal I think, although it would be nice to discard it altogether). EDIT: Instead, in this version it will either be a full index traversal to materialise the sort plus two ad-hoc checks by line, or a range search in another index to materialise the condition plus a temp-table sorting after all rows are found.

    Edited by Vincent Pelletier
Please register or sign in to reply
cat_relative_url_path_list = cat.getRelativeUrl().split('/')
cat_depth = len(cat_relative_url_path_list)
temporary_category_list.append((cat_relative_url_path_list, cat))
......
......@@ -664,8 +664,26 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(response.getStatus(), 401)
self.assertNotIn("Also, the following error occurred", str(response))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Core))
return suite
def testCategoryExport(self):
"""
Check we can export categories in a spreadsheet
"""
portal = self.getPortalObject()
category_tool = portal.portal_categories
base_category_id = "test_category_export"
if getattr(category_tool, base_category_id, None) is not None:
category_tool.manage_delObjects(ids=[base_category_id])
base_category = category_tool.newContent(portal_type="Base Category",
id=base_category_id)
base_category.newContent(portal_type="Category", reference="Rfoo",
id="foo", codification="CFoo", title="Foo")
base_category.newContent(portal_type="Category", short_title="SBar",
id="bar", int_index=3, description="desc", title="Bar")
self.tic()
self.portal.REQUEST.set("format", "csv")
self.portal.REQUEST.set("category_list", [base_category_id])
csv_data = category_tool.CategoryTool_exportCategory()
self.assertEqual("""Path,Id,Title,Short Title,Reference,Codification,Int Index,Description
*,bar,Bar,SBar,,,3,desc
*,foo,Foo,,Rfoo,CFoo,,
""", csv_data)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment