Changeset 12384 for main/ikobacustom.pcn/trunk/src
- Timestamp:
- 3 Jan 2015, 18:02:11 (10 years ago)
- Location:
- main/ikobacustom.pcn/trunk/src/ikobacustom/pcn
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/batching.py
r12371 r12384 24 24 from ikobacustom.pcn.customers.interfaces import ( 25 25 IPCNCustomer, 26 IPCNCustomerDocument, IPCNContract) 26 IPCNCustomerJPGDocument, 27 IPCNCustomerPDFDocument, 28 IPCNContract) 27 29 from ikobacustom.pcn.interfaces import MessageFactory as _ 28 30 … … 37 39 38 40 39 class PCNCustomer DocumentProcessor(CustomerDocumentProcessorBase):40 """A batch processor for IPCNCustomer Document objects.41 class PCNCustomerJPGDocumentProcessor(CustomerDocumentProcessorBase): 42 """A batch processor for IPCNCustomerJPGDocument objects. 41 43 """ 42 util_name = 'pcncustomer documentprocessor'44 util_name = 'pcncustomerjpgdocumentprocessor' 43 45 grok.name(util_name) 44 name = _('PCN Customer Document Processor')45 iface = IPCNCustomer Document46 factory_name = 'waeup.PCNCustomer Document'46 name = _('PCN Customer JPG Document Processor') 47 iface = IPCNCustomerJPGDocument 48 factory_name = 'waeup.PCNCustomerJPGDocument' 47 49 50 class PCNCustomerPDFDocumentProcessor(CustomerDocumentProcessorBase): 51 """A batch processor for IPCNCustomerPDFDocument objects. 52 """ 53 util_name = 'pcncustomerpdfdocumentprocessor' 54 grok.name(util_name) 55 name = _('PCN Customer PDF Document Processor') 56 iface = IPCNCustomerPDFDocument 57 factory_name = 'waeup.PCNCustomerPDFDocument' 48 58 49 59 class PCNContractProcessor(ContractProcessorBase): -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/documents.py
r12371 r12384 26 26 from waeup.ikoba.customers.documents import CustomerDocumentBase 27 27 from ikobacustom.pcn.interfaces import MessageFactory as _ 28 from ikobacustom.pcn.customers.interfaces import IPCNCustomerDocument 28 from ikobacustom.pcn.customers.interfaces import ( 29 IPCNCustomerJPGDocument, IPCNCustomerPDFDocument) 29 30 30 31 31 class PCNCustomer Document(CustomerDocumentBase):32 class PCNCustomerJPGDocument(CustomerDocumentBase): 32 33 """This is a sample customer document. 33 34 """ 34 35 35 grok.implements(IPCNCustomer Document, ICustomerNavigation)36 grok.provides(IPCNCustomer Document)36 grok.implements(IPCNCustomerJPGDocument, ICustomerNavigation) 37 grok.provides(IPCNCustomerJPGDocument) 37 38 38 39 # Ikoba can store any number of files per Document object. … … 40 41 # only one file per Document object. Thus the following 41 42 # tuple should contain only a single filename string. 42 filenames = ('s ample',)43 filenames = ('scan.jpg',) 43 44 44 form_fields_interface = IPCNCustomer Document45 form_fields_interface = IPCNCustomerJPGDocument 45 46 46 PCNCustomer Document = attrs_to_fields(PCNCustomerDocument)47 PCNCustomerJPGDocument = attrs_to_fields(PCNCustomerJPGDocument) 47 48 48 49 49 # Customer documents must be importable. So we need a factory. 50 class PCNCustomerDocumentFactory(grok.GlobalUtility): 50 class PCNCustomerJPGDocumentFactory(grok.GlobalUtility): 51 51 """A factory for customer documents. 52 52 """ 53 53 grok.implements(IFactory) 54 grok.name(u'waeup.PCNCustomer Document')54 grok.name(u'waeup.PCNCustomerJPGDocument') 55 55 title = u"Create a new document.", 56 description = u"This factory instantiates new sampledocument instances."56 description = u"This factory instantiates new document instances." 57 57 58 58 def __call__(self, *args, **kw): 59 return PCNCustomer Document(*args, **kw)59 return PCNCustomerJPGDocument(*args, **kw) 60 60 61 61 def getInterfaces(self): 62 return implementedBy(PCNCustomerDocument) 62 return implementedBy(PCNCustomerJPGDocument) 63 64 class PCNCustomerPDFDocument(CustomerDocumentBase): 65 """This is a sample customer document. 66 """ 67 68 grok.implements(IPCNCustomerPDFDocument, ICustomerNavigation) 69 grok.provides(IPCNCustomerPDFDocument) 70 71 filenames = ('scan.pdf',) 72 73 form_fields_interface = IPCNCustomerPDFDocument 74 75 PCNCustomerPDFDocument = attrs_to_fields(PCNCustomerPDFDocument) 76 77 78 class PCNCustomerPDFDocumentFactory(grok.GlobalUtility): 79 """A factory for customer documents. 80 """ 81 grok.implements(IFactory) 82 grok.name(u'waeup.PCNCustomerPDFDocument') 83 title = u"Create a new document.", 84 description = u"This factory instantiates new document instances." 85 86 def __call__(self, *args, **kw): 87 return PCNCustomerPDFDocument(*args, **kw) 88 89 def getInterfaces(self): 90 return implementedBy(PCNCustomerPDFDocument) -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/export.py
r12371 r12384 22 22 CustomerExporter, CustomerDocumentExporterBase, ContractExporterBase) 23 23 from ikobacustom.pcn.customers.interfaces import ( 24 IPCNCustomer, IPCNCustomerDocument, IPCNContract) 24 IPCNCustomer, IPCNCustomerJPGDocument, 25 IPCNCustomerPDFDocument, IPCNContract) 25 26 from ikobacustom.pcn.interfaces import MessageFactory as _ 26 27 … … 32 33 33 34 34 class PCNCustomer DocumentExporter(CustomerDocumentExporterBase):35 class PCNCustomerJPGDocumentExporter(CustomerDocumentExporterBase): 35 36 """Exporter for documents. 36 37 """ 37 grok.name('pcncustomerdocuments') 38 iface = IPCNCustomerDocument 39 title = _(u'PCN Customer Documents') 40 class_name = 'PCNCustomerDocument' 38 grok.name('pcncustomerjpgdocuments') 39 iface = IPCNCustomerJPGDocument 40 title = _(u'PCN Customer JPG Documents') 41 class_name = 'PCNCustomerJPGDocument' 42 43 class PCNCustomerPDFDocumentExporter(CustomerDocumentExporterBase): 44 """Exporter for documents. 45 """ 46 grok.name('pcncustomerpdfdocuments') 47 iface = IPCNCustomerPDFDocument 48 title = _(u'PCN Customer PDF Documents') 49 class_name = 'PCNCustomerPDFDocument' 41 50 42 51 -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/fileviewlets.py
r12373 r12384 23 23 FileDisplay, FileUpload, Image) 24 24 25 from ikobacustom.pcn.customers.documents import PCNCustomerDocument 25 from ikobacustom.pcn.customers.documents import ( 26 PCNCustomerJPGDocument, PCNCustomerPDFDocument) 26 27 27 28 from waeup.ikoba.customers.browser import ( … … 35 36 # File viewlets for customer documents 36 37 37 class SampleScanManageUpload(FileUpload):38 class JPGScanManageUpload(FileUpload): 38 39 """Scan upload viewlet for officers. 39 40 """ 40 41 grok.order(1) 41 grok.context(PCNCustomer Document)42 grok.context(PCNCustomerJPGDocument) 42 43 grok.view(DocumentManageFormPage) 43 44 grok.require('waeup.manageCustomer') … … 45 46 title = _(u'Sample Scan') 46 47 mus = 1024 * 50 47 download_name = u's ample'48 download_name = u'scan.jpg' 48 49 tab_redirect = '#tab2' 49 50 50 51 51 class SampleScanEditUpload(SampleScanManageUpload):52 class JPGScanEditUpload(JPGScanManageUpload): 52 53 """Scan upload viewlet for customer. 53 54 """ … … 56 57 57 58 58 class SampleScanDisplay(FileDisplay):59 class JPGScanDisplay(FileDisplay): 59 60 """Scan display viewlet. 60 61 """ 61 62 grok.order(1) 62 grok.context(PCNCustomer Document)63 grok.context(PCNCustomerJPGDocument) 63 64 grok.require('waeup.viewCustomer') 64 65 grok.view(DocumentDisplayFormPage) 65 66 label = _(u'Sample Scan') 66 67 title = _(u'Sample Scan') 67 download_name = u's ample'68 download_name = u'scan.jpg' 68 69 69 70 70 class SampleScanImage(Image):71 class JPGScanImage(Image): 71 72 """Scan document. 72 73 """ 73 grok.name('s ample')74 grok.context(PCNCustomer Document)74 grok.name('scan.jpg') 75 grok.context(PCNCustomerJPGDocument) 75 76 grok.require('waeup.viewCustomer') 76 download_name = u's ample'77 download_name = u'scan.jpg' 77 78 78 class SampleScanPDFSlip(SampleScanDisplay):79 class JPGScanPDFSlip(JPGScanDisplay): 79 80 grok.view(PDFDocumentSlipPage) 80 81 … … 84 85 """ 85 86 grok.view(DocumentManageFormPage) 86 grok.context(PCNCustomer Document)87 grok.context(PCNCustomerPDFDocument) 87 88 grok.require('waeup.manageCustomer') 88 89 label = _(u'PDF File') 89 90 title = _(u'PDF File') 90 91 mus = 1024 * 200 91 download_name = u's ample.pdf'92 download_name = u'scan.pdf' 92 93 tab_redirect = '#tab2' 93 94 … … 104 105 """ 105 106 grok.order(1) 106 grok.context(PCNCustomer Document)107 grok.context(PCNCustomerPDFDocument) 107 108 grok.require('waeup.viewCustomer') 108 109 grok.view(DocumentDisplayFormPage) 109 110 label = _(u'PDF Scan') 110 111 title = _(u'PDF Scan') 111 download_name = u's ample.pdf'112 download_name = u'scan.pdf' 112 113 113 114 … … 115 116 """Scan document. 116 117 """ 117 grok.name('s ample.pdf')118 grok.context(PCNCustomer Document)118 grok.name('scan.pdf') 119 grok.context(PCNCustomerPDFDocument) 119 120 grok.require('waeup.viewCustomer') 120 download_name = u's ample.pdf'121 download_name = u'scan.pdf' 121 122 122 123 class PDFScanSlip(PDFScanDisplay): -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/interfaces.py
r12371 r12384 19 19 from zope import schema 20 20 from waeup.ikoba.customers.interfaces import ( 21 ICustomer, ICustomerDocument, IC ontract)21 ICustomer, ICustomerDocument, ICustomerPDFDocument, IContract) 22 22 from waeup.ikoba.customers.vocabularies import ( 23 23 ConCatProductSource, CustomerDocumentSource) … … 34 34 35 35 36 class IPCNCustomerDocument(ICustomerDocument): 37 """A customer document. 36 class IPCNCustomerJPGDocument(ICustomerDocument): 37 """A customer jpg document. 38 39 """ 40 41 class IPCNCustomerPDFDocument(ICustomerPDFDocument): 42 """A customer pdf document. 38 43 39 44 """ -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_browser.py
r12371 r12384 32 32 from ikobacustom.pcn.customers.export import ( 33 33 PCNCustomerExporter, 34 PCNCustomerDocumentExporter, 34 PCNCustomerPDFDocumentExporter, 35 PCNCustomerJPGDocumentExporter, 35 36 PCNContractExporter) 36 37 from ikobacustom.pcn.customers.batching import ( 37 38 PCNCustomerProcessor, 38 PCNCustomerDocumentProcessor, 39 PCNCustomerPDFDocumentProcessor, 40 PCNCustomerJPGDocumentProcessor, 39 41 PCNContractProcessor) 40 42 from ikobacustom.pcn.testing import FunctionalLayer, samples_dir … … 56 58 IWorkflowState(customer).setState('started') 57 59 self.app['customers'].addCustomer(customer) 58 document = createObject(u'waeup.PCNCustomerDocument') 59 document.title = u'My first document' 60 customer['documents'].addDocument(document) 60 document1 = createObject(u'waeup.PCNCustomerPDFDocument') 61 document1.title = u'My first document' 62 document2 = createObject(u'waeup.PCNCustomerJPGDocument') 63 document2.title = u'My second document' 64 customer['documents'].addDocument(document1) 65 customer['documents'].addDocument(document2) 61 66 contract = createObject(u'waeup.PCNContract') 62 67 contract.tc_dict = {'en':u'Hello World'} 63 68 customer['contracts'].addContract(contract) 64 69 self.customer = customer 65 self.document = document 70 self.document1 = document1 71 self.document2 = document2 66 72 self.contract = contract 67 73 self.outfile = os.path.join(self.workdir, 'myoutput.csv') … … 108 114 return 109 115 110 def test_export_reimport_ documents(self):116 def test_export_reimport_pdf_documents(self): 111 117 # we can export all documents in a portal 112 118 # set values we can expect in export file 113 119 self.setup_for_export() 114 exporter = PCNCustomer DocumentExporter()120 exporter = PCNCustomerPDFDocumentExporter() 115 121 exporter.export_all(self.app, self.outfile) 116 122 result = open(self.outfile, 'rb').read() 117 123 self.assertMatches(result, 118 124 'class_name,document_id,history,state,title,user_id\r\n' 119 'PCNCustomer Document,%s,'125 'PCNCustomerPDFDocument,%s,' 120 126 '[u\'2014-12-21 17:00:36 WAT - Document created by system\'],' 121 127 'created,My first document,K1000000\r\n' 122 % self.document .document_id)128 % self.document1.document_id) 123 129 # We can reimport the file if we change the header (user_id -> customer_id) 124 processor = PCNCustomer DocumentProcessor()130 processor = PCNCustomerPDFDocumentProcessor() 125 131 open(self.outfile, 'wb').write( 126 132 'customer_id,class_name,document_id,state,title\r\n' 127 'K1000000,PCNCustomer Document,%s,started,My first title\r\n'128 % self.document .document_id)133 'K1000000,PCNCustomerPDFDocument,%s,started,My first title\r\n' 134 % self.document1.document_id) 129 135 result = processor.doImport( 130 136 self.outfile, … … 135 141 self.assertEqual(num_fail,1) 136 142 # We remove the original document. 137 del self.customer['documents'][self.document.document_id] 143 del self.customer['documents'][self.document1.document_id] 144 result = processor.doImport( 145 self.outfile, 146 ['customer_id','class_name','document_id','state','title'], 147 mode='create') 148 num_succ, num_fail, finished_path, failed_path = result 149 self.assertEqual(num_fail,0) 150 # We can import the same file in update mode. 151 result = processor.doImport( 152 self.outfile, 153 ['customer_id','class_name','document_id','state','title'], 154 mode='update') 155 num_succ, num_fail, finished_path, failed_path = result 156 self.assertEqual(num_succ,1) 157 self.assertEqual(num_fail,0) 158 return 159 160 def test_export_reimport_jpg_documents(self): 161 # we can export all documents in a portal 162 # set values we can expect in export file 163 self.setup_for_export() 164 exporter = PCNCustomerJPGDocumentExporter() 165 exporter.export_all(self.app, self.outfile) 166 result = open(self.outfile, 'rb').read() 167 self.assertMatches(result, 168 'class_name,document_id,history,state,title,user_id\r\n' 169 'PCNCustomerJPGDocument,%s,' 170 '[u\'2014-12-21 17:00:36 WAT - Document created by system\'],' 171 'created,My second document,K1000000\r\n' 172 % self.document2.document_id) 173 # We can reimport the file if we change the header (user_id -> customer_id) 174 processor = PCNCustomerJPGDocumentProcessor() 175 open(self.outfile, 'wb').write( 176 'customer_id,class_name,document_id,state,title\r\n' 177 'K1000000,PCNCustomerJPGDocument,%s,started,My second title\r\n' 178 % self.document2.document_id) 179 result = processor.doImport( 180 self.outfile, 181 ['customer_id','class_name','document_id','state','title'], 182 mode='create') 183 num, num_fail, finished_path, failed_path = result 184 # The object exists. 185 self.assertEqual(num_fail,1) 186 # We remove the original document. 187 del self.customer['documents'][self.document2.document_id] 138 188 result = processor.doImport( 139 189 self.outfile, … … 219 269 self.browser.open(self.customer_path + '/documents') 220 270 self.browser.getControl("Add document").click() 221 self.browser.getControl(name="doctype").value = ['PCNCustomer Document']271 self.browser.getControl(name="doctype").value = ['PCNCustomerPDFDocument'] 222 272 self.browser.getControl(name="form.title").value = 'My PCN Document' 223 273 self.browser.getControl("Add document").click() … … 247 297 name='upload_pdfscanmanageupload').click() 248 298 self.assertTrue( 249 'href="http://localhost/app/customers/K1000000/documents/%s/s ample.pdf">PDF File</a>'299 'href="http://localhost/app/customers/K1000000/documents/%s/scan.pdf">PDF File</a>' 250 300 % docid in self.browser.contents) 251 301 # Browsing the link shows a real pdf 252 self.browser.open('s ample.pdf')302 self.browser.open('scan.pdf') 253 303 self.assertEqual( 254 304 self.browser.headers['content-type'], 'application/pdf') -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_document.py
r12371 r12384 29 29 30 30 from ikobacustom.pcn.testing import (FunctionalLayer, FunctionalTestCase) 31 from ikobacustom.pcn.customers.documents import PCNCustomer Document32 from ikobacustom.pcn.customers.interfaces import IPCNCustomer Document31 from ikobacustom.pcn.customers.documents import PCNCustomerPDFDocument 32 from ikobacustom.pcn.customers.interfaces import IPCNCustomerPDFDocument 33 33 34 34 … … 38 38 39 39 def test_interfaces(self): 40 verify.verifyClass(IPCNCustomer Document, PCNCustomerDocument)41 verify.verifyClass(ICustomerNavigation, PCNCustomer Document)42 verify.verifyObject(IPCNCustomer Document, PCNCustomerDocument())43 verify.verifyObject(ICustomerNavigation, PCNCustomer Document())40 verify.verifyClass(IPCNCustomerPDFDocument, PCNCustomerPDFDocument) 41 verify.verifyClass(ICustomerNavigation, PCNCustomerPDFDocument) 42 verify.verifyObject(IPCNCustomerPDFDocument, PCNCustomerPDFDocument()) 43 verify.verifyObject(ICustomerNavigation, PCNCustomerPDFDocument()) 44 44 return 45 45 46 46 def test_addDocument(self): 47 47 container = CustomerDocumentsContainer() 48 document = createObject(u'waeup.PCNCustomer Document')48 document = createObject(u'waeup.PCNCustomerPDFDocument') 49 49 id = document.document_id 50 50 container.addDocument(document) 51 51 self.assertEqual(container[id], document) 52 52 self.assertRaises(TypeError, container.addDocument, object()) 53 self.assertEqual(document.class_name, 'PCNCustomer Document')53 self.assertEqual(document.class_name, 'PCNCustomerPDFDocument') 54 54 return -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/utils.py
r12371 r12384 47 47 #'CustomerPDFDocument': _('PDF Document'), 48 48 49 'PCNCustomerDocument': _('PCN Document'), 49 'PCNCustomerJPGDocument': _('JPG Document'), 50 'PCNCustomerPDFDocument': _('PDF Document'), 50 51 } 51 52 … … 62 63 EXPORTER_NAMES = ( 63 64 'customers', 64 'pcncustomerdocuments', 65 'pcncustomerjpgdocuments', 66 'pcncustomerpdfdocuments', 65 67 'pcncontracts') -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/utils/utils.py
r12380 r12384 60 60 'products', 61 61 'customers', 62 'pcncustomerdocuments', 62 'pcncustomerjpgdocuments', 63 'pcncustomerpdfdocuments', 63 64 'pcncontracts') 64 65 65 66 BATCH_PROCESSOR_NAMES = ( 66 67 'pcncustomerprocessor', 67 'pcncustomerdocumentprocessor', 68 'pcncustomerjpgdocumentprocessor', 69 'pcncustomerpdfdocumentprocessor', 68 70 'pcncontractprocessor', 69 71 'pcnproductprocessor',
Note: See TracChangeset for help on using the changeset viewer.