Changeset 12213 for main/waeup.ikoba/trunk/src/waeup/ikoba/documents
- Timestamp:
- 13 Dec 2014, 10:51:17 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/documents
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py
r12206 r12213 125 125 @action(_('Create document'), style='primary') 126 126 def addDocument(self, **data): 127 document = createObject(u'waeup. Document')127 document = createObject(u'waeup.PublicDocument') 128 128 self.applyData(document, **data) 129 129 try: -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/container.py
r12207 r12213 24 24 from waeup.ikoba.documents.interfaces import IDocumentsContainer, IDocument 25 25 from waeup.ikoba.utils.helpers import attrs_to_fields 26 from waeup.ikoba.utils.logger import Logger 26 27 27 class DocumentsContainer(grok.Container ):28 class DocumentsContainer(grok.Container, Logger): 28 29 """This is a container for all kind of documents. 29 30 """ -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py
r12211 r12213 38 38 from waeup.ikoba.utils.helpers import attrs_to_fields, get_current_principal 39 39 from waeup.ikoba.documents.interfaces import ( 40 IDocument, I Document, IDocumentsUtils,40 IDocument, IPublicDocument, IDocumentsUtils, 41 41 IPDFDocument, IHTMLDocument) 42 42 from waeup.ikoba.documents.utils import generate_document_id … … 54 54 55 55 user_id = None 56 state = None 57 translated_state = None 56 58 57 59 def __init__(self): … … 70 72 71 73 @property 74 def class_name(self): 75 return self.__class__.__name__ 76 77 @property 78 def formatted_transition_date(self): 79 try: 80 return self.history.messages[-1].split(' - ')[0] 81 except IndexError: 82 return 83 84 @property 85 def connected_files(self): 86 return 87 88 @property 89 def is_verifiable(self): 90 return True, None 91 92 def setMD5(self): 93 """Determine md5 checksum of all files and store checksums as 94 document attributes. 95 """ 96 return 97 98 class PublicDocumentBase(Document): 99 """This is a customer document baseclass. 100 """ 101 grok.implements(IPublicDocument) 102 grok.provides(IPublicDocument) 103 grok.baseclass() 104 105 @property 72 106 def state(self): 73 107 state = IWorkflowState(self).getState() … … 83 117 return 84 118 85 @property 86 def class_name(self): 87 return self.__class__.__name__ 88 89 @property 90 def formatted_transition_date(self): 91 try: 92 return self.history.messages[-1].split(' - ')[0] 93 except IndexError: 94 return 95 96 @property 97 def connected_files(self): 98 return 99 100 @property 101 def is_verifiable(self): 102 return True, None 103 104 def setMD5(self): 105 """Determine md5 checksum of all files and store checksums as 106 document attributes. 107 """ 108 return 109 110 Document = attrs_to_fields(Document) 111 112 113 class PDFDocument(Document): 119 120 class PDFDocument(PublicDocumentBase): 114 121 """This is a document for a single pdf upload file. 115 122 """ … … 120 127 121 128 122 class HTMLDocument( Document):129 class HTMLDocument(PublicDocumentBase): 123 130 """This is a document to render html-coded text. 124 131 """ … … 133 140 """ 134 141 grok.implements(IFactory) 135 grok.name(u'waeup. Document')136 title = u"Create a new document.",137 description = u"This factory instantiates new documents."142 grok.name(u'waeup.PublicDocument') 143 title = u"Create a new public document.", 144 description = u"This factory instantiates new public documents." 138 145 139 146 def __call__(self, *args, **kw): 140 return Document(*args, **kw)147 return PublicDocument(*args, **kw) 141 148 142 149 def getInterfaces(self): 143 return implementedBy( Document)150 return implementedBy(PublicDocument) 144 151 145 152 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12210 r12213 59 59 """ 60 60 61 class IPDFDocument(IDocument): 61 class IPublicDocument(IDocument): 62 """A base representation of public documents. 63 64 """ 65 66 67 class IPDFDocument(IPublicDocument): 62 68 """A base representation of PDF documents. 63 69 … … 65 71 66 72 67 class IHTMLDocument(I Document):73 class IHTMLDocument(IPublicDocument): 68 74 """A base representation of HTML documents. 69 75 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_document.py
r12204 r12213 30 30 from waeup.ikoba.imagestorage import DefaultStorage 31 31 from waeup.ikoba.documents.interfaces import ( 32 IDocumentsContainer, I Document, IPDFDocument, IHTMLDocument)32 IDocumentsContainer, IPublicDocument, IPDFDocument, IHTMLDocument) 33 33 from waeup.ikoba.documents.container import DocumentsContainer 34 34 from waeup.ikoba.documents.document import ( 35 Document,PDFDocument, HTMLDocument,35 PDFDocument, HTMLDocument, 36 36 DocumentFileNameChooser, DocumentFileStoreHandler) 37 37 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) … … 53 53 self.assertTrue( 54 54 verifyClass( 55 IDocument, Document)56 )57 self.assertTrue(58 verifyObject(59 IDocument, Document())60 )61 62 self.assertTrue(63 verifyClass(64 55 IPDFDocument, PDFDocument) 65 56 ) … … 68 59 IPDFDocument, PDFDocument()) 69 60 ) 70 71 61 self.assertTrue( 72 62 verifyClass( … … 93 83 IWorkflowInfo(document).fireTransition('create') 94 84 self.assertEqual(IWorkflowState(document).getState(), 'created') 95 IWorkflowInfo(document).fireTransition('submit')96 self.assertEqual(IWorkflowState(document).getState(), 'submitted')97 IWorkflowInfo(document).fireTransition('verify')98 self.assertEqual(IWorkflowState(document).getState(), 'verified')99 IWorkflowInfo(document).fireTransition('reset2')100 self.assertEqual(IWorkflowState(document).getState(), 'created')101 self.assertRaises(InvalidTransitionError,102 IWorkflowInfo(document).fireTransition, 'verify')103 IWorkflowInfo(document).fireTransition('submit')104 IWorkflowInfo(document).fireTransition('reset3')105 self.assertEqual(IWorkflowState(document).getState(), 'created')106 IWorkflowInfo(document).fireTransition('publish')107 self.assertEqual(IWorkflowState(document).getState(), 'published')108 85 return 109 86 … … 166 143 def test_name_chooser_available(self): 167 144 # we can get a name chooser for document objects as adapter 168 doc = Document()145 doc = PDFDocument() 169 146 chooser = IFileStoreNameChooser(doc) 170 147 self.assertTrue(chooser is not None) … … 173 150 def test_name_chooser_document(self): 174 151 # we can get an image filename for documents not in a container 175 doc = Document()152 doc = PDFDocument() 176 153 chooser = IFileStoreNameChooser(doc) 177 154 result = chooser.chooseName('sample.jpg') -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py
r12212 r12213 19 19 """ 20 20 import grok 21 from datetime import datetime22 21 from zope.component import getUtility 23 22 from hurry.workflow.workflow import Transition, WorkflowState, NullCondition … … 27 26 IObjectHistory, IIkobaWorkflowInfo, 28 27 SimpleIkobaVocabulary, 29 CREATED, SUBMITTED, VERIFIED, REJECTED, EXPIRED,PUBLISHED)28 CREATED, PUBLISHED) 30 29 from waeup.ikoba.interfaces import MessageFactory as _ 31 30 from waeup.ikoba.workflow import IkobaWorkflow, IkobaWorkflowInfo 32 from waeup.ikoba.utils.helpers import get_current_principal 33 from waeup.ikoba.documents.interfaces import IDocument 31 from waeup.ikoba.documents.interfaces import IPublicDocument 34 32 35 VERIFICATION_TRANSITIONS = ( 33 34 PUBLISHING_TRANSITIONS = ( 36 35 Transition( 37 36 transition_id = 'create', … … 41 40 msg = _('Document created'), 42 41 destination = CREATED), 43 44 Transition(45 transition_id = 'submit',46 title = _('Submit for verification'),47 msg = _('Submitted for verification'),48 source = CREATED,49 destination = SUBMITTED),50 51 Transition(52 transition_id = 'verify',53 title = _('Verify'),54 msg = _('Verified'),55 source = SUBMITTED,56 destination = VERIFIED),57 58 Transition(59 transition_id = 'reject',60 title = _('Reject'),61 msg = _('REJECTED'),62 source = SUBMITTED,63 destination = REJECTED),64 65 Transition(66 transition_id = 'reset1',67 title = _('Reset to initial state'),68 msg = _('Reset to initial state'),69 source = REJECTED,70 destination = CREATED),71 72 Transition(73 transition_id = 'reset2',74 title = _('Reset to initial state'),75 msg = _('Reset to initial state'),76 source = VERIFIED,77 destination = CREATED),78 79 Transition(80 transition_id = 'reset3',81 title = _('Reset to initial state'),82 msg = _('Reset to initial state'),83 source = SUBMITTED,84 destination = CREATED),85 86 Transition(87 transition_id = 'expire',88 title = _('Set to expired'),89 msg = _('Set to expired'),90 source = VERIFIED,91 destination = EXPIRED),92 93 Transition(94 transition_id = 'reset4',95 title = _('Reset to initial state'),96 msg = _('Reset to initial state'),97 source = EXPIRED,98 destination = CREATED),99 100 Transition(101 transition_id = 'publish',102 title = _('Publish'),103 msg = _('Published'),104 source = CREATED,105 destination = PUBLISHED),106 42 ) 107 43 44 publishing_workflow = IkobaWorkflow(PUBLISHING_TRANSITIONS) 108 45 109 verification_workflow = IkobaWorkflow(VERIFICATION_TRANSITIONS) 110 111 class VerificationWorkflowState(WorkflowState, grok.Adapter): 46 class PublishingWorkflowState(WorkflowState, grok.Adapter): 112 47 """An adapter to adapt Document objects to workflow states. 113 48 """ 114 grok.context(I Document)49 grok.context(IPublicDocument) 115 50 grok.provides(IWorkflowState) 116 51 117 state_key = 'wf. verification.state'118 state_id = 'wf. verification.id'52 state_key = 'wf.publishing.state' 53 state_id = 'wf.publishing.id' 119 54 120 class VerificationWorkflowInfo(IkobaWorkflowInfo, grok.Adapter): 121 """Adapter to adapt Document objects to workflow info objects. 55 56 class PublishingWorkflowInfo(IkobaWorkflowInfo, grok.Adapter): 57 """Adapter to adapt CustomerDocument objects to workflow info objects. 122 58 """ 123 grok.context(I Document)59 grok.context(IPublicDocument) 124 60 grok.provides(IIkobaWorkflowInfo) 125 61 126 62 def __init__(self, context): 127 63 self.context = context 128 self.wf = verification_workflow64 self.wf = publishing_workflow 129 65 130 @grok.subscribe(IDocument, IWorkflowTransitionEvent) 131 def handle_document_transition_event(obj, event): 66 67 @grok.subscribe(IPublicDocument, IWorkflowTransitionEvent) 68 def handle_public_document_transition_event(obj, event): 132 69 """Append message to document history and log file. 133 70 134 Undo the verification of document and raise an exception if document135 does not meet the requirements for verification.136 71 """ 137 if event.transition.destination == VERIFIED:138 verifiable, error = obj.is_verifiable139 if not verifiable:140 # Undo transition and raise an exception.141 IWorkflowState(obj).setState(event.transition.source)142 raise InvalidTransitionError(error)143 if event.transition.transition_id == 'verify':144 obj.setMD5()145 72 msg = event.transition.user_data['msg'] 146 73 history = IObjectHistory(obj) 147 74 history.addMessage(msg) 148 75 try: 149 customers_container = grok.getSite()['customers'] 150 customers_container.logger.info('%s - %s' % (obj.customer_id,msg)) 76 grok.getSite().logger.info('%s' % msg) 151 77 except (TypeError, AttributeError): 152 78 pass
Note: See TracChangeset for help on using the changeset viewer.