Changeset 12015
- Timestamp:
- 20 Nov 2014, 21:39:40 (10 years ago)
- 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$ 2 2 ## 3 3 ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann … … 45 45 from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now 46 46 from waeup.ikoba.customers.interfaces import ( 47 ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils 47 ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils, 48 ICustomerDocument, ICustomerDocumentsContainer 48 49 ) 49 50 from waeup.ikoba.customers.catalog import search … … 583 584 return 584 585 585 # Pages for customers only586 # Pages for customers 586 587 587 588 … … 628 629 self.flash(' '.join(errors), type="warning") 629 630 return 631 632 # Pages for customer documents 633 634 class DocumentsBreadcrumb(Breadcrumb): 635 """A breadcrumb for the documents container. 636 """ 637 grok.context(ICustomerDocumentsContainer) 638 title = _('Documents') 639 640 641 class 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 651 class 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 708 class 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 748 class 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 765 class 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$ 2 2 ## 3 3 ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann … … 80 80 81 81 def __call__(self, *args, **kw): 82 return CustomerDocument( )82 return CustomerDocument(*args, **kw) 83 83 84 84 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$ 2 2 ## 3 3 ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann … … 44 44 45 45 46 class PayCustomer(grok.Permission):47 grok.name('waeup. payCustomer')46 class EditCustomerDocuments(grok.Permission): 47 grok.name('waeup.editCustomerDocuments') 48 48 49 49 … … 69 69 grok.title(u'Customer Record Owner') 70 70 grok.permissions('waeup.handleCustomer', 'waeup.uploadCustomerFile', 71 'waeup.viewCustomer', 'waeup. payCustomer')71 'waeup.viewCustomer', 'waeup.editCustomerDocuments') 72 72 73 73 … … 92 92 grok.permissions('waeup.viewCustomer', 'waeup.viewCustomers', 93 93 'waeup.manageCustomer', 'waeup.viewCustomersContainer', 94 'waeup. payCustomer', 'waeup.uploadCustomerFile',94 'waeup.editCustomerDocuments', 'waeup.uploadCustomerFile', 95 95 'waeup.viewCustomersTab', 'waeup.triggerTransition') 96 96 -
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$ 2 2 ## 3 3 ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann … … 101 101 self.customer_id = customer.customer_id 102 102 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) 103 106 104 107 # Set password … … 114 117 self.trigtrans_path = self.customer_path + '/trigtrans' 115 118 self.history_path = self.customer_path + '/history' 119 self.documents_path = self.customer_path + '/documents' 116 120 117 121 self.app['configuration'].carry_over = True … … 766 770 'job_id=%s' % job_id in logcontent 767 771 ) 772 773 774 class 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 138 138 self.assertEqual( 139 139 result, 140 'doc type,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' 142 142 ) 143 143 return … … 152 152 result = open(self.outfile, 'rb').read() 153 153 self.assertTrue( 154 'doc type,document_id,history,title,customer_id\r\n'154 'document_id,history,title,customer_id\r\n' 155 155 in result 156 156 ) … … 169 169 result = open(self.outfile, 'rb').read() 170 170 self.assertTrue( 171 'doc type,document_id,history,title,customer_id\r\n'171 'document_id,history,title,customer_id\r\n' 172 172 in result) 173 173 self.assertTrue( … … 184 184 result = open(self.outfile, 'rb').read() 185 185 self.assertTrue( 186 'doc type,document_id,history,title,customer_id\r\n'186 'document_id,history,title,customer_id\r\n' 187 187 in result) 188 188 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$ 2 2 ## 3 3 ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann … … 26 26 from waeup.ikoba.browser.layout import default_primary_nav_template 27 27 from waeup.ikoba.customers.interfaces import ( 28 ICustomer, ICustomersContainer) 28 ICustomer, ICustomersContainer, 29 ICustomerDocumentsContainer) 29 30 from waeup.ikoba.customers.browser import ( 30 31 CustomersContainerPage, CustomersContainerManagePage, 31 CustomerBaseDisplayFormPage) 32 CustomerBaseDisplayFormPage, 33 DocumentsManageFormPage) 32 34 33 35 grok.context(IIkobaObject) # Make IIkobaObject the default context … … 105 107 targets += [ 106 108 {'url':customer_url, 'title':'Base Data'}, 109 {'url':customer_url + '/documents', 'title':_('Documents')}, 107 110 {'url':customer_url + '/history', 'title':_('History')}, 108 111 ] … … 145 148 text = _(u'Base Data') 146 149 150 class CustomerManageDocumentsLink(CustomerManageLink): 151 grok.order(3) 152 link = 'documents' 153 text = _(u'Documents') 154 147 155 148 156 class CustomerManageHistoryLink(CustomerManageLink): … … 275 283 text = _('Change portrait') 276 284 target = 'change_portrait' 285 286 287 # Viewlets for customer cocuments 288 289 290 class 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 46 46 history = Attribute('Object history, a list of messages') 47 47 48 doctype = schema.Choice(49 title = _(u'Document Type'),50 source = DocumentTypeSource(),51 required = True,52 )53 54 48 title = schema.TextLine( 55 49 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$ 2 2 ## 3 3 ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann … … 34 34 VERIFIED = 'verified' 35 35 REJECTED = 'rejected' 36 OUTDATED = 'outdated' 36 37 37 38 IMPORTABLE_STATES = (CREATED, SUBMITTED, VERIFIED, REJECTED) … … 87 88 source = SUBMITTED, 88 89 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), 89 97 ) 90 98 -
main/waeup.ikoba/trunk/src/waeup/ikoba/permissions.py
r11967 r12015 157 157 'waeup.viewCustomer', 'waeup.viewCustomers', 158 158 'waeup.manageCustomer', 'waeup.viewCustomersContainer', 159 'waeup. payCustomer', 'waeup.uploadCustomerFile',159 'waeup.editCustomerDocuments', 'waeup.uploadCustomerFile', 160 160 'waeup.triggerTransition', 161 161 'waeup.viewCustomersTab' … … 182 182 'waeup.viewCustomer', 'waeup.viewCustomers', 183 183 'waeup.manageCustomer', 'waeup.viewCustomersContainer', 184 'waeup. payCustomer', 'waeup.uploadCustomerFile',184 'waeup.editCustomerDocuments', 'waeup.uploadCustomerFile', 185 185 'waeup.triggerTransition', 186 186 'waeup.viewCustomersTab'
Note: See TracChangeset for help on using the changeset viewer.