Changeset 12256 for main/waeup.ikoba/trunk/src/waeup/ikoba/documents
- Timestamp:
- 18 Dec 2014, 12:58:12 (10 years ago)
- 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 56 56 factory_name = 'waeup.PDFDocument' 57 57 58 location_fields = []59 58 additional_fields = ['class_name'] 60 59 additional_headers = ['class_name'] … … 66 65 67 66 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 69 73 70 74 def getParent(self, row, site): … … 94 98 """Update obj to the values given in row. 95 99 """ 96 items_changed = super( DocumentProcessor, self).updateEntry(100 items_changed = super(PDFDocumentProcessor, self).updateEntry( 97 101 obj, row, site, filename) 98 102 # Log actions... … … 110 114 # We need to check if the class_name corresponds with the 111 115 # processor chosen. This is to avoid accidentally wrong imports. 112 if mode != 'remove':116 if mode == 'create': 113 117 class_name = row.get('class_name', None) 114 118 if class_name != self.factory_name.strip('waeup.'): 115 119 errs.append(('class_name','wrong processor')) 116 # We have to check document_id.117 120 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')) 132 123 return errs, inv_errs, conv_dict 133 124 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py
r12235 r12256 39 39 IDocument, IPublicDocument, IDocumentsUtils, 40 40 IPDFDocument, IHTMLDocument) 41 from waeup.ikoba.documents.utils import generate_document_id42 41 43 42 class Document(grok.Container): … … 58 57 translated_state = None 59 58 translated_class_name = None 60 61 def __init__(self):62 super(Document, self).__init__()63 # The site doesn't exist in unit tests64 try:65 self.document_id = generate_document_id()66 except AttributeError:67 self.document_id = u'd123'68 return69 59 70 60 @property -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12239 r12256 38 38 39 39 """ 40 document_id = Attribute('Document Identifier')41 40 history = Attribute('Object history, a list of messages') 42 41 state = Attribute('Returns the verification state of a document') … … 49 48 connected_files = Attribute('Names of files connected to a document') 50 49 is_verifiable = Attribute('Contract verifiable by officer') 50 51 document_id = schema.TextLine( 52 title = _(u'Document Id'), 53 required = False, 54 ) 51 55 52 56 title = schema.TextLine( -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py
r12246 r12256 111 111 self.browser.getControl(name="doctype").value = ['PDFDocument'] 112 112 self.browser.getControl(name="form.title").value = 'My PDF Document' 113 self.browser.getControl(name="form.document_id").value = 'DOC1' 113 114 self.browser.getControl("Add document").click() 114 115 self.assertTrue('PDF Document added.' in self.browser.contents) 115 document = self.app['documents'][' d101']116 document = self.app['documents']['DOC1'] 116 117 117 118 # Document can be edited 118 self.browser.getLink(" d101").click()119 self.browser.getLink("DOC1").click() 119 120 self.browser.getLink("Manage").click() 120 121 self.browser.getControl(name="form.title").value = 'My first doc' … … 122 123 self.assertTrue('Form has been saved.' in self.browser.contents) 123 124 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') 125 126 126 127 # File can be uploaded … … 149 150 name='upload_pdfscanmanageupload').click() 150 151 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>' 152 153 in self.browser.contents) 153 154 # Browsing the link shows a real pdf only if the document … … 158 159 in self.browser.contents) 159 160 IWorkflowState(document).setState(PUBLISHED) 160 self.browser.open(self.container_path + '/ d101/sample.pdf')161 self.browser.open(self.container_path + '/DOC1/sample.pdf') 161 162 self.assertEqual( 162 163 self.browser.headers['content-type'], 'application/pdf') … … 164 165 # Transitions can be performed 165 166 self.assertEqual(document.state, 'published') 166 self.browser.open(self.container_path + '/ d101')167 self.browser.open(self.container_path + '/DOC1') 167 168 self.browser.getLink("Transition").click() 168 169 self.browser.getControl(name="transition").value = ['retract'] … … 213 214 self.browser.getControl("Add document").click() 214 215 self.browser.getControl(name="doctype").value = ['HTMLDocument'] 216 self.browser.getControl(name="form.document_id").value = 'DOC2' 215 217 self.browser.getControl(name="form.title").value = 'My HTML Document' 216 218 self.browser.getControl("Add document").click() 217 219 self.assertTrue('HTML Document added.' in self.browser.contents) 218 document = self.app['documents'][' d101']220 document = self.app['documents']['DOC2'] 219 221 220 222 # Document can be edited 221 self.browser.getLink(" d101").click()223 self.browser.getLink("DOC2").click() 222 224 self.browser.getLink("Manage").click() 223 225 self.browser.getControl(name="form.title").value = 'My second doc' … … 230 232 self.assertTrue('Form has been saved.' in self.browser.contents) 231 233 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') 233 235 self.assertTrue( 234 236 '<h1>Hello World</h1>' in self.browser.contents) … … 241 243 '<h1>Hallo Welt</h1>' in self.browser.contents) 242 244 # 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') 244 246 self.assertTrue( 245 247 'The document requested has not yet been published' … … 249 251 250 252 # Transitions can be performed 251 self.browser.open(self.container_path + '/ d101')253 self.browser.open(self.container_path + '/DOC2') 252 254 self.browser.getLink("Transition").click() 253 255 self.browser.getControl(name="transition").value = ['publish'] … … 256 258 257 259 # The content can be rendered 258 self.browser.open(self.container_path + '/ d101/display')260 self.browser.open(self.container_path + '/DOC2/display') 259 261 self.assertTrue( 260 262 '<h1>Hallo Welt</h1>' in self.browser.contents) -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_document.py
r12213 r12256 72 72 container = DocumentsContainer() 73 73 document = createObject(u'waeup.HTMLDocument') 74 document _id = document.document_id74 document.document_id = u'DOC' 75 75 container.addDocument(document) 76 self.assertEqual(container[document _id], document)76 self.assertEqual(container[document.document_id], document) 77 77 self.assertRaises(TypeError, container.addDocument, object()) 78 self.assertEqual(document _id, 'd123')78 self.assertEqual(document.document_id, 'DOC') 79 79 return 80 80 … … 151 151 # we can get an image filename for documents not in a container 152 152 doc = PDFDocument() 153 doc.document_id = u'DOC' 153 154 chooser = IFileStoreNameChooser(doc) 154 155 result = chooser.chooseName('sample.jpg') 155 156 # the file would be stored in a ``_default`` directory. 156 157 self.assertEqual( 157 result, '__file-document__documents/sample_ d123.jpg')158 result, '__file-document__documents/sample_DOC.jpg') 158 159 return -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py
r12214 r12256 26 26 27 27 28 def generate_document_id():29 new_id = grok.getSite().unique_document_id30 return new_id31 32 33 28 class DocumentsUtils(grok.GlobalUtility): 34 29 """A collection of methods subject to customization.
Note: See TracChangeset for help on using the changeset viewer.