Changeset 12384 for main/ikobacustom.pcn


Ignore:
Timestamp:
3 Jan 2015, 18:02:11 (10 years ago)
Author:
Henrik Bettermann
Message:

Implement two different types of PCN customer documents.

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  
    2424from ikobacustom.pcn.customers.interfaces import (
    2525    IPCNCustomer,
    26     IPCNCustomerDocument, IPCNContract)
     26    IPCNCustomerJPGDocument,
     27    IPCNCustomerPDFDocument,
     28    IPCNContract)
    2729from ikobacustom.pcn.interfaces import MessageFactory as _
    2830
     
    3739
    3840
    39 class PCNCustomerDocumentProcessor(CustomerDocumentProcessorBase):
    40     """A batch processor for IPCNCustomerDocument objects.
     41class PCNCustomerJPGDocumentProcessor(CustomerDocumentProcessorBase):
     42    """A batch processor for IPCNCustomerJPGDocument objects.
    4143    """
    42     util_name = 'pcncustomerdocumentprocessor'
     44    util_name = 'pcncustomerjpgdocumentprocessor'
    4345    grok.name(util_name)
    44     name = _('PCN Customer Document Processor')
    45     iface = IPCNCustomerDocument
    46     factory_name = 'waeup.PCNCustomerDocument'
     46    name = _('PCN Customer JPG Document Processor')
     47    iface = IPCNCustomerJPGDocument
     48    factory_name = 'waeup.PCNCustomerJPGDocument'
    4749
     50class 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'
    4858
    4959class PCNContractProcessor(ContractProcessorBase):
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/documents.py

    r12371 r12384  
    2626from waeup.ikoba.customers.documents import CustomerDocumentBase
    2727from ikobacustom.pcn.interfaces import MessageFactory as _
    28 from ikobacustom.pcn.customers.interfaces import IPCNCustomerDocument
     28from ikobacustom.pcn.customers.interfaces import (
     29    IPCNCustomerJPGDocument, IPCNCustomerPDFDocument)
    2930
    3031
    31 class PCNCustomerDocument(CustomerDocumentBase):
     32class PCNCustomerJPGDocument(CustomerDocumentBase):
    3233    """This is a sample customer document.
    3334    """
    3435
    35     grok.implements(IPCNCustomerDocument, ICustomerNavigation)
    36     grok.provides(IPCNCustomerDocument)
     36    grok.implements(IPCNCustomerJPGDocument, ICustomerNavigation)
     37    grok.provides(IPCNCustomerJPGDocument)
    3738
    3839    # Ikoba can store any number of files per Document object.
     
    4041    # only one file per Document object. Thus the following
    4142    # tuple should contain only a single filename string.
    42     filenames = ('sample',)
     43    filenames = ('scan.jpg',)
    4344
    44     form_fields_interface = IPCNCustomerDocument
     45    form_fields_interface = IPCNCustomerJPGDocument
    4546
    46 PCNCustomerDocument = attrs_to_fields(PCNCustomerDocument)
     47PCNCustomerJPGDocument = attrs_to_fields(PCNCustomerJPGDocument)
    4748
    4849
    49 # Customer documents must be importable. So we need a factory.
    50 class PCNCustomerDocumentFactory(grok.GlobalUtility):
     50class PCNCustomerJPGDocumentFactory(grok.GlobalUtility):
    5151    """A factory for customer documents.
    5252    """
    5353    grok.implements(IFactory)
    54     grok.name(u'waeup.PCNCustomerDocument')
     54    grok.name(u'waeup.PCNCustomerJPGDocument')
    5555    title = u"Create a new document.",
    56     description = u"This factory instantiates new sample document instances."
     56    description = u"This factory instantiates new document instances."
    5757
    5858    def __call__(self, *args, **kw):
    59         return PCNCustomerDocument(*args, **kw)
     59        return PCNCustomerJPGDocument(*args, **kw)
    6060
    6161    def getInterfaces(self):
    62         return implementedBy(PCNCustomerDocument)
     62        return implementedBy(PCNCustomerJPGDocument)
     63
     64class 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
     75PCNCustomerPDFDocument = attrs_to_fields(PCNCustomerPDFDocument)
     76
     77
     78class 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  
    2222    CustomerExporter, CustomerDocumentExporterBase, ContractExporterBase)
    2323from ikobacustom.pcn.customers.interfaces import (
    24     IPCNCustomer, IPCNCustomerDocument, IPCNContract)
     24    IPCNCustomer, IPCNCustomerJPGDocument,
     25    IPCNCustomerPDFDocument, IPCNContract)
    2526from ikobacustom.pcn.interfaces import MessageFactory as _
    2627
     
    3233
    3334
    34 class PCNCustomerDocumentExporter(CustomerDocumentExporterBase):
     35class PCNCustomerJPGDocumentExporter(CustomerDocumentExporterBase):
    3536    """Exporter for documents.
    3637    """
    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
     43class 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'
    4150
    4251
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/fileviewlets.py

    r12373 r12384  
    2323    FileDisplay, FileUpload, Image)
    2424
    25 from ikobacustom.pcn.customers.documents import PCNCustomerDocument
     25from ikobacustom.pcn.customers.documents import (
     26    PCNCustomerJPGDocument, PCNCustomerPDFDocument)
    2627
    2728from waeup.ikoba.customers.browser import (
     
    3536# File viewlets for customer documents
    3637
    37 class SampleScanManageUpload(FileUpload):
     38class JPGScanManageUpload(FileUpload):
    3839    """Scan upload viewlet for officers.
    3940    """
    4041    grok.order(1)
    41     grok.context(PCNCustomerDocument)
     42    grok.context(PCNCustomerJPGDocument)
    4243    grok.view(DocumentManageFormPage)
    4344    grok.require('waeup.manageCustomer')
     
    4546    title = _(u'Sample Scan')
    4647    mus = 1024 * 50
    47     download_name = u'sample'
     48    download_name = u'scan.jpg'
    4849    tab_redirect = '#tab2'
    4950
    5051
    51 class SampleScanEditUpload(SampleScanManageUpload):
     52class JPGScanEditUpload(JPGScanManageUpload):
    5253    """Scan upload viewlet for customer.
    5354    """
     
    5657
    5758
    58 class SampleScanDisplay(FileDisplay):
     59class JPGScanDisplay(FileDisplay):
    5960    """Scan display viewlet.
    6061    """
    6162    grok.order(1)
    62     grok.context(PCNCustomerDocument)
     63    grok.context(PCNCustomerJPGDocument)
    6364    grok.require('waeup.viewCustomer')
    6465    grok.view(DocumentDisplayFormPage)
    6566    label = _(u'Sample Scan')
    6667    title = _(u'Sample Scan')
    67     download_name = u'sample'
     68    download_name = u'scan.jpg'
    6869
    6970
    70 class SampleScanImage(Image):
     71class JPGScanImage(Image):
    7172    """Scan document.
    7273    """
    73     grok.name('sample')
    74     grok.context(PCNCustomerDocument)
     74    grok.name('scan.jpg')
     75    grok.context(PCNCustomerJPGDocument)
    7576    grok.require('waeup.viewCustomer')
    76     download_name = u'sample'
     77    download_name = u'scan.jpg'
    7778
    78 class SampleScanPDFSlip(SampleScanDisplay):
     79class JPGScanPDFSlip(JPGScanDisplay):
    7980    grok.view(PDFDocumentSlipPage)
    8081
     
    8485    """
    8586    grok.view(DocumentManageFormPage)
    86     grok.context(PCNCustomerDocument)
     87    grok.context(PCNCustomerPDFDocument)
    8788    grok.require('waeup.manageCustomer')
    8889    label = _(u'PDF File')
    8990    title = _(u'PDF File')
    9091    mus = 1024 * 200
    91     download_name = u'sample.pdf'
     92    download_name = u'scan.pdf'
    9293    tab_redirect = '#tab2'
    9394
     
    104105    """
    105106    grok.order(1)
    106     grok.context(PCNCustomerDocument)
     107    grok.context(PCNCustomerPDFDocument)
    107108    grok.require('waeup.viewCustomer')
    108109    grok.view(DocumentDisplayFormPage)
    109110    label = _(u'PDF Scan')
    110111    title = _(u'PDF Scan')
    111     download_name = u'sample.pdf'
     112    download_name = u'scan.pdf'
    112113
    113114
     
    115116    """Scan document.
    116117    """
    117     grok.name('sample.pdf')
    118     grok.context(PCNCustomerDocument)
     118    grok.name('scan.pdf')
     119    grok.context(PCNCustomerPDFDocument)
    119120    grok.require('waeup.viewCustomer')
    120     download_name = u'sample.pdf'
     121    download_name = u'scan.pdf'
    121122
    122123class PDFScanSlip(PDFScanDisplay):
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/interfaces.py

    r12371 r12384  
    1919from zope import schema
    2020from waeup.ikoba.customers.interfaces import (
    21     ICustomer, ICustomerDocument, IContract)
     21    ICustomer, ICustomerDocument, ICustomerPDFDocument, IContract)
    2222from waeup.ikoba.customers.vocabularies import (
    2323    ConCatProductSource, CustomerDocumentSource)
     
    3434
    3535
    36 class IPCNCustomerDocument(ICustomerDocument):
    37     """A customer document.
     36class IPCNCustomerJPGDocument(ICustomerDocument):
     37    """A customer jpg document.
     38
     39    """
     40
     41class IPCNCustomerPDFDocument(ICustomerPDFDocument):
     42    """A customer pdf document.
    3843
    3944    """
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_browser.py

    r12371 r12384  
    3232from ikobacustom.pcn.customers.export import (
    3333    PCNCustomerExporter,
    34     PCNCustomerDocumentExporter,
     34    PCNCustomerPDFDocumentExporter,
     35    PCNCustomerJPGDocumentExporter,
    3536    PCNContractExporter)
    3637from ikobacustom.pcn.customers.batching import (
    3738    PCNCustomerProcessor,
    38     PCNCustomerDocumentProcessor,
     39    PCNCustomerPDFDocumentProcessor,
     40    PCNCustomerJPGDocumentProcessor,
    3941    PCNContractProcessor)
    4042from ikobacustom.pcn.testing import FunctionalLayer, samples_dir
     
    5658        IWorkflowState(customer).setState('started')
    5759        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)
    6166        contract = createObject(u'waeup.PCNContract')
    6267        contract.tc_dict = {'en':u'Hello World'}
    6368        customer['contracts'].addContract(contract)
    6469        self.customer = customer
    65         self.document = document
     70        self.document1 = document1
     71        self.document2 = document2
    6672        self.contract = contract
    6773        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     
    108114        return
    109115
    110     def test_export_reimport_documents(self):
     116    def test_export_reimport_pdf_documents(self):
    111117        # we can export all documents in a portal
    112118        # set values we can expect in export file
    113119        self.setup_for_export()
    114         exporter = PCNCustomerDocumentExporter()
     120        exporter = PCNCustomerPDFDocumentExporter()
    115121        exporter.export_all(self.app, self.outfile)
    116122        result = open(self.outfile, 'rb').read()
    117123        self.assertMatches(result,
    118124            'class_name,document_id,history,state,title,user_id\r\n'
    119             'PCNCustomerDocument,%s,'
     125            'PCNCustomerPDFDocument,%s,'
    120126            '[u\'2014-12-21 17:00:36 WAT - Document created by system\'],'
    121127            'created,My first document,K1000000\r\n'
    122             % self.document.document_id)
     128            % self.document1.document_id)
    123129        # We can reimport the file if we change the header (user_id -> customer_id)
    124         processor = PCNCustomerDocumentProcessor()
     130        processor = PCNCustomerPDFDocumentProcessor()
    125131        open(self.outfile, 'wb').write(
    126132            'customer_id,class_name,document_id,state,title\r\n'
    127             'K1000000,PCNCustomerDocument,%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)
    129135        result = processor.doImport(
    130136            self.outfile,
     
    135141        self.assertEqual(num_fail,1)
    136142        # 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]
    138188        result = processor.doImport(
    139189            self.outfile,
     
    219269        self.browser.open(self.customer_path + '/documents')
    220270        self.browser.getControl("Add document").click()
    221         self.browser.getControl(name="doctype").value = ['PCNCustomerDocument']
     271        self.browser.getControl(name="doctype").value = ['PCNCustomerPDFDocument']
    222272        self.browser.getControl(name="form.title").value = 'My PCN Document'
    223273        self.browser.getControl("Add document").click()
     
    247297            name='upload_pdfscanmanageupload').click()
    248298        self.assertTrue(
    249             'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">PDF File</a>'
     299            'href="http://localhost/app/customers/K1000000/documents/%s/scan.pdf">PDF File</a>'
    250300            % docid in self.browser.contents)
    251301        # Browsing the link shows a real pdf
    252         self.browser.open('sample.pdf')
     302        self.browser.open('scan.pdf')
    253303        self.assertEqual(
    254304            self.browser.headers['content-type'], 'application/pdf')
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_document.py

    r12371 r12384  
    2929
    3030from ikobacustom.pcn.testing import (FunctionalLayer, FunctionalTestCase)
    31 from ikobacustom.pcn.customers.documents import PCNCustomerDocument
    32 from ikobacustom.pcn.customers.interfaces import IPCNCustomerDocument
     31from ikobacustom.pcn.customers.documents import PCNCustomerPDFDocument
     32from ikobacustom.pcn.customers.interfaces import IPCNCustomerPDFDocument
    3333
    3434
     
    3838
    3939    def test_interfaces(self):
    40         verify.verifyClass(IPCNCustomerDocument, PCNCustomerDocument)
    41         verify.verifyClass(ICustomerNavigation, PCNCustomerDocument)
    42         verify.verifyObject(IPCNCustomerDocument, PCNCustomerDocument())
    43         verify.verifyObject(ICustomerNavigation, PCNCustomerDocument())
     40        verify.verifyClass(IPCNCustomerPDFDocument, PCNCustomerPDFDocument)
     41        verify.verifyClass(ICustomerNavigation, PCNCustomerPDFDocument)
     42        verify.verifyObject(IPCNCustomerPDFDocument, PCNCustomerPDFDocument())
     43        verify.verifyObject(ICustomerNavigation, PCNCustomerPDFDocument())
    4444        return
    4545
    4646    def test_addDocument(self):
    4747        container = CustomerDocumentsContainer()
    48         document = createObject(u'waeup.PCNCustomerDocument')
     48        document = createObject(u'waeup.PCNCustomerPDFDocument')
    4949        id = document.document_id
    5050        container.addDocument(document)
    5151        self.assertEqual(container[id], document)
    5252        self.assertRaises(TypeError, container.addDocument, object())
    53         self.assertEqual(document.class_name, 'PCNCustomerDocument')
     53        self.assertEqual(document.class_name, 'PCNCustomerPDFDocument')
    5454        return
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/utils.py

    r12371 r12384  
    4747        #'CustomerPDFDocument': _('PDF Document'),
    4848
    49         'PCNCustomerDocument': _('PCN Document'),
     49        'PCNCustomerJPGDocument': _('JPG Document'),
     50        'PCNCustomerPDFDocument': _('PDF Document'),
    5051        }
    5152
     
    6263    EXPORTER_NAMES = (
    6364        'customers',
    64         'pcncustomerdocuments',
     65        'pcncustomerjpgdocuments',
     66        'pcncustomerpdfdocuments',
    6567        'pcncontracts')
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/utils/utils.py

    r12380 r12384  
    6060        'products',
    6161        'customers',
    62         'pcncustomerdocuments',
     62        'pcncustomerjpgdocuments',
     63        'pcncustomerpdfdocuments',
    6364        'pcncontracts')
    6465
    6566    BATCH_PROCESSOR_NAMES = (
    6667        'pcncustomerprocessor',
    67         'pcncustomerdocumentprocessor',
     68        'pcncustomerjpgdocumentprocessor',
     69        'pcncustomerpdfdocumentprocessor',
    6870        'pcncontractprocessor',
    6971        'pcnproductprocessor',
Note: See TracChangeset for help on using the changeset viewer.