Changeset 12053 for main/waeup.ikoba/trunk/src
- Timestamp:
- 25 Nov 2014, 08:19:54 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py
r12052 r12053 39 39 IkobaPage, IkobaEditFormPage, IkobaAddFormPage, IkobaDisplayFormPage, 40 40 IkobaForm, NullValidator, jsaction, action, UtilityView) 41 from waeup.ikoba.widgets.datewidget import ( 42 FriendlyDateWidget, FriendlyDateDisplayWidget, 43 FriendlyDatetimeDisplayWidget) 41 44 from waeup.ikoba.browser.pages import ContactAdminForm 42 45 from waeup.ikoba.browser.breadcrumbs import Breadcrumb … … 796 799 @property 797 800 def selectable_doctypes(self): 798 doctypes = getUtility(I IkobaUtils).DOCUMENT_TYPES801 doctypes = getUtility(ICustomersUtils).SELECTABLE_DOCTYPES_DICT 799 802 return sorted(doctypes.items()) 800 803 … … 806 809 # Here we can create various instances of CustomerDocument derived 807 810 # classes depending on the doctype parameter given in form. 808 # So far we only have one CustomerDocument class and no derived 809 # classes. 810 document = createObject(u'waeup.CustomerDocument') 811 document = createObject('waeup.%s' % doctype) 811 812 self.context.addDocument(document) 812 doctype = getUtility(I IkobaUtils).DOCUMENT_TYPES[doctype]813 doctype = getUtility(ICustomersUtils).SELECTABLE_DOCTYPES_DICT[doctype] 813 814 self.flash(_('${a} created.', 814 815 mapping = {'a': doctype})) … … 831 832 grok.template('documentpage') 832 833 form_fields = grok.AutoFields(ICustomerDocument) 834 form_fields[ 835 'last_transition_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') 833 836 pnav = 4 834 837 … … 851 854 grok.require('waeup.manageCustomer') 852 855 grok.template('documenteditpage') 853 form_fields = grok.AutoFields(ICustomerDocument) 856 form_fields = grok.AutoFields(ICustomerDocument).omit('last_transition_date') 854 857 pnav = 4 855 858 deletion_warning = _('Are you sure?') … … 960 963 def render(self): 961 964 portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE 962 Id = translate(_(' DocumentId'), 'waeup.ikoba', target_language=portal_language)965 Id = translate(_('Id'), 'waeup.ikoba', target_language=portal_language) 963 966 Title = translate(_('Title'), 'waeup.ikoba', target_language=portal_language) 967 Type = translate(_('Type'), 'waeup.ikoba', target_language=portal_language) 964 968 State = translate(_('State'), 'waeup.ikoba', target_language=portal_language) 969 LT = translate(_('Last Transition'), 'waeup.ikoba', target_language=portal_language) 970 tableheader = [] 965 971 tabledata = [] 966 tableheader = []967 972 contenttitle = [] 968 973 for i in range(1,3): 969 974 tabledata.append(sorted( 970 975 [value for value in self.context['documents'].values()])) 971 tableheader.append([(Id, 'document_id', 3), 972 (Title, 'title', 8), 973 (State, 'translated_state', 3), 976 tableheader.append([(Id, 'document_id', 2), 977 (Title, 'title', 6), 978 (Type, 'translated_classname', 6), 979 (State, 'translated_state', 2), 980 (LT, 'formatted_transition_date', 3), 974 981 ]) 975 982 customerview = CustomerBasePDFFormPage(self.context, -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/documentsmanagepage.pt
r12016 r12053 8 8 <th i18n:translate="">Document Id</th> 9 9 <th i18n:translate="">Title</th> 10 <th i18n:translate="">Type</th> 11 <th i18n:translate="">State</th> 12 <th i18n:translate="">Last Transition</th> 10 13 </tr> 11 14 </thead> … … 25 28 <span tal:content="cl/title">TITLE</span> 26 29 </td> 30 <td> 31 <span tal:content="cl/translated_classname">CLASSNAME</span> 32 </td> 33 <td> 34 <span tal:content="cl/translated_state">STATE</span> 35 </td> 36 <td> 37 <span tal:content="cl/formatted_transition_date"> 38 LASTTRANSITIONDATE 39 </span> 40 </td> 27 41 </tr> 28 42 </tbody> -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py
r12035 r12053 33 33 from waeup.ikoba.customers.interfaces import ( 34 34 ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument, 35 ICustomersUtils )35 ICustomersUtils, ICustomerPDFDocument) 36 36 from waeup.ikoba.documents import DocumentsContainer, Document 37 37 from waeup.ikoba.documents.interfaces import IDocumentsUtils … … 60 60 61 61 class CustomerDocument(Document): 62 """This is a ndocument.62 """This is a customer document. 63 63 """ 64 64 grok.implements(ICustomerDocument, ICustomerNavigation) … … 94 94 return True 95 95 96 @property 97 def translated_classname(self): 98 try: 99 DOCTYPES_DICT = getUtility(ICustomersUtils).DOCTYPES_DICT 100 return DOCTYPES_DICT[self.classname] 101 except KeyError: 102 return 103 96 104 CustomerDocument = attrs_to_fields(CustomerDocument) 105 106 class CustomerPDFDocument(CustomerDocument): 107 """This is a customer document for a single pdf upload file only. 108 """ 109 grok.implements(ICustomerPDFDocument, ICustomerNavigation) 110 grok.provides(ICustomerPDFDocument) 111 112 CustomerPDFDocument = attrs_to_fields(CustomerPDFDocument) 97 113 98 114 … … 104 120 grok.name(u'waeup.CustomerDocument') 105 121 title = u"Create a new document.", 106 description = u"This factory instantiates new document instances."122 description = u"This factory instantiates new sample document instances." 107 123 108 124 def __call__(self, *args, **kw): … … 111 127 def getInterfaces(self): 112 128 return implementedBy(CustomerDocument) 129 130 # Customer documents must be importable. So we might need a factory. 131 class CustomerPDFDocumentFactory(grok.GlobalUtility): 132 """A factory for customer pdf documents. 133 """ 134 grok.implements(IFactory) 135 grok.name(u'waeup.CustomerPDFDocument') 136 title = u"Create a new document.", 137 description = u"This factory instantiates new pdf document instances." 138 139 def __call__(self, *args, **kw): 140 return CustomerPDFDocument(*args, **kw) 141 142 def getInterfaces(self): 143 return implementedBy(CustomerPDFDocument) 113 144 114 145 #: The file id marker for customer files -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py
r12032 r12053 147 147 ICustomerDocument, 148 148 exclude_attribs=False, 149 omit=['is_editable', 'translated_state']))) + ( 149 omit=['is_editable', 150 'translated_state', 151 'formatted_transition_date', 152 'translated_classname']))) + ( 150 153 'customer_id',) 151 154 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py
r12039 r12053 270 270 271 271 is_editable = Attribute('Document editable by customer') 272 translated_classname = Attribute('Translatable classname') 273 274 275 class ICustomerPDFDocument(IDocument): 276 """A customer document. 277 278 """ -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
r12051 r12053 812 812 self.browser.getLink("Documents").click() 813 813 self.browser.getLink("Add document").click() 814 self.browser.getControl(name="doctype").value = [' sample']814 self.browser.getControl(name="doctype").value = ['CustomerPDFDocument'] 815 815 self.browser.getControl("Create document").click() 816 self.assertTrue(' SampleDocument created.' in self.browser.contents)816 self.assertTrue('PDF Document created.' in self.browser.contents) 817 817 document = self.customer['documents']['d102'] 818 818 … … 853 853 self.assertTrue( 854 854 'INFO - zope.mgr - customers.browser.DocumentAddFormPage ' 855 '- K1000000 - added: SampleDocument %s'855 '- K1000000 - added: PDF Document %s' 856 856 % document.document_id in logcontent) 857 857 … … 871 871 self.browser.getLink("Documents").click() 872 872 self.browser.getLink("Add document").click() 873 self.browser.getControl(name="doctype").value = [' sample']873 self.browser.getControl(name="doctype").value = ['CustomerDocument'] 874 874 self.browser.getControl("Create document").click() 875 875 self.assertTrue('Sample Document created.' in self.browser.contents) -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py
r12004 r12053 61 61 self.assertEqual(container[id], document) 62 62 self.assertRaises(TypeError, container.addDocument, object()) 63 self.assertEqual(document.classname, 'CustomerDocument') 63 64 return 64 65 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py
r12017 r12053 138 138 self.assertEqual( 139 139 result, 140 ' document_id,history,state,title,customer_id\r\n'141 ' d101,[],,,\r\n'140 'classname,document_id,history,last_transition_date,state,title,customer_id\r\n' 141 'CustomerDocument,d101,[],,,,\r\n' 142 142 ) 143 143 return … … 152 152 result = open(self.outfile, 'rb').read() 153 153 self.assertTrue( 154 ' document_id,history,state,title,customer_id\r\n'154 'classname,document_id,history,last_transition_date,state,title,customer_id\r\n' 155 155 in result 156 156 ) 157 self.assertTrue( 158 'Document created by system\'],created,My Document,A111111\r\n' 159 in result 157 self.assertMatches( 158 '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - ' 159 'Document created by system\'],2014-11-25 06:57:24.990308#,' 160 'created,My Document,A111111...', 161 result 160 162 ) 161 163 return … … 169 171 result = open(self.outfile, 'rb').read() 170 172 self.assertTrue( 171 ' document_id,history,state,title,customer_id\r\n'173 'classname,document_id,history,last_transition_date,state,title,customer_id\r\n' 172 174 in result) 173 self.assertTrue( 174 ' Document created by system\'],created,My Document,A111111\r\n' 175 in result) 175 self.assertMatches( 176 '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - ' 177 'Document created by system\'],2014-11-25 06:57:24.990308#,' 178 'created,My Document,A111111...', 179 result 180 ) 176 181 return 177 182 … … 184 189 result = open(self.outfile, 'rb').read() 185 190 self.assertTrue( 186 ' document_id,history,state,title,customer_id\r\n'191 'classname,document_id,history,last_transition_date,state,title,customer_id\r\n' 187 192 in result) 188 self.assertTrue( 189 ' Document created by system\'],created,My Document,A111111\r\n' 190 in result) 193 self.assertMatches( 194 '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - ' 195 'Document created by system\'],2014-11-25 06:57:24.990308#,' 196 'created,My Document,A111111...', 197 result 198 ) 191 199 return -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py
r12051 r12053 288 288 } 289 289 290 DOCTYPES_DICT = { 291 'CustomerDocument': 'Sample Document', 292 'CustomerPDFDocument': 'PDF Document', 293 } 294 295 SELECTABLE_DOCTYPES_DICT = DOCTYPES_DICT 296 290 297 def getPDFCreator(self, context=None): 291 298 """Get a pdf creator suitable for `context`. -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py
r12032 r12053 76 76 try: 77 77 TRANSLATED_STATES = getUtility(IDocumentsUtils).TRANSLATED_STATES 78 ts = TRANSLATED_STATES[self.state] 79 return ts 78 return TRANSLATED_STATES[self.state] 80 79 except KeyError: 81 80 return 81 82 @property 83 def classname(self): 84 return self.__class__.__name__ 85 86 @property 87 def formatted_transition_date(self): 88 try: 89 return self.last_transition_date.strftime('%Y-%m-%d %H:%M:%S') 90 except AttributeError: 91 return 92 82 93 83 94 Document = attrs_to_fields(Document) -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12032 r12053 49 49 translated_state = Attribute( 50 50 'Returns a translated, more verbose verification state of a document') 51 classname = Attribute('Name of the document class') 52 formatted_transition_date = Attribute('Last transition formatted date string') 51 53 52 54 title = schema.TextLine( … … 55 57 ) 56 58 59 last_transition_date = schema.Datetime( 60 title = _(u'Last Transition Date'), 61 required = False, 62 readonly = False, 63 ) 64 65 57 66 class IDocumentsUtils(Interface): 58 67 """A collection of methods which are subject to customization. -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py
r12032 r12053 124 124 @grok.subscribe(IDocument, IWorkflowTransitionEvent) 125 125 def handle_document_transition_event(obj, event): 126 """Append message to document history and log file when transition happened. 126 """Append message to document history and log file and update 127 last_transition_date when transition happened. 127 128 """ 128 129 msg = event.transition.user_data['msg'] 129 130 history = IObjectHistory(obj) 130 131 history.addMessage(msg) 132 obj.last_transition_date = datetime.utcnow() 131 133 try: 132 134 customers_container = grok.getSite()['customers'] -
main/waeup.ikoba/trunk/src/waeup/ikoba/utils/utils.py
r12038 r12053 114 114 ('C', 'Good'), 115 115 ) 116 117 # Should be overridden in custom packages118 DOCUMENT_TYPES = {119 'sample': 'Sample Document',120 }121 116 122 117 PAYMENT_CATEGORIES = {
Note: See TracChangeset for help on using the changeset viewer.