Changeset 12161 for main/waeup.ikoba/trunk/src/waeup
- Timestamp:
- 7 Dec 2014, 10:07:29 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py
r12128 r12161 21 21 import os 22 22 import grok 23 from hashlib import md5 23 24 from zope.component import queryUtility, getUtility 24 25 from zope.component.interfaces import IFactory … … 66 67 grok.baseclass() 67 68 69 filenames = () 70 68 71 @property 69 72 def customer(self): … … 105 108 return 106 109 110 @property 111 def connected_files(self): 112 store = getUtility(IExtFileStore) 113 files = [] 114 try: 115 for filename in self.filenames: 116 attrname = filename.replace('.','_') 117 file = store.getFileByContext(self, attr=filename) 118 files.append((attrname, file)) 119 except AttributeError: 120 # In unit tests we don't have a customer to 121 # determine the file path. 122 return 123 return files 124 125 def setMD5(self): 126 """Set md5 checksum attribute for all files connected to this document. 127 """ 128 for file in self.connected_files: 129 attrname = '%s_md5' % file[0] 130 checksum = md5(file[1].read()).hexdigest() 131 setattr(self, attrname, checksum) 132 return 133 107 134 108 135 class CustomerSampleDocument(CustomerDocumentBase): 109 136 """This is a sample customer document. 110 137 """ 138 139 filenames = ('sample',) 111 140 112 141 CustomerSampleDocument = attrs_to_fields(CustomerSampleDocument) -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py
r12156 r12161 160 160 'translated_state', 161 161 'formatted_transition_date', 162 'translated_class_name']))) 162 'translated_class_name', 163 'connected_files', # Could be used to export file URLs 164 ]))) 163 165 164 166 #: The title under which this exporter will be displayed -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
r12151 r12161 43 43 from waeup.ikoba.customers.customer import Customer 44 44 from waeup.ikoba.interfaces import ( 45 IUserAccount, IJobManager, APPROVED, SUBMITTED) 45 IUserAccount, IJobManager, APPROVED, SUBMITTED, 46 IFileStoreNameChooser, IExtFileStore, IFileStoreHandler) 47 from waeup.ikoba.imagestorage import ( 48 FileStoreNameChooser, ExtFileStore, DefaultFileStoreHandler, 49 DefaultStorage) 46 50 from waeup.ikoba.authentication import LocalRoleSetEvent 47 51 from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase … … 1212 1216 1213 1217 def test_contract_approval(self): 1214 # This is not a UI test. It just tests the approval 1215 # of contracts. 1218 # This is not a UI test. It just a functional test. 1216 1219 self.assertRaises(ConstraintNotSatisfied, 1217 1220 self.contract.document_object, self.document) … … 1227 1230 self.assertEqual(IWorkflowState(self.contract).getState(), 'approved') 1228 1231 1229 1230 1232 def test_contract_approval_in_UI(self): 1231 1233 # Now let's see what the UI says why trying to approve a contract … … 1246 1248 self.browser.getControl("Save").click() 1247 1249 self.assertEqual(IWorkflowState(self.contract).getState(), 'approved') 1250 1251 def test_get_setmd5_file(self): 1252 # A proper file name chooser is registered for customer documents. 1253 # This is not a UI test. It just a functional test. 1254 file_id = IFileStoreNameChooser(self.document).chooseName(attr='sample') 1255 fs = ExtFileStore(root=self.dc_root) 1256 fs.createFile(file_id, StringIO('my sample 1')) 1257 result = fs.getFileByContext(self.document, attr='sample') 1258 self.assertEqual(file_id, '__file-customerdocument__01000/K1000000/sample_d101_K1000000') 1259 self.assertEqual(result.read(), 'my sample 1') 1260 self.assertEqual(self.document.connected_files[0][1].read(), 'my sample 1') 1261 self.document.setMD5() 1262 self.assertEqual(self.document.sample_md5, 'a406995ee8eb6772bacf51aa4b0caa24') 1263 return 1264 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py
r12160 r12161 87 87 return 88 88 89 def setMD5(self, files): 90 """Set md5 checksum of selected files connected to this document. 89 def setMD5(self): 90 """Determine md5 checksum of all files and store checksums as 91 document attributes. 91 92 """ 92 93 return 93 94 95 Document = attrs_to_fields(Document) 94 96 95 Document = attrs_to_fields(Document)96 97 97 98 class DocumentFactory(grok.GlobalUtility): -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12160 r12161 52 52 formatted_transition_date = Attribute('Last transition formatted date string') 53 53 user_id = Attribute('Id of a user') 54 connected_files = Attribute(' Getfiles connected to a document')54 connected_files = Attribute('Names of files connected to a document') 55 55 56 56 title = schema.TextLine( … … 65 65 ) 66 66 67 def setMD5(files): 68 """Set md5 checksum of selected files connected to this document. 67 def setMD5(): 68 """Determine md5 checksum of selected files and store checksums as 69 document attributes. 69 70 """ 70 71
Note: See TracChangeset for help on using the changeset viewer.