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/documents
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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.