Ignore:
Timestamp:
21 Dec 2014, 10:35:54 (10 years ago)
Author:
Henrik Bettermann
Message:

Reorganize batch processor classes to ease customization.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py

    r12258 r12281  
    4343from waeup.ikoba.customers.interfaces import (
    4444    ICustomer, ICustomerUpdateByRegNo,
    45     ICustomerDocument, IContract, ISampleContract)
     45    ICustomerSampleDocument, ISampleContract)
    4646from waeup.ikoba.customers.workflow import  (
    4747    IMPORTABLE_REGISTRATION_STATES, IMPORTABLE_REGISTRATION_TRANSITIONS)
     
    366366        return result
    367367
    368 class CustomerDocumentProcessor(CustomerProcessorBase):
    369     """A batch processor for ICustomerDocument objects.
     368class CustomerDocumentProcessorBase(CustomerProcessorBase):
     369    """A batch processor for customer documents.
     370
     371    This is a baseclass.
    370372    """
    371373    grok.implements(IBatchProcessor)
    372374    grok.provides(IBatchProcessor)
    373375    grok.context(Interface)
    374     util_name = 'customerdocumentprocessor'
    375     grok.name(util_name)
    376 
    377     name = _('CustomerDocument Processor')
    378     iface = ICustomerDocument
    379     factory_name = 'waeup.CustomerSampleDocument'
     376
     377    grok.baseclass()
     378
     379    util_name = None
     380    name = None
     381    iface = None
     382    factory_name = None
    380383
    381384    location_fields = []
     
    384387
    385388    def checkHeaders(self, headerfields, mode='ignore'):
    386         super(CustomerDocumentProcessor, self).checkHeaders(headerfields)
     389        super(CustomerDocumentProcessorBase, self).checkHeaders(headerfields)
    387390        if mode in ('update', 'remove') and not 'document_id' in headerfields:
    388391            raise FatalCSVError(
     
    412415        if 'document_id' in row and row['document_id'] in (None, IGNORE_MARKER):
    413416            row.pop('document_id')
    414         items_changed = super(CustomerDocumentProcessor, self).updateEntry(
     417        items_changed = super(CustomerDocumentProcessorBase, self).updateEntry(
    415418            obj, row, site, filename)
    416419        customer = self.getParent(row, site).__parent__
     
    440443        """
    441444        errs, inv_errs, conv_dict = super(
    442             CustomerDocumentProcessor, self).checkConversion(row, mode=mode)
     445            CustomerDocumentProcessorBase, self).checkConversion(row, mode=mode)
    443446        # We need to check if the class_name corresponds with the
    444447        # processor chosen. This is to avoid accidentally wrong imports.
     
    450453
    451454
    452 class ContractProcessor(CustomerProcessorBase):
    453     """A batch processor for IContract objects.
     455class CustomerSampleDocumentProcessor(CustomerDocumentProcessorBase):
     456    """A batch processor for ICustomerSampleDocument objects.
     457    """
     458    util_name = 'customersampledocumentprocessor'
     459    grok.name(util_name)
     460
     461    name = _('Customer Sample Document Processor')
     462    iface = ICustomerSampleDocument
     463    factory_name = 'waeup.CustomerSampleDocument'
     464
     465
     466class ContractProcessorBase(CustomerProcessorBase):
     467    """A batch processor for contracts.
     468
     469    This is a baseclass.
    454470    """
    455471    grok.implements(IBatchProcessor)
    456472    grok.provides(IBatchProcessor)
    457473    grok.context(Interface)
    458     util_name = 'contractprocessor'
    459     grok.name(util_name)
    460 
    461     name = _('Contract Processor')
    462     iface = ISampleContract
    463     factory_name = 'waeup.SampleContract'
     474
     475    grok.baseclass()
     476
     477    util_name = None
     478    name = None
     479    iface = None
     480    factory_name = None
    464481
    465482    location_fields = []
     
    468485
    469486    def checkHeaders(self, headerfields, mode='ignore'):
    470         super(ContractProcessor, self).checkHeaders(headerfields)
     487        super(ContractProcessorBase, self).checkHeaders(headerfields)
    471488        if mode in ('update', 'remove') and not 'contract_id' in headerfields:
    472489            raise FatalCSVError(
     
    499516        if 'contract_id' in row and row['contract_id'] in (None, IGNORE_MARKER):
    500517            row.pop('contract_id')
    501         items_changed = super(ContractProcessor, self).updateEntry(
     518        items_changed = super(ContractProcessorBase, self).updateEntry(
    502519            obj, row, site, filename)
    503520        customer = self.getParent(row, site).__parent__
     
    527544        """
    528545        errs, inv_errs, conv_dict = super(
    529             ContractProcessor, self).checkConversion(row, mode=mode)
     546            ContractProcessorBase, self).checkConversion(row, mode=mode)
    530547        # We need to check if the class_name corresponds with the
    531548        # processor chosen. This is to avoid accidentally wrong imports.
     
    535552                errs.append(('class_name','wrong processor'))
    536553        return errs, inv_errs, conv_dict
     554
     555
     556class SampleContractProcessor(ContractProcessorBase):
     557    """A batch processor for ISampleContract objects.
     558    """
     559    util_name = 'samplecontractprocessor'
     560    grok.name(util_name)
     561
     562    name = _('Sample Contract Processor')
     563    iface = ISampleContract
     564    factory_name = 'waeup.SampleContract'
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12261 r12281  
    3737    IBatchProcessor, FatalCSVError, IUserAccount, VERIFIED)
    3838from waeup.ikoba.customers.batching import (
    39     CustomerProcessor, CustomerDocumentProcessor, ContractProcessor)
     39    CustomerProcessor, CustomerSampleDocumentProcessor, SampleContractProcessor)
    4040from waeup.ikoba.customers.customer import Customer
    4141from waeup.ikoba.customers.documents import CustomerSampleDocument
     
    274274        shutil.rmtree(os.path.dirname(fin_file))
    275275
    276 class CustomerDocumentProcessorTest(CustomerImportExportSetup):
     276class CustomerSampleDocumentProcessorTest(CustomerImportExportSetup):
    277277
    278278    def setUp(self):
    279         super(CustomerDocumentProcessorTest, self).setUp()
     279        super(CustomerSampleDocumentProcessorTest, self).setUp()
    280280
    281281        customer = Customer()
     
    292292        shutil.rmtree(os.path.dirname(fin_file))
    293293
    294         self.processor = CustomerDocumentProcessor()
     294        self.processor = CustomerSampleDocumentProcessor()
    295295        self.csv_file = os.path.join(
    296296            self.workdir, 'sample_document_data.csv')
     
    301301        assert verifyObject(IBatchProcessor, self.processor) is True
    302302        assert verifyClass(
    303             IBatchProcessor, CustomerDocumentProcessor) is True
     303            IBatchProcessor, CustomerSampleDocumentProcessor) is True
    304304
    305305    def test_getEntry(self):
     
    369369         # Logging message from updateEntry
    370370        self.assertTrue(
    371             'INFO - system - CustomerDocument Processor - '
     371            'INFO - system - Customer Sample Document Processor - '
    372372            'sample_document_data - X666666 - %s - updated: title=My 4th doc'
    373373            % docid in logcontent)
     
    404404
    405405
    406 class ContractProcessorTest(CustomerImportExportSetup):
     406class SampleContractProcessorTest(CustomerImportExportSetup):
    407407
    408408    def setUp(self):
    409         super(ContractProcessorTest, self).setUp()
     409        super(SampleContractProcessorTest, self).setUp()
    410410
    411411        customer = Customer()
     
    422422        shutil.rmtree(os.path.dirname(fin_file))
    423423
    424         self.processor = ContractProcessor()
     424        self.processor = SampleContractProcessor()
    425425        self.csv_file = os.path.join(
    426426            self.workdir, 'sample_contract_data.csv')
     
    431431        assert verifyObject(IBatchProcessor, self.processor) is True
    432432        assert verifyClass(
    433             IBatchProcessor, ContractProcessor) is True
     433            IBatchProcessor, SampleContractProcessor) is True
    434434
    435435    def test_getEntry(self):
     
    502502            if len(i) > 10][0]
    503503        self.assertTrue(
    504             'INFO - system - Contract Processor - sample_contract_data - '
     504            'INFO - system - Sample Contract Processor - sample_contract_data - '
    505505            'X666666 - %s - updated: title=My 4th contract, '
    506506            'product_object=SAM, document_object=DOC1' % conid
Note: See TracChangeset for help on using the changeset viewer.