Changeset 12077 for main/waeup.ikoba/trunk
- Timestamp:
- 28 Nov 2014, 07:29:14 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/products
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/products/export.py
r12073 r12077 19 19 """ 20 20 import grok 21 from zope.securitypolicy.interfaces import IPrincipalRoleMap 21 22 from waeup.ikoba.interfaces import ICSVExporter 22 23 from waeup.ikoba.interfaces import MessageFactory as _ … … 24 25 from waeup.ikoba.utils.helpers import iface_names 25 26 from waeup.ikoba.products.interfaces import IProduct 27 28 29 class ProductExporter(grok.GlobalUtility, ExporterBase): 30 """Exporter for products. 31 """ 32 grok.implements(ICSVExporter) 33 grok.name('products') 34 35 #: Fieldnames considered by this exporter 36 fields = tuple(sorted(iface_names(IProduct))) + ( 37 'users_with_local_roles',) 38 39 #: The title under which this exporter will be displayed 40 title = _(u'Products') 41 42 def mangle_value(self, value, name, context=None): 43 """Hook for mangling values in derived classes 44 """ 45 if name == 'users_with_local_roles': 46 value = [] 47 role_map = IPrincipalRoleMap(context) 48 for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): 49 value.append({'user_name':user_name,'local_role':local_role}) 50 return super(ProductExporter, self).mangle_value( 51 value, name, context) 52 53 def export(self, products, filepath=None): 54 """Export `products`, an iterable, as CSV file. 55 56 If `filepath` is ``None``, a raw string with CSV data is returned. 57 """ 58 writer, outfile = self.get_csv_writer(filepath) 59 for product in products: 60 self.write_item(product, writer) 61 return self.close_outfile(filepath, outfile) 62 63 def export_all(self, site, filepath=None): 64 """Export products in productscontainer into filepath as CSV data. 65 66 If `filepath` is ``None``, a raw string with CSV data is returned. 67 """ 68 products = site.get('products', {}) 69 return self.export(products.values(), filepath) -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_batching.py
r12073 r12077 31 31 from zope.catalog.interfaces import ICatalog 32 32 from zope.interface.verify import verifyClass, verifyObject 33 from zope.securitypolicy.interfaces import IPrincipalRoleManager 33 34 34 35 from waeup.ikoba.app import Company … … 82 83 self.app['products'][product.product_id] = self.product = product 83 84 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 85 role_manager = IPrincipalRoleManager(product) 86 role_manager.assignRoleToPrincipal(u'johnsrole', u'john') 84 87 return 85 88 -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_browser.py
r12073 r12077 55 55 return None 56 56 57 class Products sFullSetup(FunctionalTestCase):57 class ProductsFullSetup(FunctionalTestCase): 58 58 # A test case that only contains a setup and teardown 59 59 # … … 67 67 68 68 def setUp(self): 69 super(Products sFullSetup, self).setUp()69 super(ProductsFullSetup, self).setUp() 70 70 71 71 # Setup a sample site for each test … … 113 113 114 114 def tearDown(self): 115 super(Products sFullSetup, self).tearDown()115 super(ProductsFullSetup, self).tearDown() 116 116 clearSite() 117 117 shutil.rmtree(self.dc_root) 118 118 119 class ProductsContainerUITests(Products sFullSetup):119 class ProductsContainerUITests(ProductsFullSetup): 120 120 # Tests for ProductsContainer class views and pages 121 121 … … 163 163 164 164 165 class ProductsUITests(Products sFullSetup):165 class ProductsUITests(ProductsFullSetup): 166 166 # Tests for Products class views and pages 167 167
Note: See TracChangeset for help on using the changeset viewer.