Changeset 12057 for main


Ignore:
Timestamp:
25 Nov 2014, 13:15:27 (10 years ago)
Author:
Henrik Bettermann
Message:

Use a baseclass for customer documents. That eases file viewlet configuration.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py

    r12056 r12057  
    376376    name = _('CustomerDocument Processor')
    377377    iface = ICustomerDocument
    378     factory_name = 'waeup.CustomerDocument'
     378    factory_name = 'waeup.CustomerSampleDocument'
    379379
    380380    location_fields = []
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12056 r12057  
    5959CustomerDocumentsContainer = attrs_to_fields(CustomerDocumentsContainer)
    6060
    61 class CustomerDocument(Document):
    62     """This is a customer document.
     61class CustomerDocumentBase(Document):
     62    """This is a customer document baseclass.
    6363    """
    6464    grok.implements(ICustomerDocument, ICustomerNavigation)
    6565    grok.provides(ICustomerDocument)
    66 
    67     def __init__(self):
    68         super(CustomerDocument, self).__init__()
    69         return
     66    grok.baseclass()
    7067
    7168    @property
     
    10299            return
    103100
    104 CustomerDocument = attrs_to_fields(CustomerDocument)
    105 
    106 class CustomerPDFDocument(CustomerDocument):
    107     """This is a customer document for a single pdf upload file only.
     101
     102class CustomerSampleDocument(CustomerDocumentBase):
     103    """This is a sample customer document.
     104    """
     105
     106CustomerSampleDocument = attrs_to_fields(CustomerSampleDocument)
     107
     108
     109class CustomerPDFDocument(CustomerDocumentBase):
     110    """This is a customer document for a single pdf upload file.
    108111    """
    109112    grok.implements(ICustomerPDFDocument, ICustomerNavigation)
     
    118121    """
    119122    grok.implements(IFactory)
    120     grok.name(u'waeup.CustomerDocument')
     123    grok.name(u'waeup.CustomerSampleDocument')
    121124    title = u"Create a new document.",
    122125    description = u"This factory instantiates new sample document instances."
    123126
    124127    def __call__(self, *args, **kw):
    125         return CustomerDocument(*args, **kw)
     128        return CustomerSampleDocument(*args, **kw)
    126129
    127130    def getInterfaces(self):
    128         return implementedBy(CustomerDocument)
     131        return implementedBy(CustomerSampleDocument)
    129132
    130133# Customer documents must be importable. So we might need a factory.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/fileviewlets.py

    r12050 r12057  
    3232
    3333from waeup.ikoba.customers.interfaces import (
    34     ICustomer, ICustomersUtils, ICustomerDocument)
     34    ICustomer, ICustomersUtils)
     35
     36from waeup.ikoba.customers.documents import (
     37    CustomerSampleDocument, CustomerPDFDocument
     38    )
    3539from waeup.ikoba.customers.browser import (
    3640    CustomerBaseDisplayFormPage, CustomerBaseManageFormPage,
     
    258262# File viewlets for customer documents
    259263
    260 class ScanManageUpload(FileUpload):
     264class SampleManageUpload(FileUpload):
    261265    """Scan upload viewlet for officers.
    262266    """
    263267    grok.order(1)
    264     grok.context(ICustomerDocument)
     268    grok.context(CustomerSampleDocument)
    265269    grok.view(DocumentManageFormPage)
    266270    grok.require('waeup.manageCustomer')
    267     label = _(u'Scan')
    268     title = _(u'Scan')
     271    label = _(u'Sample Scan')
     272    title = _(u'Sample Scan')
    269273    mus = 1024 * 50
    270     download_name = u'scan'
     274    download_name = u'sample'
    271275    tab_redirect = '#tab2'
    272276
    273277
    274 class ScanEditUpload(ScanManageUpload):
     278class SampleEditUpload(SampleManageUpload):
    275279    """Scan upload viewlet for customer.
    276280    """
     
    279283
    280284
    281 class ScanDisplay(FileDisplay):
     285class SampleDisplay(FileDisplay):
    282286    """Scan display viewlet.
    283287    """
    284288    grok.order(1)
    285     grok.context(ICustomerDocument)
     289    grok.context(CustomerSampleDocument)
    286290    grok.require('waeup.viewCustomer')
    287291    grok.view(DocumentDisplayFormPage)
    288     label = _(u'Scan')
    289     title = _(u'Scan')
    290     download_name = u'scan'
    291 
    292 
    293 class ScanImage(Image):
     292    label = _(u'Sample Scan')
     293    title = _(u'Sample Scan')
     294    download_name = u'sample'
     295
     296
     297class SampleScanImage(Image):
    294298    """Scan document.
    295299    """
    296     grok.name('scan')
    297     grok.context(ICustomerDocument)
    298     grok.require('waeup.viewCustomer')
    299     download_name = u'scan'
     300    grok.name('sample')
     301    grok.context(CustomerSampleDocument)
     302    grok.require('waeup.viewCustomer')
     303    download_name = u'sample'
     304
     305
     306class PDFManageUpload(FileUpload):
     307    """Scan upload viewlet for officers.
     308    """
     309    grok.view(DocumentManageFormPage)
     310    grok.context(CustomerPDFDocument)
     311    grok.require('waeup.manageCustomer')
     312    label = _(u'PDF File')
     313    title = _(u'PDF File')
     314    mus = 1024 * 200
     315    download_name = u'pdffile'
     316    tab_redirect = '#tab2'
     317
     318
     319class PDFEditUpload(PDFManageUpload):
     320    """Scan upload viewlet for customer.
     321    """
     322    grok.view(DocumentEditFormPage)
     323    grok.require('waeup.handleCustomer')
     324
     325
     326class PDFDisplay(FileDisplay):
     327    """Scan display viewlet.
     328    """
     329    grok.order(1)
     330    grok.context(CustomerPDFDocument)
     331    grok.require('waeup.viewCustomer')
     332    grok.view(DocumentDisplayFormPage)
     333    label = _(u'PDF Scan')
     334    title = _(u'PDF Scan')
     335    download_name = u'pdf'
     336
     337
     338class PDFScanImage(Image):
     339    """Scan document.
     340    """
     341    grok.name('pdf')
     342    grok.context(CustomerPDFDocument)
     343    grok.require('waeup.viewCustomer')
     344    download_name = u'pdf'
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12056 r12057  
    269269    """
    270270
    271     is_editable = Attribute('Document editable by customer')
    272     translated_class_name = Attribute('Translatable class name')
     271    #is_editable = Attribute('Document editable by customer')
     272    #translated_class_name = Attribute('Translatable class name')
    273273
    274274
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/sample_document_data.csv

    r12056 r12057  
    11class_name,document_id,reg_number,title
    2 CustomerDocument,d3,1,My first doc
    3 CustomerDocument,d4,2,My second doc
    4 CustomerDocument,d5,3,My third doc
    5 CustomerDocument,,1,My 4th doc
    6 CustomerDocument,d5,2,My stolen doc
     2CustomerSampleDocument,d3,1,My first doc
     3CustomerSampleDocument,d4,2,My second doc
     4CustomerSampleDocument,d5,3,My third doc
     5CustomerSampleDocument,,1,My 4th doc
     6CustomerSampleDocument,d5,2,My stolen doc
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12056 r12057  
    3838    CustomerProcessor, CustomerDocumentProcessor)
    3939from waeup.ikoba.customers.customer import Customer
    40 from waeup.ikoba.customers.documents import CustomerDocument
     40from waeup.ikoba.customers.documents import CustomerSampleDocument
    4141from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    4242
     
    117117        customer.nationality = u'NG'
    118118
    119         document = CustomerDocument()
     119        document = CustomerSampleDocument()
    120120        document.title = u'My Document'
    121121        customer['documents'].addDocument(document)
     
    262262        self.app['customers'].addCustomer(customer)
    263263        self.customer = self.app['customers'][customer.customer_id]
    264         document = createObject(u'waeup.CustomerDocument')
     264        document = createObject(u'waeup.CustomerSampleDocument')
    265265        document.document_id = 'd120'
    266266        self.customer['documents'][document.document_id] = document
     
    306306    def test_addEntry(self):
    307307        self.assertEqual(len(self.customer['documents'].keys()),1)
    308         document1 = createObject(u'waeup.CustomerDocument')
     308        document1 = createObject(u'waeup.CustomerSampleDocument')
    309309        document1.document_id = 'p234'
    310310        self.processor.addEntry(
     
    313313        self.assertEqual(len(self.customer['documents'].keys()),2)
    314314        self.assertEqual(self.customer['documents']['p234'].document_id, 'p234')
    315         document2 = createObject(u'waeup.CustomerDocument')
     315        document2 = createObject(u'waeup.CustomerSampleDocument')
    316316        document1.document_id = 'nonsense'
    317317
    318318    def test_checkConversion(self):
    319319        errs, inv_errs, conv_dict = self.processor.checkConversion(
    320             dict(document_id='d1266236341955', class_name='CustomerDocument'))
     320            dict(document_id='d1266236341955', class_name='CustomerSampleDocument'))
    321321        self.assertEqual(len(errs),0)
    322322        errs, inv_errs, conv_dict = self.processor.checkConversion(
    323             dict(document_id='nonsense', class_name='CustomerDocument'))
     323            dict(document_id='nonsense', class_name='CustomerSampleDocument'))
    324324        self.assertEqual(len(errs),1)
    325325        timestamp = ("%d" % int(time()*10000))[1:]
    326326        document_id = "d%s" % timestamp
    327327        errs, inv_errs, conv_dict = self.processor.checkConversion(
    328             dict(document_id=document_id, class_name='CustomerDocument'))
     328            dict(document_id=document_id, class_name='CustomerSampleDocument'))
    329329        self.assertEqual(len(errs),0)
    330330        errs, inv_errs, conv_dict = self.processor.checkConversion(
     
    340340        self.assertEqual(fail_file,
    341341            'class_name,reg_number,document_id,title,--ERRORS--\r\n'
    342             'CustomerDocument,2,d5,My stolen doc,document_id: id exists\r\n')
     342            'CustomerSampleDocument,2,d5,My stolen doc,document_id: id exists\r\n')
    343343        document = self.processor.getEntry(dict(reg_number='1',
    344344            document_id='d3'), self.app)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12053 r12057  
    103103        self.customer_id = customer.customer_id
    104104        self.customer = self.app['customers'][self.customer_id]
    105         document = createObject('waeup.CustomerDocument')
     105        document = createObject('waeup.CustomerSampleDocument')
    106106        document.title = u'My first document'
    107107        self.customer['documents'].addDocument(document)
     
    800800
    801801class DocumentUITests(CustomersFullSetup):
    802     # Tests for CustomerDocument relates views and pages
     802    # Tests for CustomerSampleDocument relates views and pages
    803803
    804804    def test_manage_document(self):
     
    871871        self.browser.getLink("Documents").click()
    872872        self.browser.getLink("Add document").click()
    873         self.browser.getControl(name="doctype").value = ['CustomerDocument']
     873        self.browser.getControl(name="doctype").value = ['CustomerSampleDocument']
    874874        self.browser.getControl("Create document").click()
    875875        self.assertTrue('Sample Document created.' in self.browser.contents)
     
    892892        # Costumer can upload a document.
    893893        self.browser.getLink("Edit").click()
    894         ctrl = self.browser.getControl(name='scaneditupload')
     894        ctrl = self.browser.getControl(name='sampleeditupload')
    895895        file_obj = open(SAMPLE_IMAGE, 'rb')
    896896        file_ctrl = ctrl.mech_control
    897897        file_ctrl.add_file(file_obj, filename='my_document.jpg')
    898898        self.browser.getControl(
    899             name='upload_scaneditupload').click()
    900         self.assertTrue(
    901             'href="http://localhost/app/customers/K1000000/documents/d102/scan"'
     899            name='upload_sampleeditupload').click()
     900        self.assertTrue(
     901            'href="http://localhost/app/customers/K1000000/documents/d102/sample"'
    902902            in self.browser.contents)
    903903        # Costumer can submit the form. The form is also saved.
     
    918918        # Create a pseudo image file and select it to be uploaded
    919919        image = open(SAMPLE_IMAGE, 'rb')
    920         ctrl = self.browser.getControl(name='scanmanageupload')
     920        ctrl = self.browser.getControl(name='samplemanageupload')
    921921        file_ctrl = ctrl.mech_control
    922         file_ctrl.add_file(image, filename='my_scan.jpg')
     922        file_ctrl.add_file(image, filename='my_sample_scan.jpg')
    923923        # The Save action does not upload files
    924924        self.browser.getControl("Save").click() # submit form
    925925        self.assertFalse(
    926             'href="http://localhost/app/customers/K1000000/documents/d101/scan"'
     926            'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
    927927            in self.browser.contents)
    928928        # ... but the correct upload submit button does
    929929        image = open(SAMPLE_IMAGE)
    930         ctrl = self.browser.getControl(name='scanmanageupload')
     930        ctrl = self.browser.getControl(name='samplemanageupload')
    931931        file_ctrl = ctrl.mech_control
    932         file_ctrl.add_file(image, filename='my_scan.jpg')
    933         self.browser.getControl(
    934             name='upload_scanmanageupload').click()
    935         self.assertTrue(
    936             'href="http://localhost/app/customers/K1000000/documents/d101/scan"'
     932        file_ctrl.add_file(image, filename='my_sample_scan.jpg')
     933        self.browser.getControl(
     934            name='upload_samplemanageupload').click()
     935        self.assertTrue(
     936            'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
    937937            in self.browser.contents)
    938938        # Browsing the link shows a real image
    939         self.browser.open('scan')
     939        self.browser.open('sample')
    940940        self.assertEqual(
    941941            self.browser.headers['content-type'], 'image/jpeg')
     
    944944        self.browser.open(self.customer_path + '/documents/d101/manage')
    945945        self.assertFalse(
    946             'upload_scanmanageupload' in self.browser.contents)
     946            'upload_samplemanageupload' in self.browser.contents)
    947947        # File must be deleted first
    948         self.browser.getControl(name='delete_scanmanageupload').click()
    949         self.assertTrue(
    950             'scan deleted' in self.browser.contents)
     948        self.browser.getControl(name='delete_samplemanageupload').click()
     949        self.assertTrue(
     950            'sample deleted' in self.browser.contents)
    951951        # Uploading a file which is bigger than 150k will raise an error
    952952        big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75)
    953         ctrl = self.browser.getControl(name='scanmanageupload')
     953        ctrl = self.browser.getControl(name='samplemanageupload')
    954954        file_ctrl = ctrl.mech_control
    955         file_ctrl.add_file(big_image, filename='my_scan.jpg')
    956         self.browser.getControl(
    957             name='upload_scanmanageupload').click()
     955        file_ctrl.add_file(big_image, filename='my_sample_scan.jpg')
     956        self.browser.getControl(
     957            name='upload_samplemanageupload').click()
    958958        self.assertTrue(
    959959            'Uploaded file is too big' in self.browser.contents)
    960960        # we do not rely on filename extensions given by uploaders
    961961        image = open(SAMPLE_IMAGE, 'rb') # a jpg-file
    962         ctrl = self.browser.getControl(name='scanmanageupload')
     962        ctrl = self.browser.getControl(name='samplemanageupload')
    963963        file_ctrl = ctrl.mech_control
    964964        # tell uploaded file is bmp
    965         file_ctrl.add_file(image, filename='my_scan.bmp')
    966         self.browser.getControl(
    967             name='upload_scanmanageupload').click()
     965        file_ctrl.add_file(image, filename='my_sample_scan.bmp')
     966        self.browser.getControl(
     967            name='upload_samplemanageupload').click()
    968968        self.assertTrue(
    969969            # jpg file was recognized
    970             'File scan.jpg uploaded.' in self.browser.contents)
     970            'File sample.jpg uploaded.' in self.browser.contents)
    971971        # Delete file again
    972         self.browser.getControl(name='delete_scanmanageupload').click()
    973         self.assertTrue(
    974             'scan deleted' in self.browser.contents)
     972        self.browser.getControl(name='delete_samplemanageupload').click()
     973        self.assertTrue(
     974            'sample deleted' in self.browser.contents)
    975975        # File names must meet several conditions
    976976        bmp_image = open(SAMPLE_IMAGE_BMP, 'rb')
    977         ctrl = self.browser.getControl(name='scanmanageupload')
     977        ctrl = self.browser.getControl(name='samplemanageupload')
    978978        file_ctrl = ctrl.mech_control
    979         file_ctrl.add_file(bmp_image, filename='my_scan.bmp')
    980         self.browser.getControl(
    981             name='upload_scanmanageupload').click()
     979        file_ctrl.add_file(bmp_image, filename='my_sample_scan.bmp')
     980        self.browser.getControl(
     981            name='upload_samplemanageupload').click()
    982982        self.assertTrue('Only the following extensions are allowed'
    983983            in self.browser.contents)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py

    r12056 r12057  
    2727from waeup.ikoba.interfaces import IObjectHistory
    2828from waeup.ikoba.customers.documents import (
    29     CustomerDocumentsContainer, CustomerDocument)
     29    CustomerDocumentsContainer, CustomerSampleDocument)
    3030from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
    3131
     
    4646        self.assertTrue(
    4747            verifyClass(
    48                 ICustomerDocument, CustomerDocument)
     48                ICustomerDocument, CustomerSampleDocument)
    4949            )
    5050        self.assertTrue(
    5151            verifyObject(
    52                 ICustomerDocument, CustomerDocument())
     52                ICustomerDocument, CustomerSampleDocument())
    5353            )
    5454        return
     
    5656    def test_addDocument(self):
    5757        container = CustomerDocumentsContainer()
    58         document = createObject(u'waeup.CustomerDocument')
     58        document = createObject(u'waeup.CustomerSampleDocument')
    5959        id = document.document_id
    6060        container.addDocument(document)
    6161        self.assertEqual(container[id], document)
    6262        self.assertRaises(TypeError, container.addDocument, object())
    63         self.assertEqual(document.class_name, 'CustomerDocument')
     63        self.assertEqual(document.class_name, 'CustomerSampleDocument')
    6464        return
    6565
    6666    def test_document_workflow(self):
    67         document = createObject(u'waeup.CustomerDocument')
     67        document = createObject(u'waeup.CustomerSampleDocument')
    6868        IWorkflowInfo(document).fireTransition('create')
    6969        self.assertEqual(IWorkflowState(document).getState(), 'created')
     
    8282
    8383    def test_document_history(self):
    84         doc = createObject(u'waeup.CustomerDocument')
     84        doc = createObject(u'waeup.CustomerSampleDocument')
    8585        IWorkflowInfo(doc).fireTransition('create')
    8686        messages = ' '.join(doc.history.messages)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r12056 r12057  
    1313from waeup.ikoba.customers.interfaces import ICSVCustomerExporter
    1414from waeup.ikoba.customers.customer import Customer
    15 from waeup.ikoba.customers.documents import CustomerDocument
     15from waeup.ikoba.customers.documents import CustomerSampleDocument
    1616from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup
    1717from waeup.ikoba.testing import FunctionalLayer
     
    132132    def test_export_empty(self):
    133133        # we can export a nearly empty document
    134         document = CustomerDocument()
     134        document = CustomerSampleDocument()
    135135        exporter = CustomerDocumentsExporter()
    136136        exporter.export([document], self.outfile)
     
    139139            result,
    140140            'class_name,document_id,history,last_transition_date,state,title,customer_id\r\n'
    141             'CustomerDocument,d101,[],,,,\r\n'
     141            'CustomerSampleDocument,d101,[],,,,\r\n'
    142142            )
    143143        return
     
    156156            )
    157157        self.assertMatches(
    158             '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     158            '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
    159159            'Document created by system\'],2014-11-25 06:57:24.990308#,'
    160160            'created,My Document,A111111...',
     
    174174            in result)
    175175        self.assertMatches(
    176             '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     176            '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
    177177            'Document created by system\'],2014-11-25 06:57:24.990308#,'
    178178            'created,My Document,A111111...',
     
    192192            in result)
    193193        self.assertMatches(
    194             '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     194            '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
    195195            'Document created by system\'],2014-11-25 06:57:24.990308#,'
    196196            'created,My Document,A111111...',
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12053 r12057  
    289289
    290290    DOCTYPES_DICT = {
    291         'CustomerDocument': 'Sample Document',
     291        'CustomerSampleDocument': 'Sample Document',
    292292        'CustomerPDFDocument': 'PDF Document',
    293293        }
Note: See TracChangeset for help on using the changeset viewer.