Changeset 12279 for main/waeup.ikoba/trunk/src/waeup/ikoba
- Timestamp:
- 21 Dec 2014, 10:13:45 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/customers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py
r12275 r12279 27 27 from waeup.ikoba.customers.catalog import CustomersQuery 28 28 from waeup.ikoba.customers.interfaces import ( 29 ICustomer, ICSVCustomerExporter, ICustomerDocument,30 I SampleContract)29 ICustomer, ICSVCustomerExporter, 30 ICustomerSampleDocument, ISampleContract) 31 31 from waeup.ikoba.utils.batching import ExporterBase 32 32 from waeup.ikoba.utils.helpers import iface_names, to_timezone … … 34 34 #: A tuple containing all exporter names referring to customers or 35 35 #: subobjects thereof. 36 EXPORTER_NAMES = ('customers', 'customer documents')36 EXPORTER_NAMES = ('customers', 'customersampledocuments', 'samplecontracts') 37 37 38 38 … … 42 42 return cust_filter.query() 43 43 44 def get_documents(customers ):44 def get_documents(customers, class_name): 45 45 """Get all documents of `customers`. 46 46 """ … … 48 48 for customer in customers: 49 49 for document in customer.get('documents', {}).values(): 50 documents.append(document) 50 if document.class_name == class_name: 51 documents.append(document) 51 52 return documents 52 53 53 def get_contracts(customers ):54 def get_contracts(customers, class_name): 54 55 """Get all contracts of `customers`. 55 56 """ … … 57 58 for customer in customers: 58 59 for contract in customer.get('contracts', {}).values(): 59 contracts.append(contract) 60 if contract.class_name == class_name: 61 contracts.append(contract) 60 62 return contracts 61 63 … … 151 153 152 154 153 class CustomerDocumentExporter (grok.GlobalUtility, CustomerExporterBase):154 """Exporter for Customer Document instances.155 """ 156 grok.name('customerdocuments')157 158 iface = ICustomerDocument159 160 #: The title under which this exporter will be displayed161 title = _(u'Customer Documents')155 class CustomerDocumentExporterBase(grok.GlobalUtility, CustomerExporterBase): 156 """Exporter for Customer Document instances. 157 158 This is a baseclass. 159 """ 160 grok.baseclass() 161 iface = None 162 class_name = None 163 title = None 162 164 163 165 #: Fieldnames considered by this exporter … … 177 179 178 180 def filter_func(self, x, **kw): 179 return get_documents(x )181 return get_documents(x, self.class_name) 180 182 181 183 def mangle_value(self, value, name, context=None): … … 184 186 value = value.messages 185 187 return super( 186 CustomerDocumentExporter , self).mangle_value(188 CustomerDocumentExporterBase, self).mangle_value( 187 189 value, name, context=context) 188 190 189 191 190 class ContractExporter(grok.GlobalUtility, CustomerExporterBase): 192 class CustomerSampleDocumentExporter(CustomerDocumentExporterBase): 193 """Exporter for CustomerSampleDocument instances. 194 """ 195 grok.name('customersampledocuments') 196 197 iface = ICustomerSampleDocument 198 class_name = 'CustomerSampleDocument' 199 title = _(u'Customer Sample Documents') 200 201 202 class SampleContractExporterBase(grok.GlobalUtility, CustomerExporterBase): 191 203 """Exporter for Contract instances. 192 """ 193 grok.name('contracts')194 195 iface = ISampleContract196 197 #: The title under which this exporter will be displayed198 title = _(u'Contracts')204 205 This is a baseclass. 206 """ 207 grok.baseclass() 208 iface = None 209 class_name = None 210 title = None 199 211 200 212 #: Fieldnames considered by this exporter … … 211 223 212 224 def filter_func(self, x, **kw): 213 return get_contracts(x )225 return get_contracts(x, self.class_name) 214 226 215 227 def mangle_value(self, value, name, context=None): … … 225 237 return mangled_value 226 238 return super( 227 ContractExporter, self).mangle_value(239 SampleContractExporterBase, self).mangle_value( 228 240 value, name, context=context) 241 242 243 class SampleContractExporter(SampleContractExporterBase): 244 """Exporter for sample contracts. 245 """ 246 grok.name('samplecontracts') 247 iface = ISampleContract 248 class_name = 'SampleContract' 249 title = _(u'Sample Contracts') -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py
r12260 r12279 251 251 252 252 253 class ICustomerSampleDocument(ICustomerDocument): 254 """A customer sample document object. 255 256 """ 257 258 253 259 class ICustomerPDFDocument(ICustomerDocument): 254 """A customer document.260 """A customer pdf document object. 255 261 256 262 """ -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py
r12259 r12279 31 31 from waeup.ikoba.customers.catalog import CustomersQuery 32 32 from waeup.ikoba.customers.export import ( 33 CustomerExporter, Customer DocumentExporter,ContractExporter,33 CustomerExporter, CustomerSampleDocumentExporter, SampleContractExporter, 34 34 get_customers) 35 35 from waeup.ikoba.customers.interfaces import ICSVCustomerExporter … … 131 131 return 132 132 133 class Customer DocumentExporterTest(CustomerImportExportSetup):133 class CustomerSampleDocumentExporterTest(CustomerImportExportSetup): 134 134 135 135 layer = FunctionalLayer 136 136 137 137 def setUp(self): 138 super(Customer DocumentExporterTest, self).setUp()138 super(CustomerSampleDocumentExporterTest, self).setUp() 139 139 self.setup_for_export() 140 140 return … … 142 142 def test_ifaces(self): 143 143 # make sure we fullfill interface contracts 144 obj = Customer DocumentExporter()144 obj = CustomerSampleDocumentExporter() 145 145 verifyObject(ICSVCustomerExporter, obj) 146 verifyClass(ICSVCustomerExporter, Customer DocumentExporter)146 verifyClass(ICSVCustomerExporter, CustomerSampleDocumentExporter) 147 147 return 148 148 149 149 def test_get_as_utility(self): 150 150 # we can get a documents exporter as utility 151 result = queryUtility(ICSVExporter, name="customer documents")151 result = queryUtility(ICSVExporter, name="customersampledocuments") 152 152 self.assertTrue(result is not None) 153 153 return … … 157 157 document = CustomerSampleDocument() 158 158 document.document_id = u'DOC1' 159 exporter = Customer DocumentExporter()159 exporter = CustomerSampleDocumentExporter() 160 160 exporter.export([document], self.outfile) 161 161 result = open(self.outfile, 'rb').read() … … 172 172 self.setup_customer(self.customer) 173 173 document = self.customer['documents']['DOC1'] 174 exporter = Customer DocumentExporter()174 exporter = CustomerSampleDocumentExporter() 175 175 exporter.export([document], self.outfile) 176 176 result = open(self.outfile, 'rb').read() … … 191 191 # set values we can expect in export file 192 192 self.setup_customer(self.customer) 193 exporter = Customer DocumentExporter()193 exporter = CustomerSampleDocumentExporter() 194 194 exporter.export_all(self.app, self.outfile) 195 195 result = open(self.outfile, 'rb').read() … … 209 209 # set values we can expect in export file 210 210 self.setup_customer(self.customer) 211 exporter = Customer DocumentExporter()211 exporter = CustomerSampleDocumentExporter() 212 212 exporter.export_customer(self.customer, self.outfile) 213 213 result = open(self.outfile, 'rb').read() … … 224 224 225 225 226 class ContractExporterTest(CustomerImportExportSetup):226 class SampleContractExporterTest(CustomerImportExportSetup): 227 227 228 228 layer = FunctionalLayer 229 229 230 230 def setUp(self): 231 super( ContractExporterTest, self).setUp()231 super(SampleContractExporterTest, self).setUp() 232 232 self.setup_for_export() 233 233 return … … 235 235 def test_ifaces(self): 236 236 # make sure we fullfill interface contracts 237 obj = ContractExporter()237 obj = SampleContractExporter() 238 238 verifyObject(ICSVCustomerExporter, obj) 239 verifyClass(ICSVCustomerExporter, ContractExporter)239 verifyClass(ICSVCustomerExporter, SampleContractExporter) 240 240 return 241 241 242 242 def test_get_as_utility(self): 243 243 # we can get a contracts exporter as utility 244 result = queryUtility(ICSVExporter, name=" contracts")244 result = queryUtility(ICSVExporter, name="samplecontracts") 245 245 self.assertTrue(result is not None) 246 246 return … … 250 250 contract = SampleContract() 251 251 contract.contract_id = u'CON1' 252 exporter = ContractExporter()252 exporter = SampleContractExporter() 253 253 exporter.export([contract], self.outfile) 254 254 result = open(self.outfile, 'rb').read() … … 267 267 # set values we can expect in export file 268 268 self.setup_customer(self.customer) 269 exporter = ContractExporter()269 exporter = SampleContractExporter() 270 270 exporter.export([self.contract], self.outfile) 271 271 result = open(self.outfile, 'rb').read() … … 286 286 # set values we can expect in export file 287 287 self.setup_customer(self.customer) 288 exporter = ContractExporter()288 exporter = SampleContractExporter() 289 289 exporter.export_all(self.app, self.outfile) 290 290 result = open(self.outfile, 'rb').read() … … 305 305 # set values we can expect in export file 306 306 self.setup_customer(self.customer) 307 exporter = ContractExporter()307 exporter = SampleContractExporter() 308 308 exporter.export_customer(self.customer, self.outfile) 309 309 result = open(self.outfile, 'rb').read()
Note: See TracChangeset for help on using the changeset viewer.