Ignore:
Timestamp:
18 Dec 2014, 12:58:12 (10 years ago)
Author:
Henrik Bettermann
Message:

Change document_id generation algorithm. Use Universally Unique IDentifiers instead of consecutive numbers.

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

Legend:

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

    r12207 r12256  
    4242    grok.implements(ICompany)
    4343
    44     _curr_doc_id = 101
    45 
    4644    _curr_con_id = 101
    4745
     
    5654        self.setup()
    5755        return
    58 
    59     @property
    60     def unique_document_id(self):
    61         """A unique document id for all documents in company.
    62 
    63         The document id returned is guaranteed to be unique.
    64 
    65         Once a document id was issued, it won't be issued again.
    66 
    67         Obtaining a document id is currently not thread-safe but can be
    68         made easily by enabling commented lines.
    69         """
    70         # lock.acquire() # lock data
    71         new_id = u'd%s' % (self._curr_doc_id)
    72         self._curr_doc_id += 1
    73         # self._p_changed = True
    74         # commit()
    75         # lock.release() # end of lock
    76         return new_id
    7756
    7857    @property
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py

    r12250 r12256  
    4040from waeup.ikoba.interfaces import IIkobaUtils
    4141from waeup.ikoba.interfaces import MessageFactory as _
    42 from waeup.ikoba.documents.utils import generate_document_id
    4342from waeup.ikoba.customers.utils import generate_contract_id
    4443from waeup.ikoba.customers.interfaces import (
     
    398397
    399398    def getEntry(self, row, site):
    400         documents = self.getParent(row, site)
    401         if documents is None:
    402             return None
    403399        document_id = row.get('document_id', None)
    404400        if document_id is None:
    405401            return None
    406         entry = documents.get(document_id)
    407         return entry
     402        cat = queryUtility(ICatalog, name='documents_catalog')
     403        results = list(cat.searchResults(document_id=(document_id, document_id)))
     404        if results:
     405            return results[0]
     406        return None
     407
     408        #documents = self.getParent(row, site)
     409        #if documents is None:
     410        #    return None
     411        #document_id = row.get('document_id', None)
     412        #if document_id is None:
     413        #    return None
     414        #entry = documents.get(document_id)
     415        #return entry
    408416
    409417    def updateEntry(self, obj, row, site, filename):
    410418        """Update obj to the values given in row.
    411419        """
     420        # Remove document_id from row if empty
     421        if 'document_id' in row and row['document_id'] in (None, IGNORE_MARKER):
     422            row.pop('document_id')
    412423        items_changed = super(CustomerDocumentProcessor, self).updateEntry(
    413424            obj, row, site, filename)
    414425        customer = self.getParent(row, site).__parent__
    415426        customer.__parent__.logger.info(
    416             '%s - %s - %s - updated: %s'
    417             % (self.name, filename, customer.customer_id, items_changed))
     427            '%s - %s - %s - %s - updated: %s'
     428            % (self.name, filename, customer.customer_id, obj.document_id,
     429               items_changed))
    418430        return
    419431
    420432    def addEntry(self, obj, row, site):
    421433        parent = self.getParent(row, site)
    422         document_id = row['document_id'].strip('#')
    423         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
     434        parent.addDocument(obj)
    428435        return
    429436
     
    449456            if class_name != self.factory_name.strip('waeup.'):
    450457                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
    459         # We have to check document_id.
    460         document_id = row.get('document_id', None)
    461         if mode == 'create':
    462             if not document_id:
    463                 document_id = generate_document_id()
    464                 conv_dict['document_id'] = document_id
    465                 return errs, inv_errs, conv_dict
    466             cat = queryUtility(ICatalog, name='documents_catalog')
    467             results = list(
    468                 cat.searchResults(document_id=(document_id, document_id)))
    469             if results:
    470                 # document_id must not exist.
    471                 errs.append(('document_id','id exists'))
    472         else:
    473             if not document_id.startswith('d'):
    474                 errs.append(('document_id','invalid format'))
    475458        return errs, inv_errs, conv_dict
    476459
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12246 r12256  
    817817    pnav = 4
    818818
    819     form_fields = grok.AutoFields(ICustomerDocument)
     819    form_fields = grok.AutoFields(ICustomerDocument).omit('document_id')
    820820
    821821    @property
     
    876876    @property
    877877    def form_fields(self):
    878         return grok.AutoFields(self.context.form_fields_interface)
     878        return grok.AutoFields(
     879            self.context.form_fields_interface).omit('document_id')
    879880
    880881    def update(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12214 r12256  
    3333from waeup.ikoba.interfaces import (
    3434    IFileStoreNameChooser, IFileStoreHandler,
    35     IIkobaUtils, IExtFileStore)
     35    IIkobaUtils, IExtFileStore, IIDSource)
    3636from waeup.ikoba.customers.interfaces import (
    3737    ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument,
     
    7676    # tuple should contain only a single filename string.
    7777    filenames = ()
     78
     79    def __init__(self):
     80        super(CustomerDocumentBase, self).__init__()
     81        source = getUtility(IIDSource)
     82        self.document_id = unicode(source.get_hex_uuid())
     83        return
    7884
    7985    @property
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/sample_contract_data.csv

    r12131 r12256  
    11class_name,contract_id,reg_number,title,product_object,document_object
    2 SampleContract,c3,1,My first contract,SAM,d101
    3 SampleContract,c4,2,My second contract,SAM,d101
    4 SampleContract,c5,3,My third contract,SAM,d101
    5 SampleContract,,1,My 4th contract,SAM,d101
    6 SampleContract,c5,2,My stolen contract,SAM,d101
     2SampleContract,c3,1,My first contract,SAM,DOC1
     3SampleContract,c4,2,My second contract,SAM,DOC1
     4SampleContract,c5,3,My third contract,SAM,DOC1
     5SampleContract,,1,My 4th contract,SAM,DOC1
     6SampleContract,c5,2,My stolen contract,SAM,DOC1
    77SampleContract,c6,3,My 5th contract,SAM,NONEXISTENT
    8 SampleContract,c7,3,My sixt contract,NONEXISTENT,d101
     8SampleContract,c7,3,My sixt contract,NONEXISTENT,DOC1
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12250 r12256  
    132132        document = createObject('waeup.CustomerSampleDocument')
    133133        document.title = u'My Document'
     134        document.document_id = u'DOC1'
    134135        customer['documents'].addDocument(document)
    135136        IWorkflowState(document).setState(VERIFIED)
     
    151152        super(CustomerProcessorTest, self).setUp()
    152153
    153         # Add customer with subobjects
     154        # Add customer
    154155        customer = Customer()
    155156        self.app['customers'].addCustomer(customer)
     
    305306            dict(customer_id='ID_NONE', document_id='nonsense'), self.app) is None
    306307        assert self.processor.getEntry(
    307             dict(customer_id=self.customer.customer_id, document_id='d101'),
    308             self.app) is self.customer['documents']['d101']
     308            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
     309            self.app) is self.customer['documents']['DOC1']
    309310
    310311    def test_delEntry(self):
    311312        assert self.processor.getEntry(
    312             dict(customer_id=self.customer.customer_id, document_id='d101'),
    313             self.app) is self.customer['documents']['d101']
     313            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
     314            self.app) is self.customer['documents']['DOC1']
    314315        self.assertEqual(len(self.customer['documents'].keys()),1)
    315316        self.processor.delEntry(
    316             dict(customer_id=self.customer.customer_id, document_id='d101'),
     317            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
    317318            self.app)
    318319        assert self.processor.getEntry(
    319             dict(customer_id=self.customer.customer_id, document_id='d101'),
     320            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
    320321            self.app) is None
    321322        self.assertEqual(len(self.customer['documents'].keys()),0)
    322323
    323324    def test_addEntry(self):
    324         self.assertEqual(self.app._curr_doc_id, 102)
    325325        self.assertEqual(len(self.customer['documents'].keys()),1)
    326326        document1 = createObject(u'waeup.CustomerSampleDocument')
    327         document1.document_id = 'd234'
     327        document1.document_id = u'd234'
    328328        self.processor.addEntry(
    329329            document1, dict(customer_id=self.customer.customer_id, document_id='d234'),
     
    331331        self.assertEqual(len(self.customer['documents'].keys()),2)
    332332        self.assertEqual(self.customer['documents']['d234'].document_id, 'd234')
    333         # _curr_doc_id hasn't changed
    334         self.assertEqual(self.app._curr_doc_id, 102)
    335333
    336334    def test_checkConversion(self):
    337         self.assertEqual(self.app._curr_doc_id, 102)
    338         errs, inv_errs, conv_dict = self.processor.checkConversion(
    339             dict(document_id='d126', class_name='CustomerSampleDocument'))
     335        errs, inv_errs, conv_dict = self.processor.checkConversion(
     336            dict(document_id='DOC', class_name='CustomerSampleDocument'))
    340337        self.assertEqual(len(errs),0)
    341         errs, inv_errs, conv_dict = self.processor.checkConversion(
    342             dict(document_id='nonsense', class_name='CustomerSampleDocument'))
     338        #errs, inv_errs, conv_dict = self.processor.checkConversion(
     339        #    dict(document_id='id with spaces', class_name='CustomerSampleDocument'))
     340        #self.assertEqual(len(errs),1)
     341        errs, inv_errs, conv_dict = self.processor.checkConversion(
     342            dict(document_id='DOC', class_name='WrongDocument'))
    343343        self.assertEqual(len(errs),1)
    344         errs, inv_errs, conv_dict = self.processor.checkConversion(
    345             dict(document_id='d127', class_name='WrongDocument'))
    346         self.assertEqual(len(errs),1)
    347         errs, inv_errs, conv_dict = self.processor.checkConversion(
    348             dict(document_id='', class_name='CustomerSampleDocument',
    349             mode='update'))
    350         self.assertEqual(len(errs),1)
    351         # _curr_doc_id hasn't changed
    352         self.assertEqual(self.app._curr_doc_id, 102)
    353344
    354345    def test_import(self):
    355346        num, num_warns, fin_file, fail_file = self.processor.doImport(
    356347            self.csv_file, DOCUMENT_HEADER_FIELDS,'create')
     348        fail_file = open(fail_file).read()
    357349        self.assertEqual(num_warns,1)
    358350        # document_id must be unique
    359         fail_file = open(fail_file).read()
    360351        self.assertEqual(fail_file,
    361352            'class_name,reg_number,document_id,title,--ERRORS--\r\n'
    362             'CustomerSampleDocument,2,d5,My stolen doc,document_id: id exists\r\n')
     353            'CustomerSampleDocument,2,d5,My stolen doc,'
     354            'This object already exists. Skipping.\r\n')
    363355        document = self.processor.getEntry(dict(reg_number='1',
    364356            document_id='d3'), self.app)
     
    371363        shutil.rmtree(os.path.dirname(fin_file))
    372364        logcontent = open(self.logfile).read()
    373         # Logging message from updateEntry
     365        # Fetch uuid
     366        docid = [i for i in self.app['customers']['X666666']['documents'].keys()
     367            if len(i) > 10][0]
     368         # Logging message from updateEntry
    374369        self.assertTrue(
    375370            'INFO - system - CustomerDocument Processor - '
    376             'sample_document_data - X666666 - updated: '
    377             'document_id=d3, title=My first doc'
    378             in logcontent)
     371            'sample_document_data - X666666 - %s - updated: title=My 4th doc'
     372            % docid in logcontent)
    379373
    380374    def test_import_update(self):
     
    387381        num, num_warns, fin_file, fail_file = self.processor.doImport(
    388382            self.csv_file, DOCUMENT_HEADER_FIELDS,'update')
    389         # There is one record without document_id and one duplicate
    390         self.assertEqual(num_warns,2)
     383        # There is one record without document_id
     384        self.assertEqual(num_warns,1)
    391385        shutil.rmtree(os.path.dirname(fin_file))
    392386
     
    475469        errs, inv_errs, conv_dict = self.processor.checkConversion(
    476470            dict(contract_id='c126', class_name='SampleContract',
    477                  document_object='d101', product_object='SAM'))
     471                 document_object='DOC1', product_object='SAM'))
    478472        self.assertEqual(len(errs),0)
    479473        errs, inv_errs, conv_dict = self.processor.checkConversion(
     
    495489            'reg_number,contract_id,title,class_name,product_object,'
    496490            'document_object,--ERRORS--\r\n'
    497             '2,c5,My stolen contract,SampleContract,SAM,d101,'
     491            '2,c5,My stolen contract,SampleContract,SAM,DOC1,'
    498492            'contract_id: id exists\r\n'
    499493            '3,c6,My 5th contract,SampleContract,SAM,NONEXISTENT,'
    500494            'document_object: Invalid value\r\n'
    501             '3,c7,My sixt contract,SampleContract,NONEXISTENT,d101,'
     495            '3,c7,My sixt contract,SampleContract,NONEXISTENT,DOC1,'
    502496            'product_object: Invalid value\r\n')
    503497        contract = self.processor.getEntry(dict(reg_number='1',
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12246 r12256  
    120120        self.document = createObject('waeup.CustomerSampleDocument')
    121121        self.document.title = u'My first document'
     122        self.document.document_id = u'DOC1'
    122123        self.customer['documents'].addDocument(self.document)
    123124        self.contract = createObject('waeup.SampleContract')
     
    834835        self.browser.getControl("Add document").click()
    835836        self.assertTrue('PDF Document added.' in self.browser.contents)
    836         document = self.customer['documents']['d102']
     837        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     838        document = self.customer['documents'][docid]
    837839
    838840        # Document can be edited
    839         self.browser.getLink("d102").click()
     841        self.browser.getLink(docid).click()
    840842        self.browser.getLink("Manage").click()
    841843        self.browser.getControl(name="form.title").value = 'My second doc'
     
    843845        self.assertTrue('Form has been saved.' in self.browser.contents)
    844846        self.browser.getLink("View").click()
    845         self.assertEqual(self.browser.url, self.documents_path + '/d102/index')
     847        self.assertEqual(self.browser.url,
     848            self.documents_path + '/' + docid + '/index')
    846849
    847850        # Transitions can be performed
     
    859862
    860863        # Manage button and form is no longer available
    861         self.browser.open(self.documents_path + '/d102/index')
     864        self.browser.open(self.documents_path + '/' + docid + '/index')
    862865        self.assertFalse(
    863             'href="http://localhost/app/customers/K1000000/documents/d102/manage"'
    864             in self.browser.contents)
    865         self.browser.open(self.documents_path + '/d102/manage')
     866            'href="http://localhost/app/customers/K1000000/documents/%s/manage"'
     867            % docid in self.browser.contents)
     868        self.browser.open(self.documents_path + '/' + docid + '/manage')
    866869        self.assertTrue(
    867870            'The requested form is locked (read-only)'
     
    881884
    882885        self.assertTrue(
    883             'INFO - system - K1000000 - d101 - Document created'
     886            'INFO - system - K1000000 - DOC1 - Document created'
    884887            in logcontent)
    885888        self.assertTrue(
     
    889892        self.assertTrue(
    890893            'INFO - zope.mgr - customers.browser.DocumentManageFormPage '
    891             '- K1000000 - d102 - saved: title'
     894            '- K1000000 - %s - saved: title' % docid
    892895            in logcontent)
    893896        self.assertTrue(
    894             'INFO - zope.mgr - K1000000 - d102 - Submitted for verification'
    895             in logcontent)
     897            'INFO - zope.mgr - K1000000 - %s - Submitted for verification'
     898            % docid in logcontent)
    896899        self.assertTrue(
    897900            'INFO - zope.mgr - customers.browser.DocumentsManageFormPage '
    898             '- K1000000 - removed: d102'
     901            '- K1000000 - removed: %s' % docid
    899902            in logcontent)
    900903
     
    913916        self.browser.getControl("Add document").click()
    914917        self.assertTrue('Sample Document added.' in self.browser.contents)
    915         document = self.customer['documents']['d102']
     918        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     919        document = self.customer['documents'][docid]
    916920
    917921        # Document can be edited ...
    918         self.browser.getLink("d102").click()
    919         self.browser.open(self.documents_path + '/d102/edit')
     922        self.browser.getLink(docid).click()
     923        self.browser.open(self.documents_path + '/' + docid + '/edit')
    920924        #self.browser.getLink("Edit").click()
    921925        self.assertTrue('The requested form is locked' in self.browser.contents)
    922926        # Customer is in wrong state
    923927        IWorkflowState(self.customer).setState(APPROVED)
    924         self.browser.open(self.documents_path + '/d102/edit')
     928        self.browser.open(self.documents_path + '/' + docid + '/edit')
    925929        self.browser.getControl(name="form.title").value = 'My second doc'
    926930        self.browser.getControl("Save").click()
     
    928932        self.assertTrue('Form has been saved.' in self.browser.contents)
    929933        self.browser.getLink("View").click()
    930         self.assertEqual(self.browser.url, self.documents_path + '/d102/index')
     934        self.assertEqual(
     935            self.browser.url, self.documents_path + '/%s/index' % docid)
    931936        # Costumer can upload a document.
    932937        self.browser.getLink("Edit").click()
     
    938943            name='upload_samplescaneditupload').click()
    939944        self.assertTrue(
    940             'href="http://localhost/app/customers/K1000000/documents/d102/sample"'
    941             in self.browser.contents)
     945            'href="http://localhost/app/customers/K1000000/documents/%s/sample"'
     946            % docid in self.browser.contents)
    942947        # Costumer can submit the form. The form is also saved.
    943948        self.browser.getControl(name="form.title").value = 'My third doc'
     
    947952        self.assertTrue('Document State: submitted for verification' in self.browser.contents)
    948953        # Customer can't edit the document once it has been submitted
    949         self.browser.open(self.documents_path + '/d102/edit')
     954        self.browser.open(self.documents_path + '/%s/edit' % docid)
    950955        self.assertTrue('The requested form is locked' in self.browser.contents)
    951956
     
    954959        # The image is stored even if form has errors
    955960        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    956         self.browser.open(self.customer_path + '/documents/d101/manage')
     961        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    957962        # Create a pseudo image file and select it to be uploaded
    958963        image = open(SAMPLE_IMAGE, 'rb')
     
    963968        self.browser.getControl("Save").click() # submit form
    964969        self.assertFalse(
    965             'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
     970            'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"'
    966971            in self.browser.contents)
    967972        # ... but the correct upload submit button does
     
    973978            name='upload_samplescanmanageupload').click()
    974979        self.assertTrue(
    975             'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
     980            'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"'
    976981            in self.browser.contents)
    977982        # Browsing the link shows a real image
     
    981986        self.assertEqual(len(self.browser.contents), 2787)
    982987        # We can't reupload a file. The existing file must be deleted first.
    983         self.browser.open(self.customer_path + '/documents/d101/manage')
     988        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    984989        self.assertFalse(
    985990            'upload_samplescanmanageupload' in self.browser.contents)
     
    10241029    def test_verify_document(self):
    10251030        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1026         self.browser.open(self.customer_path + '/documents/d101/manage')
     1031        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    10271032        image = open(SAMPLE_IMAGE, 'rb')
    10281033        ctrl = self.browser.getControl(name='samplescanmanageupload')
     
    10351040        self.assertEqual(
    10361041            getattr(self.document, 'sample_md5', None), None)
    1037         self.browser.open(self.documents_path + '/d101/trigtrans')
     1042        self.browser.open(self.documents_path + '/DOC1/trigtrans')
    10381043        self.browser.getControl(name="transition").value = ['verify']
    10391044        self.browser.getControl("Apply now").click()
     
    10511056        self.browser.getControl(name="form.title").value = 'My PDF Document'
    10521057        self.browser.getControl("Add document").click()
    1053         self.browser.open(self.documents_path + '/d102/manage')
     1058        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     1059        self.browser.open(self.documents_path + '/%s/manage' % docid)
    10541060        # Create a pseudo image file and select it to be uploaded
    10551061        image = open(SAMPLE_IMAGE, 'rb')
     
    10751081            name='upload_pdfscanmanageupload').click()
    10761082        self.assertTrue(
    1077             'href="http://localhost/app/customers/K1000000/documents/d102/sample.pdf">PDF File</a>'
    1078             in self.browser.contents)
     1083            'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">PDF File</a>'
     1084            % docid in self.browser.contents)
    10791085        # Browsing the link shows a real pdf
    10801086        self.browser.open('sample.pdf')
     
    10981104        jpegfile = open(SAMPLE_IMAGE, 'rb')
    10991105        fs.createFile(file_id, jpegfile)
    1100         self.browser.open(self.customer_path + '/documents/d101')
     1106        self.browser.open(self.customer_path + '/documents/DOC1')
    11011107        self.browser.getLink("Download document slip").click()
    11021108        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     
    11141120        pdffile = open(SAMPLE_PDF, 'rb')
    11151121        fs.createFile(file_id, pdffile)
    1116         self.browser.open(self.customer_path + '/documents/d102')
     1122        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     1123        self.browser.open(self.customer_path + '/documents/' + docid)
    11171124        self.browser.getLink("Download document slip").click()
    11181125        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     
    11291136        fs.createFile(file_id, StringIO('my sample 1'))
    11301137        result = fs.getFileByContext(self.document, attr='sample')
    1131         self.assertEqual(file_id, '__file-customerdocument__01000/K1000000/sample_d101_K1000000')
     1138        self.assertEqual(file_id, '__file-customerdocument__01000/K1000000/sample_DOC1_K1000000')
    11321139        self.assertEqual(result.read(), 'my sample 1')
    11331140        self.assertEqual(self.document.connected_files[0][1].read(), 'my sample 1')
     
    12531260        self.browser.open(self.contracts_path + '/c102/edit')
    12541261        self.browser.getControl(name="form.product_object").value = ['SAM']
    1255         self.browser.getControl(name="form.document_object").value = ['d101']
     1262        self.browser.getControl(name="form.document_object").value = ['DOC1']
    12561263        self.browser.getControl(name="form.title").value = 'My second contract'
    12571264        self.browser.getControl("Save").click()
     
    12731280            in self.browser.contents)
    12741281        self.assertTrue(
    1275             '<a href="http://localhost/app/customers/K1000000/documents/d101">d101 -'
     1282            '<a href="http://localhost/app/customers/K1000000/documents/DOC1">DOC1 -'
    12761283            in self.browser.contents)
    12771284        # Customer can submit the form. The form is also saved.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_catalog.py

    r12195 r12256  
    213213        logcontent = open(logfile).read()
    214214        self.assertTrue(
    215             'INFO - system - ObjectRemovedEvent - K1000000 - c101 - removed: d101\n'
    216             in logcontent)
    217 
     215            'INFO - system - ObjectRemovedEvent - K1000000 - c101 - removed: %s\n'
     216            % self.document_id in logcontent)
     217
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py

    r12205 r12256  
    156156        # we can't get an image filename for documents not owned by a customer
    157157        doc = CustomerSampleDocument()
     158        doc.document_id = u'DOC1'
    158159        chooser = IFileStoreNameChooser(doc)
    159160        # no customer can be found
     
    168169        result = chooser.chooseName('sample.jpg')
    169170        self.assertEqual(
    170             result, '__file-customerdocument__01000/K1000001/sample_d123_K1000001.jpg')
     171            result, '__file-customerdocument__01000/K1000001/sample_DOC1_K1000001.jpg')
    171172        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r12221 r12256  
    156156        # we can export a nearly empty document
    157157        document = CustomerSampleDocument()
     158        document.document_id = u'DOC1'
    158159        exporter = CustomerDocumentExporter()
    159160        exporter.export([document], self.outfile)
     
    162163            result,
    163164            'class_name,document_id,history,state,title,user_id\r\n'
    164             'CustomerSampleDocument,d101,[],,,\r\n'
     165            'CustomerSampleDocument,DOC1,[],,,\r\n'
    165166            )
    166167        return
     
    170171        # set values we can expect in export file
    171172        self.setup_customer(self.customer)
    172         document = self.customer['documents']['d101']
     173        document = self.customer['documents']['DOC1']
    173174        exporter = CustomerDocumentExporter()
    174175        exporter.export([document], self.outfile)
     
    179180            )
    180181        self.assertMatches(
    181             '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     182            '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - '
    182183            'Document created by system\'],'
    183184            'verified,My Document,A111111...',
     
    197198            in result)
    198199        self.assertMatches(
    199             '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     200            '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - '
    200201            'Document created by system\'],'
    201202            'verified,My Document,A111111...',
     
    215216            in result)
    216217        self.assertMatches(
    217             '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     218            '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - '
    218219            'Document created by system\'],'
    219220            'verified,My Document,A111111...',
     
    273274            'product_object,state,title\r\n'
    274275
    275             'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     276            'SampleContract,sample,c101,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    276277            'Contract created by system\'],,'
    277278            'SAM,created,My Contract\r\n',
     
    292293            'product_object,state,title\r\n'
    293294
    294             'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     295            'SampleContract,sample,c101,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    295296            'Contract created by system\'],,'
    296297            'SAM,created,My Contract\r\n',
     
    311312            'product_object,state,title\r\n'
    312313
    313             'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     314            'SampleContract,sample,c101,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    314315            'Contract created by system\'],,'
    315316            'SAM,created,My Contract\r\n',
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_interfaces.py

    r12102 r12256  
    7777        document = createObject('waeup.CustomerSampleDocument')
    7878        document.title = u'My Samle Document'
     79        document.document_id = u'DOC1'
    7980        self.customer['documents'].addDocument(document)
    8081        self.document_id = document.document_id
     
    107108        source = CustomerDocumentSource()
    108109        result = source.factory.getTitle(object(), self.document)
    109         self.assertEqual(result, u'd101 - My Samle Document')
     110        self.assertEqual(result, u'DOC1 - My Samle Document')
    110111
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/batching.py

    r12250 r12256  
    5656    factory_name = 'waeup.PDFDocument'
    5757
    58     location_fields = []
    5958    additional_fields = ['class_name']
    6059    additional_headers = ['class_name']
     
    6665
    6766    def entryExists(self, row, site):
    68         return row['document_id'] in site['documents'].keys()
     67        document_id = row.get('document_id', None)
     68        cat = queryUtility(ICatalog, name='documents_catalog')
     69        results = list(cat.searchResults(document_id=(document_id, document_id)))
     70        if results:
     71            return True
     72        return False
    6973
    7074    def getParent(self, row, site):
     
    9498        """Update obj to the values given in row.
    9599        """
    96         items_changed = super(DocumentProcessor, self).updateEntry(
     100        items_changed = super(PDFDocumentProcessor, self).updateEntry(
    97101            obj, row, site, filename)
    98102        # Log actions...
     
    110114        # We need to check if the class_name corresponds with the
    111115        # processor chosen. This is to avoid accidentally wrong imports.
    112         if mode != 'remove':
     116        if mode == 'create':
    113117            class_name = row.get('class_name', None)
    114118            if class_name != self.factory_name.strip('waeup.'):
    115119                errs.append(('class_name','wrong processor'))
    116         # We have to check document_id.
    117120        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'))
     121        if ' ' in document_id:
     122            errs.append(('document_id','must not contain spaces'))
    132123        return errs, inv_errs, conv_dict
    133124
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12235 r12256  
    3939    IDocument, IPublicDocument, IDocumentsUtils,
    4040    IPDFDocument, IHTMLDocument)
    41 from waeup.ikoba.documents.utils import generate_document_id
    4241
    4342class Document(grok.Container):
     
    5857    translated_state = None
    5958    translated_class_name = None
    60 
    61     def __init__(self):
    62         super(Document, self).__init__()
    63         # The site doesn't exist in unit tests
    64         try:
    65             self.document_id = generate_document_id()
    66         except AttributeError:
    67             self.document_id = u'd123'
    68         return
    6959
    7060    @property
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12239 r12256  
    3838
    3939    """
    40     document_id = Attribute('Document Identifier')
    4140    history = Attribute('Object history, a list of messages')
    4241    state = Attribute('Returns the verification state of a document')
     
    4948    connected_files = Attribute('Names of files connected to a document')
    5049    is_verifiable = Attribute('Contract verifiable by officer')
     50
     51    document_id = schema.TextLine(
     52        title = _(u'Document Id'),
     53        required = False,
     54        )
    5155
    5256    title = schema.TextLine(
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py

    r12246 r12256  
    111111        self.browser.getControl(name="doctype").value = ['PDFDocument']
    112112        self.browser.getControl(name="form.title").value = 'My PDF Document'
     113        self.browser.getControl(name="form.document_id").value = 'DOC1'
    113114        self.browser.getControl("Add document").click()
    114115        self.assertTrue('PDF Document added.' in self.browser.contents)
    115         document = self.app['documents']['d101']
     116        document = self.app['documents']['DOC1']
    116117
    117118        # Document can be edited
    118         self.browser.getLink("d101").click()
     119        self.browser.getLink("DOC1").click()
    119120        self.browser.getLink("Manage").click()
    120121        self.browser.getControl(name="form.title").value = 'My first doc'
     
    122123        self.assertTrue('Form has been saved.' in self.browser.contents)
    123124        self.browser.getLink("View").click()
    124         self.assertEqual(self.browser.url, self.container_path + '/d101/index')
     125        self.assertEqual(self.browser.url, self.container_path + '/DOC1/index')
    125126
    126127        # File can be uploaded
     
    149150            name='upload_pdfscanmanageupload').click()
    150151        self.assertTrue(
    151             'href="http://localhost/app/documents/d101/sample.pdf">PDF File</a>'
     152            'href="http://localhost/app/documents/DOC1/sample.pdf">PDF File</a>'
    152153            in self.browser.contents)
    153154        # Browsing the link shows a real pdf only if the document
     
    158159            in self.browser.contents)
    159160        IWorkflowState(document).setState(PUBLISHED)
    160         self.browser.open(self.container_path + '/d101/sample.pdf')
     161        self.browser.open(self.container_path + '/DOC1/sample.pdf')
    161162        self.assertEqual(
    162163            self.browser.headers['content-type'], 'application/pdf')
     
    164165        # Transitions can be performed
    165166        self.assertEqual(document.state, 'published')
    166         self.browser.open(self.container_path + '/d101')
     167        self.browser.open(self.container_path + '/DOC1')
    167168        self.browser.getLink("Transition").click()
    168169        self.browser.getControl(name="transition").value = ['retract']
     
    213214        self.browser.getControl("Add document").click()
    214215        self.browser.getControl(name="doctype").value = ['HTMLDocument']
     216        self.browser.getControl(name="form.document_id").value = 'DOC2'
    215217        self.browser.getControl(name="form.title").value = 'My HTML Document'
    216218        self.browser.getControl("Add document").click()
    217219        self.assertTrue('HTML Document added.' in self.browser.contents)
    218         document = self.app['documents']['d101']
     220        document = self.app['documents']['DOC2']
    219221
    220222        # Document can be edited
    221         self.browser.getLink("d101").click()
     223        self.browser.getLink("DOC2").click()
    222224        self.browser.getLink("Manage").click()
    223225        self.browser.getControl(name="form.title").value = 'My second doc'
     
    230232        self.assertTrue('Form has been saved.' in self.browser.contents)
    231233        self.browser.getLink("View").click()
    232         self.assertEqual(self.browser.url, self.container_path + '/d101/index')
     234        self.assertEqual(self.browser.url, self.container_path + '/DOC2/index')
    233235        self.assertTrue(
    234236            '<h1>Hello World</h1>' in self.browser.contents)
     
    241243            '<h1>Hallo Welt</h1>' in self.browser.contents)
    242244        # The content can't be rendered yet
    243         self.browser.open(self.container_path + '/d101/display')
     245        self.browser.open(self.container_path + '/DOC2/display')
    244246        self.assertTrue(
    245247            'The document requested has not yet been published'
     
    249251
    250252        # Transitions can be performed
    251         self.browser.open(self.container_path + '/d101')
     253        self.browser.open(self.container_path + '/DOC2')
    252254        self.browser.getLink("Transition").click()
    253255        self.browser.getControl(name="transition").value = ['publish']
     
    256258
    257259        # The content can be rendered
    258         self.browser.open(self.container_path + '/d101/display')
     260        self.browser.open(self.container_path + '/DOC2/display')
    259261        self.assertTrue(
    260262            '<h1>Hallo Welt</h1>' in self.browser.contents)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_document.py

    r12213 r12256  
    7272        container = DocumentsContainer()
    7373        document = createObject(u'waeup.HTMLDocument')
    74         document_id = document.document_id
     74        document.document_id = u'DOC'
    7575        container.addDocument(document)
    76         self.assertEqual(container[document_id], document)
     76        self.assertEqual(container[document.document_id], document)
    7777        self.assertRaises(TypeError, container.addDocument, object())
    78         self.assertEqual(document_id, 'd123')
     78        self.assertEqual(document.document_id, 'DOC')
    7979        return
    8080
     
    151151        # we can get an image filename for documents not in a container
    152152        doc = PDFDocument()
     153        doc.document_id = u'DOC'
    153154        chooser = IFileStoreNameChooser(doc)
    154155        result = chooser.chooseName('sample.jpg')
    155156        # the file would be stored in a ``_default`` directory.
    156157        self.assertEqual(
    157             result, '__file-document__documents/sample_d123.jpg')
     158            result, '__file-document__documents/sample_DOC.jpg')
    158159        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py

    r12214 r12256  
    2626
    2727
    28 def generate_document_id():
    29     new_id = grok.getSite().unique_document_id
    30     return new_id
    31 
    32 
    3328class DocumentsUtils(grok.GlobalUtility):
    3429    """A collection of methods subject to customization.
Note: See TracChangeset for help on using the changeset viewer.