Changeset 12256
- Timestamp:
- 18 Dec 2014, 12:58:12 (10 years ago)
- 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 42 42 grok.implements(ICompany) 43 43 44 _curr_doc_id = 10145 46 44 _curr_con_id = 101 47 45 … … 56 54 self.setup() 57 55 return 58 59 @property60 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 be68 made easily by enabling commented lines.69 """70 # lock.acquire() # lock data71 new_id = u'd%s' % (self._curr_doc_id)72 self._curr_doc_id += 173 # self._p_changed = True74 # commit()75 # lock.release() # end of lock76 return new_id77 56 78 57 @property -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py
r12250 r12256 40 40 from waeup.ikoba.interfaces import IIkobaUtils 41 41 from waeup.ikoba.interfaces import MessageFactory as _ 42 from waeup.ikoba.documents.utils import generate_document_id43 42 from waeup.ikoba.customers.utils import generate_contract_id 44 43 from waeup.ikoba.customers.interfaces import ( … … 398 397 399 398 def getEntry(self, row, site): 400 documents = self.getParent(row, site)401 if documents is None:402 return None403 399 document_id = row.get('document_id', None) 404 400 if document_id is None: 405 401 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 408 416 409 417 def updateEntry(self, obj, row, site, filename): 410 418 """Update obj to the values given in row. 411 419 """ 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') 412 423 items_changed = super(CustomerDocumentProcessor, self).updateEntry( 413 424 obj, row, site, filename) 414 425 customer = self.getParent(row, site).__parent__ 415 426 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)) 418 430 return 419 431 420 432 def addEntry(self, obj, row, site): 421 433 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) 428 435 return 429 436 … … 449 456 if class_name != self.factory_name.strip('waeup.'): 450 457 errs.append(('class_name','wrong processor')) 451 try:452 # Correct doc_id counter. As the IConverter for documents453 # creates document objects that are not used afterwards, we454 # have to fix the site-wide doc_id counter.455 site = grok.getSite()456 site._curr_doc_id -= 1457 except (KeyError, TypeError, AttributeError):458 pass459 # 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_id465 return errs, inv_errs, conv_dict466 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'))475 458 return errs, inv_errs, conv_dict 476 459 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py
r12246 r12256 817 817 pnav = 4 818 818 819 form_fields = grok.AutoFields(ICustomerDocument) 819 form_fields = grok.AutoFields(ICustomerDocument).omit('document_id') 820 820 821 821 @property … … 876 876 @property 877 877 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') 879 880 880 881 def update(self): -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py
r12214 r12256 33 33 from waeup.ikoba.interfaces import ( 34 34 IFileStoreNameChooser, IFileStoreHandler, 35 IIkobaUtils, IExtFileStore )35 IIkobaUtils, IExtFileStore, IIDSource) 36 36 from waeup.ikoba.customers.interfaces import ( 37 37 ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument, … … 76 76 # tuple should contain only a single filename string. 77 77 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 78 84 79 85 @property -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/sample_contract_data.csv
r12131 r12256 1 1 class_name,contract_id,reg_number,title,product_object,document_object 2 SampleContract,c3,1,My first contract,SAM, d1013 SampleContract,c4,2,My second contract,SAM, d1014 SampleContract,c5,3,My third contract,SAM, d1015 SampleContract,,1,My 4th contract,SAM, d1016 SampleContract,c5,2,My stolen contract,SAM, d1012 SampleContract,c3,1,My first contract,SAM,DOC1 3 SampleContract,c4,2,My second contract,SAM,DOC1 4 SampleContract,c5,3,My third contract,SAM,DOC1 5 SampleContract,,1,My 4th contract,SAM,DOC1 6 SampleContract,c5,2,My stolen contract,SAM,DOC1 7 7 SampleContract,c6,3,My 5th contract,SAM,NONEXISTENT 8 SampleContract,c7,3,My sixt contract,NONEXISTENT, d1018 SampleContract,c7,3,My sixt contract,NONEXISTENT,DOC1 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py
r12250 r12256 132 132 document = createObject('waeup.CustomerSampleDocument') 133 133 document.title = u'My Document' 134 document.document_id = u'DOC1' 134 135 customer['documents'].addDocument(document) 135 136 IWorkflowState(document).setState(VERIFIED) … … 151 152 super(CustomerProcessorTest, self).setUp() 152 153 153 # Add customer with subobjects154 # Add customer 154 155 customer = Customer() 155 156 self.app['customers'].addCustomer(customer) … … 305 306 dict(customer_id='ID_NONE', document_id='nonsense'), self.app) is None 306 307 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'] 309 310 310 311 def test_delEntry(self): 311 312 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'] 314 315 self.assertEqual(len(self.customer['documents'].keys()),1) 315 316 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'), 317 318 self.app) 318 319 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'), 320 321 self.app) is None 321 322 self.assertEqual(len(self.customer['documents'].keys()),0) 322 323 323 324 def test_addEntry(self): 324 self.assertEqual(self.app._curr_doc_id, 102)325 325 self.assertEqual(len(self.customer['documents'].keys()),1) 326 326 document1 = createObject(u'waeup.CustomerSampleDocument') 327 document1.document_id = 'd234'327 document1.document_id = u'd234' 328 328 self.processor.addEntry( 329 329 document1, dict(customer_id=self.customer.customer_id, document_id='d234'), … … 331 331 self.assertEqual(len(self.customer['documents'].keys()),2) 332 332 self.assertEqual(self.customer['documents']['d234'].document_id, 'd234') 333 # _curr_doc_id hasn't changed334 self.assertEqual(self.app._curr_doc_id, 102)335 333 336 334 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')) 340 337 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')) 343 343 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 changed352 self.assertEqual(self.app._curr_doc_id, 102)353 344 354 345 def test_import(self): 355 346 num, num_warns, fin_file, fail_file = self.processor.doImport( 356 347 self.csv_file, DOCUMENT_HEADER_FIELDS,'create') 348 fail_file = open(fail_file).read() 357 349 self.assertEqual(num_warns,1) 358 350 # document_id must be unique 359 fail_file = open(fail_file).read()360 351 self.assertEqual(fail_file, 361 352 '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') 363 355 document = self.processor.getEntry(dict(reg_number='1', 364 356 document_id='d3'), self.app) … … 371 363 shutil.rmtree(os.path.dirname(fin_file)) 372 364 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 374 369 self.assertTrue( 375 370 '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) 379 373 380 374 def test_import_update(self): … … 387 381 num, num_warns, fin_file, fail_file = self.processor.doImport( 388 382 self.csv_file, DOCUMENT_HEADER_FIELDS,'update') 389 # There is one record without document_id and one duplicate390 self.assertEqual(num_warns, 2)383 # There is one record without document_id 384 self.assertEqual(num_warns,1) 391 385 shutil.rmtree(os.path.dirname(fin_file)) 392 386 … … 475 469 errs, inv_errs, conv_dict = self.processor.checkConversion( 476 470 dict(contract_id='c126', class_name='SampleContract', 477 document_object=' d101', product_object='SAM'))471 document_object='DOC1', product_object='SAM')) 478 472 self.assertEqual(len(errs),0) 479 473 errs, inv_errs, conv_dict = self.processor.checkConversion( … … 495 489 'reg_number,contract_id,title,class_name,product_object,' 496 490 'document_object,--ERRORS--\r\n' 497 '2,c5,My stolen contract,SampleContract,SAM, d101,'491 '2,c5,My stolen contract,SampleContract,SAM,DOC1,' 498 492 'contract_id: id exists\r\n' 499 493 '3,c6,My 5th contract,SampleContract,SAM,NONEXISTENT,' 500 494 'document_object: Invalid value\r\n' 501 '3,c7,My sixt contract,SampleContract,NONEXISTENT, d101,'495 '3,c7,My sixt contract,SampleContract,NONEXISTENT,DOC1,' 502 496 'product_object: Invalid value\r\n') 503 497 contract = self.processor.getEntry(dict(reg_number='1', -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
r12246 r12256 120 120 self.document = createObject('waeup.CustomerSampleDocument') 121 121 self.document.title = u'My first document' 122 self.document.document_id = u'DOC1' 122 123 self.customer['documents'].addDocument(self.document) 123 124 self.contract = createObject('waeup.SampleContract') … … 834 835 self.browser.getControl("Add document").click() 835 836 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] 837 839 838 840 # Document can be edited 839 self.browser.getLink( "d102").click()841 self.browser.getLink(docid).click() 840 842 self.browser.getLink("Manage").click() 841 843 self.browser.getControl(name="form.title").value = 'My second doc' … … 843 845 self.assertTrue('Form has been saved.' in self.browser.contents) 844 846 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') 846 849 847 850 # Transitions can be performed … … 859 862 860 863 # 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') 862 865 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') 866 869 self.assertTrue( 867 870 'The requested form is locked (read-only)' … … 881 884 882 885 self.assertTrue( 883 'INFO - system - K1000000 - d101 - Document created'886 'INFO - system - K1000000 - DOC1 - Document created' 884 887 in logcontent) 885 888 self.assertTrue( … … 889 892 self.assertTrue( 890 893 'INFO - zope.mgr - customers.browser.DocumentManageFormPage ' 891 '- K1000000 - d102 - saved: title'894 '- K1000000 - %s - saved: title' % docid 892 895 in logcontent) 893 896 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) 896 899 self.assertTrue( 897 900 'INFO - zope.mgr - customers.browser.DocumentsManageFormPage ' 898 '- K1000000 - removed: d102'901 '- K1000000 - removed: %s' % docid 899 902 in logcontent) 900 903 … … 913 916 self.browser.getControl("Add document").click() 914 917 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] 916 920 917 921 # 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') 920 924 #self.browser.getLink("Edit").click() 921 925 self.assertTrue('The requested form is locked' in self.browser.contents) 922 926 # Customer is in wrong state 923 927 IWorkflowState(self.customer).setState(APPROVED) 924 self.browser.open(self.documents_path + '/ d102/edit')928 self.browser.open(self.documents_path + '/' + docid + '/edit') 925 929 self.browser.getControl(name="form.title").value = 'My second doc' 926 930 self.browser.getControl("Save").click() … … 928 932 self.assertTrue('Form has been saved.' in self.browser.contents) 929 933 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) 931 936 # Costumer can upload a document. 932 937 self.browser.getLink("Edit").click() … … 938 943 name='upload_samplescaneditupload').click() 939 944 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) 942 947 # Costumer can submit the form. The form is also saved. 943 948 self.browser.getControl(name="form.title").value = 'My third doc' … … 947 952 self.assertTrue('Document State: submitted for verification' in self.browser.contents) 948 953 # 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) 950 955 self.assertTrue('The requested form is locked' in self.browser.contents) 951 956 … … 954 959 # The image is stored even if form has errors 955 960 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') 957 962 # Create a pseudo image file and select it to be uploaded 958 963 image = open(SAMPLE_IMAGE, 'rb') … … 963 968 self.browser.getControl("Save").click() # submit form 964 969 self.assertFalse( 965 'href="http://localhost/app/customers/K1000000/documents/ d101/sample"'970 'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"' 966 971 in self.browser.contents) 967 972 # ... but the correct upload submit button does … … 973 978 name='upload_samplescanmanageupload').click() 974 979 self.assertTrue( 975 'href="http://localhost/app/customers/K1000000/documents/ d101/sample"'980 'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"' 976 981 in self.browser.contents) 977 982 # Browsing the link shows a real image … … 981 986 self.assertEqual(len(self.browser.contents), 2787) 982 987 # 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') 984 989 self.assertFalse( 985 990 'upload_samplescanmanageupload' in self.browser.contents) … … 1024 1029 def test_verify_document(self): 1025 1030 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') 1027 1032 image = open(SAMPLE_IMAGE, 'rb') 1028 1033 ctrl = self.browser.getControl(name='samplescanmanageupload') … … 1035 1040 self.assertEqual( 1036 1041 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') 1038 1043 self.browser.getControl(name="transition").value = ['verify'] 1039 1044 self.browser.getControl("Apply now").click() … … 1051 1056 self.browser.getControl(name="form.title").value = 'My PDF Document' 1052 1057 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) 1054 1060 # Create a pseudo image file and select it to be uploaded 1055 1061 image = open(SAMPLE_IMAGE, 'rb') … … 1075 1081 name='upload_pdfscanmanageupload').click() 1076 1082 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) 1079 1085 # Browsing the link shows a real pdf 1080 1086 self.browser.open('sample.pdf') … … 1098 1104 jpegfile = open(SAMPLE_IMAGE, 'rb') 1099 1105 fs.createFile(file_id, jpegfile) 1100 self.browser.open(self.customer_path + '/documents/ d101')1106 self.browser.open(self.customer_path + '/documents/DOC1') 1101 1107 self.browser.getLink("Download document slip").click() 1102 1108 self.assertEqual(self.browser.headers['Status'], '200 Ok') … … 1114 1120 pdffile = open(SAMPLE_PDF, 'rb') 1115 1121 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) 1117 1124 self.browser.getLink("Download document slip").click() 1118 1125 self.assertEqual(self.browser.headers['Status'], '200 Ok') … … 1129 1136 fs.createFile(file_id, StringIO('my sample 1')) 1130 1137 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') 1132 1139 self.assertEqual(result.read(), 'my sample 1') 1133 1140 self.assertEqual(self.document.connected_files[0][1].read(), 'my sample 1') … … 1253 1260 self.browser.open(self.contracts_path + '/c102/edit') 1254 1261 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'] 1256 1263 self.browser.getControl(name="form.title").value = 'My second contract' 1257 1264 self.browser.getControl("Save").click() … … 1273 1280 in self.browser.contents) 1274 1281 self.assertTrue( 1275 '<a href="http://localhost/app/customers/K1000000/documents/ d101">d101 -'1282 '<a href="http://localhost/app/customers/K1000000/documents/DOC1">DOC1 -' 1276 1283 in self.browser.contents) 1277 1284 # Customer can submit the form. The form is also saved. -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_catalog.py
r12195 r12256 213 213 logcontent = open(logfile).read() 214 214 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 156 156 # we can't get an image filename for documents not owned by a customer 157 157 doc = CustomerSampleDocument() 158 doc.document_id = u'DOC1' 158 159 chooser = IFileStoreNameChooser(doc) 159 160 # no customer can be found … … 168 169 result = chooser.chooseName('sample.jpg') 169 170 self.assertEqual( 170 result, '__file-customerdocument__01000/K1000001/sample_ d123_K1000001.jpg')171 result, '__file-customerdocument__01000/K1000001/sample_DOC1_K1000001.jpg') 171 172 return -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py
r12221 r12256 156 156 # we can export a nearly empty document 157 157 document = CustomerSampleDocument() 158 document.document_id = u'DOC1' 158 159 exporter = CustomerDocumentExporter() 159 160 exporter.export([document], self.outfile) … … 162 163 result, 163 164 'class_name,document_id,history,state,title,user_id\r\n' 164 'CustomerSampleDocument, d101,[],,,\r\n'165 'CustomerSampleDocument,DOC1,[],,,\r\n' 165 166 ) 166 167 return … … 170 171 # set values we can expect in export file 171 172 self.setup_customer(self.customer) 172 document = self.customer['documents'][' d101']173 document = self.customer['documents']['DOC1'] 173 174 exporter = CustomerDocumentExporter() 174 175 exporter.export([document], self.outfile) … … 179 180 ) 180 181 self.assertMatches( 181 '...CustomerSampleDocument, d101,[u\'2014-11-25 06:57:24 UTC - '182 '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - ' 182 183 'Document created by system\'],' 183 184 'verified,My Document,A111111...', … … 197 198 in result) 198 199 self.assertMatches( 199 '...CustomerSampleDocument, d101,[u\'2014-11-25 06:57:24 UTC - '200 '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - ' 200 201 'Document created by system\'],' 201 202 'verified,My Document,A111111...', … … 215 216 in result) 216 217 self.assertMatches( 217 '...CustomerSampleDocument, d101,[u\'2014-11-25 06:57:24 UTC - '218 '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - ' 218 219 'Document created by system\'],' 219 220 'verified,My Document,A111111...', … … 273 274 'product_object,state,title\r\n' 274 275 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 - ' 276 277 'Contract created by system\'],,' 277 278 'SAM,created,My Contract\r\n', … … 292 293 'product_object,state,title\r\n' 293 294 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 - ' 295 296 'Contract created by system\'],,' 296 297 'SAM,created,My Contract\r\n', … … 311 312 'product_object,state,title\r\n' 312 313 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 - ' 314 315 'Contract created by system\'],,' 315 316 'SAM,created,My Contract\r\n', -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_interfaces.py
r12102 r12256 77 77 document = createObject('waeup.CustomerSampleDocument') 78 78 document.title = u'My Samle Document' 79 document.document_id = u'DOC1' 79 80 self.customer['documents'].addDocument(document) 80 81 self.document_id = document.document_id … … 107 108 source = CustomerDocumentSource() 108 109 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') 110 111 -
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.