Ignore:
Timestamp:
16 Dec 2014, 09:02:13 (10 years ago)
Author:
Henrik Bettermann
Message:

Some repairs of document and contract batch processors (work in progress!).

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
4 edited

Legend:

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

    r12212 r12250  
    381381
    382382    location_fields = []
    383     additional_fields = ['document_id', 'class_name']
     383    additional_fields = ['class_name']
    384384    additional_headers = ['class_name']
    385385
     
    422422        document_id = row['document_id'].strip('#')
    423423        parent[document_id] = obj
     424        # Reset _curr_doc_id if document_id has been imported
     425        site = grok.getSite()
     426        if row.get('document_id', None) not in (None, IGNORE_MARKER):
     427            site._curr_doc_id -= 1
    424428        return
    425429
     
    445449            if class_name != self.factory_name.strip('waeup.'):
    446450                errs.append(('class_name','wrong processor'))
     451        try:
     452            # Correct doc_id counter. As the IConverter for documents
     453            # creates document objects that are not used afterwards, we
     454            # have to fix the site-wide doc_id counter.
     455            site = grok.getSite()
     456            site._curr_doc_id -= 1
     457        except (KeyError, TypeError, AttributeError):
     458                pass
    447459        # We have to check document_id.
    448460        document_id = row.get('document_id', None)
     
    478490
    479491    location_fields = []
    480     additional_fields = ['contract_id', 'class_name']
     492    additional_fields = ['class_name']
    481493    additional_headers = ['class_name']
    482494
     
    519531        contract_id = row['contract_id'].strip('#')
    520532        parent[contract_id] = obj
     533        # Reset _curr_con_id if contract_id has been imported
     534        site = grok.getSite()
     535        if row.get('contract_id', None) not in (None, IGNORE_MARKER):
     536            site._curr_con_id -= 1
    521537        return
    522538
     
    542558            if class_name != self.factory_name.strip('waeup.'):
    543559                errs.append(('class_name','wrong processor'))
     560        try:
     561            # Correct con_id counter. As the IConverter for contracts
     562            # creates contract objects that are not used afterwards, we
     563            # have to fix the site-wide con_id counter.
     564            site = grok.getSite()
     565            site._curr_con_id -= 1
     566        except (KeyError, TypeError, AttributeError):
     567                pass
    544568        # We have to check contract_id.
    545569        contract_id = row.get('contract_id', None)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12143 r12250  
    322322
    323323    def test_addEntry(self):
     324        self.assertEqual(self.app._curr_doc_id, 102)
    324325        self.assertEqual(len(self.customer['documents'].keys()),1)
    325326        document1 = createObject(u'waeup.CustomerSampleDocument')
     
    330331        self.assertEqual(len(self.customer['documents'].keys()),2)
    331332        self.assertEqual(self.customer['documents']['d234'].document_id, 'd234')
    332         document2 = createObject(u'waeup.CustomerSampleDocument')
    333         document1.document_id = 'nonsense'
     333        # _curr_doc_id hasn't changed
     334        self.assertEqual(self.app._curr_doc_id, 102)
    334335
    335336    def test_checkConversion(self):
     337        self.assertEqual(self.app._curr_doc_id, 102)
    336338        errs, inv_errs, conv_dict = self.processor.checkConversion(
    337339            dict(document_id='d126', class_name='CustomerSampleDocument'))
     
    347349            mode='update'))
    348350        self.assertEqual(len(errs),1)
     351        # _curr_doc_id hasn't changed
     352        self.assertEqual(self.app._curr_doc_id, 102)
    349353
    350354    def test_import(self):
     
    455459
    456460    def test_addEntry(self):
     461        self.assertEqual(self.app._curr_con_id, 102)
    457462        self.assertEqual(len(self.customer['contracts'].keys()),1)
    458463        contract1 = createObject(u'waeup.SampleContract')
     
    463468        self.assertEqual(len(self.customer['contracts'].keys()),2)
    464469        self.assertEqual(self.customer['contracts']['c234'].contract_id, 'c234')
    465         contract2 = createObject(u'waeup.SampleContract')
    466         contract1.contract_id = 'nonsense'
     470        # _curr_con_id hasn't changed
     471        self.assertEqual(self.app._curr_con_id, 102)
    467472
    468473    def test_checkConversion(self):
     474        self.assertEqual(self.app._curr_con_id, 102)
    469475        errs, inv_errs, conv_dict = self.processor.checkConversion(
    470476            dict(contract_id='c126', class_name='SampleContract',
     
    477483            dict(contract_id='c127', class_name='WrongContract'))
    478484        self.assertEqual(len(errs),1)
     485        # _curr_con_id hasn't changed
     486        self.assertEqual(self.app._curr_con_id, 102)
    479487
    480488    def test_import(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/batching.py

    r12249 r12250  
    5656    factory_name = 'waeup.PDFDocument'
    5757
     58    location_fields = []
     59    additional_fields = ['class_name']
     60    additional_headers = ['class_name']
     61
    5862    mode = None
    5963
     
    99103        return
    100104
     105    def checkConversion(self, row, mode='ignore'):
     106        """Validates all values in row.
     107        """
     108        errs, inv_errs, conv_dict = super(
     109            PDFDocumentProcessor, self).checkConversion(row, mode=mode)
     110        # We need to check if the class_name corresponds with the
     111        # processor chosen. This is to avoid accidentally wrong imports.
     112        if mode != 'remove':
     113            class_name = row.get('class_name', None)
     114            if class_name != self.factory_name.strip('waeup.'):
     115                errs.append(('class_name','wrong processor'))
     116        # We have to check document_id.
     117        document_id = row.get('document_id', None)
     118        if mode == 'create':
     119            if not document_id:
     120                document_id = generate_document_id()
     121                conv_dict['document_id'] = document_id
     122                return errs, inv_errs, conv_dict
     123            cat = queryUtility(ICatalog, name='documents_catalog')
     124            results = list(
     125                cat.searchResults(document_id=(document_id, document_id)))
     126            if results:
     127                # document_id must not exist.
     128                errs.append(('document_id','id exists'))
     129        else:
     130            if not document_id.startswith('d'):
     131                errs.append(('document_id','invalid format'))
     132        return errs, inv_errs, conv_dict
     133
    101134
    102135class HTMLDocumentProcessor(PDFDocumentProcessor):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/batching.py

    r12178 r12250  
    338338                obj = self.callFactory()
    339339                # Override all values in row, also
    340                 # customer ids which have been
     340                # ids which have been
    341341                # generated in the respective __init__ methods before.
    342342                self.updateEntry(obj, row, site, base)
Note: See TracChangeset for help on using the changeset viewer.