Changeset 12015


Ignore:
Timestamp:
20 Nov 2014, 21:39:40 (10 years ago)
Author:
Henrik Bettermann
Message:

Add first browser components with tests.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
2 added
9 edited

Legend:

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

    r11997 r12015  
    1 ## $Id: browser.py 11862 2014-10-21 07:07:04Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    4545from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now
    4646from waeup.ikoba.customers.interfaces import (
    47     ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils
     47    ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils,
     48    ICustomerDocument, ICustomerDocumentsContainer
    4849    )
    4950from waeup.ikoba.customers.catalog import search
     
    583584        return
    584585
    585 # Pages for customers only
     586# Pages for customers
    586587
    587588
     
    628629                self.flash(' '.join(errors), type="warning")
    629630        return
     631
     632# Pages for customer documents
     633
     634class DocumentsBreadcrumb(Breadcrumb):
     635    """A breadcrumb for the documents container.
     636    """
     637    grok.context(ICustomerDocumentsContainer)
     638    title = _('Documents')
     639
     640
     641class DocumentBreadcrumb(Breadcrumb):
     642    """A breadcrumb for the customer container.
     643    """
     644    grok.context(ICustomerDocument)
     645
     646    @property
     647    def title(self):
     648        return self.context.document_id
     649
     650
     651class DocumentsManageFormPage(IkobaEditFormPage):
     652    """ Page to manage the customer documents
     653
     654    This manage form page is for both customers and customers officers.
     655    """
     656    grok.context(ICustomerDocumentsContainer)
     657    grok.name('index')
     658    grok.require('waeup.viewCustomer')
     659    form_fields = grok.AutoFields(ICustomerDocumentsContainer)
     660    grok.template('documentsmanagepage')
     661    pnav = 4
     662
     663    @property
     664    def manage_documents_allowed(self):
     665        return checkPermission('waeup.editCustomerDocuments', self.context)
     666
     667    def unremovable(self, document):
     668        usertype = getattr(self.request.principal, 'user_type', None)
     669        if not usertype:
     670            return False
     671        if not self.manage_documents_allowed:
     672            return True
     673        return (self.request.principal.user_type == 'customer' and \
     674            document.state in (VERIFIED, REJECTED, OUTDATED))
     675
     676    @property
     677    def label(self):
     678        return _('${a}: Documents',
     679            mapping = {'a':self.context.__parent__.display_fullname})
     680
     681    @jsaction(_('Remove selected documents'))
     682    def delDocument(self, **data):
     683        form = self.request.form
     684        if 'val_id' in form:
     685            child_id = form['val_id']
     686        else:
     687            self.flash(_('No document selected.'), type="warning")
     688            self.redirect(self.url(self.context))
     689            return
     690        if not isinstance(child_id, list):
     691            child_id = [child_id]
     692        deleted = []
     693        for id in child_id:
     694            # Customers are not allowed to remove used documents
     695            document = self.context.get(id, None)
     696            if document is not None and not self.unremovable(document):
     697                del self.context[id]
     698                deleted.append(id)
     699        if len(deleted):
     700            self.flash(_('Successfully removed: ${a}',
     701                mapping = {'a': ', '.join(deleted)}))
     702            self.context.writeLogMessage(
     703                self,'removed: %s' % ', '.join(deleted))
     704        self.redirect(self.url(self.context))
     705        return
     706
     707
     708class DocumentAddFormPage(IkobaAddFormPage):
     709    """ Page to add an document
     710    """
     711    grok.context(ICustomerDocumentsContainer)
     712    grok.name('adddoc')
     713    grok.template('documentaddform')
     714    grok.require('waeup.editCustomerDocuments')
     715    form_fields = grok.AutoFields(ICustomerDocument)
     716    label = _('Add document')
     717    pnav = 4
     718
     719    @property
     720    def selectable_doctypes(self):
     721        doctypes = getUtility(IIkobaUtils).DOCUMENT_TYPES
     722        return sorted(doctypes.items())
     723
     724    @action(_('Create document'), style='primary')
     725    def createDocument(self, **data):
     726        form = self.request.form
     727        customer = self.context.__parent__
     728        doctype = form.get('doctype', None)
     729        # Here we can create various instances of CustomerDocument derived
     730        # classes depending on the doctype parameter given in form.
     731        # So far we only have one CustomerDocument class and no derived
     732        # classes.
     733        document = createObject(u'waeup.CustomerDocument')
     734        self.context.addDocument(document)
     735        doctype = getUtility(IIkobaUtils).DOCUMENT_TYPES[doctype]
     736        self.flash(_('${a} created.',
     737            mapping = {'a': doctype}))
     738        self.context.writeLogMessage(
     739            self,'added: %s %s' % (doctype, document.document_id))
     740        self.redirect(self.url(self.context))
     741        return
     742
     743    @action(_('Cancel'), validator=NullValidator)
     744    def cancel(self, **data):
     745        self.redirect(self.url(self.context))
     746
     747
     748class DocumentDisplayFormPage(IkobaDisplayFormPage):
     749    """ Page to view a document
     750    """
     751    grok.context(ICustomerDocument)
     752    grok.name('index')
     753    grok.require('waeup.viewCustomer')
     754    form_fields = grok.AutoFields(ICustomerDocument)
     755    pnav = 4
     756
     757    @property
     758    def label(self):
     759        return _('${a}: Document ${b}', mapping = {
     760            'a':self.context.customer.display_fullname,
     761            'b':self.context.document_id})
     762        return self.context.document_id
     763
     764
     765class DocumentManageFormPage(IkobaEditFormPage):
     766    """ Page to edit a document
     767    """
     768    grok.context(ICustomerDocument)
     769    grok.name('manage')
     770    grok.require('waeup.viewCustomer')
     771    form_fields = grok.AutoFields(ICustomerDocument)
     772    pnav = 4
     773
     774    @property
     775    def label(self):
     776        return _('${a}: Document ${b}', mapping = {
     777            'a':self.context.customer.display_fullname,
     778            'b':self.context.document_id})
     779        return self.context.document_id
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r11997 r12015  
    1 ## $Id: documents.py 11583 2014-04-04 08:44:59Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    8080
    8181    def __call__(self, *args, **kw):
    82         return CustomerDocument()
     82        return CustomerDocument(*args, **kw)
    8383
    8484    def getInterfaces(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/permissions.py

    r11997 r12015  
    1 ## $Id: permissions.py 10465 2013-08-07 11:18:43Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
     
    4444
    4545
    46 class PayCustomer(grok.Permission):
    47     grok.name('waeup.payCustomer')
     46class EditCustomerDocuments(grok.Permission):
     47    grok.name('waeup.editCustomerDocuments')
    4848
    4949
     
    6969    grok.title(u'Customer Record Owner')
    7070    grok.permissions('waeup.handleCustomer', 'waeup.uploadCustomerFile',
    71                      'waeup.viewCustomer', 'waeup.payCustomer')
     71                     'waeup.viewCustomer', 'waeup.editCustomerDocuments')
    7272
    7373
     
    9292    grok.permissions('waeup.viewCustomer', 'waeup.viewCustomers',
    9393                     'waeup.manageCustomer', 'waeup.viewCustomersContainer',
    94                      'waeup.payCustomer', 'waeup.uploadCustomerFile',
     94                     'waeup.editCustomerDocuments', 'waeup.uploadCustomerFile',
    9595                     'waeup.viewCustomersTab', 'waeup.triggerTransition')
    9696
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r11997 r12015  
    1 ## $Id: test_browser.py 11862 2014-10-21 07:07:04Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    101101        self.customer_id = customer.customer_id
    102102        self.customer = self.app['customers'][self.customer_id]
     103        document = createObject('waeup.CustomerDocument')
     104        document.title = u'My first document'
     105        self.customer['documents'].addDocument(document)
    103106
    104107        # Set password
     
    114117        self.trigtrans_path = self.customer_path + '/trigtrans'
    115118        self.history_path = self.customer_path + '/history'
     119        self.documents_path = self.customer_path + '/documents'
    116120
    117121        self.app['configuration'].carry_over = True
     
    766770            'job_id=%s' % job_id in logcontent
    767771            )
     772
     773
     774class CustomerDocumentUITests(CustomersFullSetup):
     775    # Tests for CustomerDocument relates views and pages
     776
     777    def test_manage_document(self):
     778        # Managers can access the pages of customer documentsconter
     779        # and can perform actions
     780        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     781        self.browser.open(self.customer_path)
     782        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     783        self.assertEqual(self.browser.url, self.customer_path)
     784        self.browser.open(self.customer_path)
     785        self.browser.getLink("Documents").click()
     786        self.browser.getLink("Add document").click()
     787        self.browser.getControl(name="doctype").value = ['generic']
     788        self.browser.getControl("Create document").click()
     789        self.assertTrue('Generic Document created.' in self.browser.contents)
     790        document = self.customer['documents']['d102']
     791
     792        # Documents can be removed
     793        ctrl = self.browser.getControl(name='val_id')
     794        ctrl.getControl(value=document.document_id).selected = True
     795        self.browser.getControl("Remove selected", index=0).click()
     796        self.assertTrue('Successfully removed' in self.browser.contents)
     797
     798        # All actions are being logged
     799        logfile = os.path.join(
     800            self.app['datacenter'].storage, 'logs', 'customers.log')
     801        logcontent = open(logfile).read()
     802
     803        self.assertTrue(
     804            'INFO - zope.mgr - customers.browser.DocumentAddFormPage '
     805            '- K1000000 - added: Generic Document %s'
     806            % document.document_id in logcontent)
     807
     808        self.assertTrue(
     809            'INFO - zope.mgr - customers.browser.DocumentsManageFormPage '
     810            '- K1000000 - removed: %s'
     811            % document.document_id in logcontent)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r12007 r12015  
    138138        self.assertEqual(
    139139            result,
    140             'doctype,document_id,history,title,customer_id\r\n'
    141             ',d101,[],,\r\n'
     140            'document_id,history,title,customer_id\r\n'
     141            'd101,[],,\r\n'
    142142            )
    143143        return
     
    152152        result = open(self.outfile, 'rb').read()
    153153        self.assertTrue(
    154             'doctype,document_id,history,title,customer_id\r\n'
     154            'document_id,history,title,customer_id\r\n'
    155155            in result
    156156            )
     
    169169        result = open(self.outfile, 'rb').read()
    170170        self.assertTrue(
    171             'doctype,document_id,history,title,customer_id\r\n'
     171            'document_id,history,title,customer_id\r\n'
    172172            in result)
    173173        self.assertTrue(
     
    184184        result = open(self.outfile, 'rb').read()
    185185        self.assertTrue(
    186             'doctype,document_id,history,title,customer_id\r\n'
     186            'document_id,history,title,customer_id\r\n'
    187187            in result)
    188188        self.assertTrue(
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py

    r11997 r12015  
    1 ## $Id: viewlets.py 11772 2014-07-31 04:38:23Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    2626from waeup.ikoba.browser.layout import default_primary_nav_template
    2727from waeup.ikoba.customers.interfaces import (
    28     ICustomer, ICustomersContainer)
     28    ICustomer, ICustomersContainer,
     29    ICustomerDocumentsContainer)
    2930from waeup.ikoba.customers.browser import (
    3031    CustomersContainerPage, CustomersContainerManagePage,
    31     CustomerBaseDisplayFormPage)
     32    CustomerBaseDisplayFormPage,
     33    DocumentsManageFormPage)
    3234
    3335grok.context(IIkobaObject)  # Make IIkobaObject the default context
     
    105107        targets += [
    106108            {'url':customer_url, 'title':'Base Data'},
     109            {'url':customer_url + '/documents', 'title':_('Documents')},
    107110            {'url':customer_url + '/history', 'title':_('History')},
    108111            ]
     
    145148    text = _(u'Base Data')
    146149
     150class CustomerManageDocumentsLink(CustomerManageLink):
     151    grok.order(3)
     152    link = 'documents'
     153    text = _(u'Documents')
     154
    147155
    148156class CustomerManageHistoryLink(CustomerManageLink):
     
    275283    text = _('Change portrait')
    276284    target = 'change_portrait'
     285
     286
     287# Viewlets for customer cocuments
     288
     289
     290class AddDocumentActionButton(AddActionButton):
     291    grok.order(1)
     292    grok.context(ICustomerDocumentsContainer)
     293    grok.view(DocumentsManageFormPage)
     294    grok.require('waeup.editCustomerDocuments')
     295    text = _('Add document')
     296    target = 'adddoc'
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12007 r12015  
    4646    history = Attribute('Object history, a list of messages')
    4747
    48     doctype = schema.Choice(
    49         title = _(u'Document Type'),
    50         source = DocumentTypeSource(),
    51         required = True,
    52         )
    53 
    5448    title = schema.TextLine(
    5549        title = _(u'Document Title'),
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py

    r11997 r12015  
    1 ## $Id: batching.py 11891 2014-10-28 20:02:45Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    3434VERIFIED = 'verified'
    3535REJECTED = 'rejected'
     36OUTDATED = 'outdated'
    3637
    3738IMPORTABLE_STATES = (CREATED, SUBMITTED, VERIFIED, REJECTED)
     
    8788        source = SUBMITTED,
    8889        destination = CREATED),
     90
     91    Transition(
     92        transition_id = 'outdate',
     93        title = _('Set to outdated'),
     94        msg = _('Set to outdated'),
     95        source = VERIFIED,
     96        destination = OUTDATED),
    8997    )
    9098
  • main/waeup.ikoba/trunk/src/waeup/ikoba/permissions.py

    r11967 r12015  
    157157                     'waeup.viewCustomer', 'waeup.viewCustomers',
    158158                     'waeup.manageCustomer', 'waeup.viewCustomersContainer',
    159                      'waeup.payCustomer', 'waeup.uploadCustomerFile',
     159                     'waeup.editCustomerDocuments', 'waeup.uploadCustomerFile',
    160160                     'waeup.triggerTransition',
    161161                     'waeup.viewCustomersTab'
     
    182182                     'waeup.viewCustomer', 'waeup.viewCustomers',
    183183                     'waeup.manageCustomer', 'waeup.viewCustomersContainer',
    184                      'waeup.payCustomer', 'waeup.uploadCustomerFile',
     184                     'waeup.editCustomerDocuments', 'waeup.uploadCustomerFile',
    185185                     'waeup.triggerTransition',
    186186                     'waeup.viewCustomersTab'
Note: See TracChangeset for help on using the changeset viewer.